Skip to main content

Connecting PostgreSQL to Salesforce


 


Last updated: 07/15/2026


 

Once a PostgreSQL database has been created and configured to accept incoming connections, connecting an Apache Airflow environment to itthat database is relativelyvery straightforward. BeforeHowever, before this connection can be established, however, the PostgreSQL provider must first be installed in the Airflow environment.

Installing the PostgreSQL provider in the Airflow environment

A provider is a package that can be installed in an Airflow environment to extend its capabilities.

Editing the requirements file

To install the PostgreSQL provider, the following line must be added to the requirements file of the environment:

apache-airflow-providers-postgres>=6.3.0

TheAt the end of each line, the version of the package to be installed can be specifiedspecified. by appending it to the package name. Although thisThis is not mandatory,mandatory it isbut highly recommended into orderprevent toerrors and ensure compatibility betweenacross all providers and the Airflow environmentenvironment. and the provider, while preventing unexpected changes after future releases.

The version of each package can be strictly enforced by using thea double equal sign (==). However, it is generally recommended to specifyonly onlyenforce the minimumoldest acceptableversion versionthat can be installed by using the greater than or equal sign (>=).—this Thisway, allowsa newer compatibleversion versions towill be automatically installed automatically while guaranteeing that the required features areif available.

The version of the PostgreSQL provider that can be installed depends on the latest release available as well as the version of Apache Airflow runningbeing in the environment.used.

Editing the requirements file

As a reminder, the requirements file is located in the S3 bucket associatedlinked withto the MWAAAirflow environment.environment Forfor theMWAA, local runner, it is locatedand in the requirements folder at the root of the aws-mwaa-local-runner directory.directory (which was cloned from the GitHub repository) for the local runner.

Updating the Airflow environment

Once the requirements file has been updated,edited, the Airflow environment must be updated soin thatorder for the provider isto be installed.

The process to update an environment in MWAA environment is described in this section of the page 'Setting up Apache AirflowAirflow', documentation.and Thethe same page also explains howprocess to update an environment in the local runner.runner is described in this section of the same page.

When updating an MWAA environment, in the DAG Code in Amazon S3 section, if the requirements configuration is pinnedset to a specific version of the requirements file stored in Amazon S3,file, the newly uploadededited version must be explicitly selected.selected, Otherwise,otherwise the environmentrequirements will continueremain usingunchanged. If no specific version is selected (the drop-down list still displays Choose a version), nothing needs to be done, as the previouslatest version of the file.requirements file will be selected automatically.

Configuring the connection

After the PostgreSQLSalesforce provider has been installed and the Airflow environment updated, the last step is to create a new connection.

connection

and configure it properly. Connections are managed from the Connections'Connections' page, which can be accessed from the Admin'Admin' sectiontab, located in the main navigation bar.

Screenshot 2026-07-14 at 11.07.54 AM.png

In the user interface of the Airflow userenvironments interface.

using

In Airflowversion 3.0.6 and above, the navigation menubar is located on the left.

Screenshot 2026-07-14 at 11.10.24 AM.png

In the user interface of Airflow environments using version 2.10 (as mentioned in the 'Setting up Apache Airflow' page, this is latest available version for the local runner) and below, itthe navigation bar is located aton the toptop.

of

On the page.

'Connections'

Apage, a new connection can be created by clicking on the 'Add ConnectionConnection' button (in Airflow 3.x)0.6 and above) or the '+' button (in Airflow 2.x)10 and below).

After this button is clicked, a window should appear on the screen. The first two fields that must be completed are the 'Connection ID' and the 'Connection Type.'—these fields are mandatory for every connection.

  • The

    'Connection ID' is simply the name of the connection. It can be anyanything, uniquebut identifier.it must be unique. If there isare onlyno oneother PostgreSQL databaseconnections in the environment, it is recommended to use postgres_default, which is the default value of the postgres_conn_iddefault_conn_name parameter used byof the PostgreSQL Hook.

    Hook.
  • The

    'Connection Type', as its name indicates, is simply the type of the connection. The type 'Postgres' must be set to Postgres.selected. If this optionit does not appear in the listdrop-down oflist, available connection types,then the PostgreSQLSalesforce provider wasmight most likelyhave not been installed successfully.

    properly.

UnlikeIn the Salesforcelocal provider,runner, a default connection is automatically created for each connection type. As a result, the PostgreSQLconnection providernamed doespostgres_default notshould relyalready onexist. OAuthThis orconnection certificates.can Instead,be itedited establishesinstead of creating a directnew one.

Once these two fields have been completed, the connection can be configured. Several fields must be completed in order for the Airflow environment to be able to establish a connection to the databasedatabase:

using
the'Host' connection'Port' parameters'Database' supplied'Login' in'Password' the Airflow connection.

The following fields should be completed.

Host

The 'Host' field specifies the hostnamehost name or the IP address of the PostgreSQL server.

If the database is hosted on Amazon RDS, this value corresponds to the RDS endpoint. For a locally hosted database, it is usually the hostname or IP address of the machine running PostgreSQL.

The Airflow environment must be able to reach this host over the network. For MWAAthe environments,proof thisof typically requires that bothconcept, the Airflowserver environmentis hosted and therunning databaseon residean withinEC2 instance, named foundation-etl-poc-server and located in the same'ITS VPCshared ornon-prod' withinaccount, networkspublicly thataccessible canover communicatethe with each other through appropriate routing and security rules.Internet.

Database

The 'Port' field specifies the TCP port used by the PostgreSQL server. The default PostgreSQL port is 5432, which should be used unless the server has been configured to listen on another port. For the proof of concept, this default port is used.

The 'Database' field specifies the name of the PostgreSQL database that the connection should open.

A PostgreSQL server can host multiple databases simultaneously. This field identifies which one Airflow shouldenvironment must connect toto. afterFor authenticationthe succeeds.proof of concept, a database named snowflake_mock is used.

Login

The Login field contains the username used to authenticate with PostgreSQL. In the database used for the proof of concept, a user named 

For security reasons, it is heavily recommended to create a dedicated database user for Apache Airflow instead of using the database administrator account. This user should be granted only the permissions required by the DAGs that will access the database.

Following the principle of least privilege reduces the impact of accidental modifications and limits the consequences of compromised credentials.

Password

The Password field contains the password associated with the PostgreSQL user.

Since this field contains sensitive information, Airflow stores it securely and does not display its value when the connection is edited.

Port

The Port field specifies the TCP port used by the PostgreSQL server.

The default PostgreSQL port is 5432, which should be used unless the server has been configured to listen on another port.

Extra

Most PostgreSQL connections do not require any additional configuration.

The Extra field can be used to specify optional connection parameters in JSON format. Examples include SSL configuration, connection options or additional parameters supported by the PostgreSQL driver.

For example, if SSL encryption is required by the PostgreSQL server, the following configuration can be used:

{
  "sslmode": "require"
}

The exact parameters that should be specified depend on the configuration of the PostgreSQL server.

Using the PostgreSQL connection in a DAG

The PostgreSQL provider includes the PostgresHook, which retrieves the configured connection from Airflow and establishes the connection to the database.

from datetime import datetime

from airflow.decorators import dag, task
from airflow.providers.postgres.hooks.postgres import PostgresHook


@dag(
    dag_id="postgres_dag_example",
    schedule=None,
    start_date=datetime(2026, 1, 1),
    catchup=False,
)
def postgres_dag_example():

    @task
    def postgres_task_example():

        # By default, the PostgresHook retrieves the connection
        # named "postgres_default". If another connection ID was
        # used, it must be specified here.

        hook = PostgresHook()
        # or
        # hook = PostgresHook(postgres_conn_id="my_postgres_connection")

        # Execute a SQL query.

        records = hook.get_records(
            "SELECT id, first_name, last_name FROM employees LIMIT 5"
        )

        for record in records:
            print(record)

    postgres_task_example()


postgres_dag_example()

If more advanced database operations are required, the PostgresHook also provides direct access to the underlying database connection and cursor, allowing any SQL statement supported by PostgreSQL to be executed.