> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sync.cdata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PostgreSQL

export const CommonAuthSchemeAwsec2roles = ({siteName = "CData Sync", siteNameShort = "Sync", datasource = "the data source"}) => {
  return <>
      <p>
        When you run {siteName} on an EC2 instance, {siteName} can authenticate by using the IAM role that is assigned to the instance. Select <strong>AwsEC2Roles</strong> for <strong>Auth Scheme</strong> to use that role. No additional properties are required.
      </p>
    </>;
};

export const CommonAuthSchemeAwsiamroles = ({siteName = "CData Sync", siteNameShort = "Sync", datasource = "the data source"}) => {
  return <>
      <p>To connect with your IAM user credentials, specify the following properties:</p>
      <ul>
        <li><strong>Auth Scheme:</strong> Select <strong>AwsIAMRoles</strong>.</li>
        <li><strong>User:</strong> Enter the username that you use to authenticate to your {datasource} account.</li>
        <li><strong>AWS Access Key:</strong> Enter your Amazon Web Services (AWS) account access key. You can locate this value on your AWS security credentials page.</li>
        <li><strong>AWS Secret Key:</strong> Enter your AWS account secret key. You can locate this value on your AWS security credentials page.</li>
        <li><strong>AWS Role ARN:</strong> Enter the Amazon Resource Name (ARN) for the role with which you want to authenticate.</li>
        <li>(Optional) <strong>AWS External Id:</strong> Enter the unique identifier that is required when you assume a role in another account.</li>
      </ul>
    </>;
};

export const CommonDatasourceMoreInformation = ({datasource = "the data source", advancedurl = "", siteName = "CData Sync", driverVersion = ""}) => {
  return <>
      <p>
        For more information about interactions between {siteName} and {datasource}, see{' '}
        <a href={`https://cdn.cdata.com/help/${advancedurl}${driverVersion}/synch/default.htm`}>
          {datasource} Connector for {siteName}
        </a>.
      </p>
    </>;
};

export const CommonDatasourceAddConnector = ({datasource = "the data source", title = "the connector", destination = false, siteNameShort = "Sync"}) => {
  return <>
      <p>
        To enable {siteNameShort} to use data from {datasource}, you first must add the
        connector, as follows:
      </p>
      <ol>
        <li>Open the <strong>Connections</strong> page of the {siteNameShort} dashboard.</li>
        <li>Click <strong>Add Connection</strong> to open the <strong>Select Connectors</strong> page.</li>
        <li>
          Click the <strong>{destination ? "Destinations" : "Sources"}</strong> tab and locate
          the <strong>{title}</strong> row.
        </li>
        <li>
          Click the <strong>Configure Connection</strong> icon at the end of that row to open
          the <strong>New Connection</strong> page. This action opens the{' '}
          <strong>Add Connection</strong> dialog box.
          <br />
          <strong>Note:</strong> If the <strong>Configure Connection</strong> icon is not
          available, click the <strong>Download Connector</strong> icon to install
          the {title} connector.
        </li>
        <li>Enter a name for your connection in the <strong>Add Connection</strong> dialog box.</li>
        <li>Click <strong>Add</strong> to open the <strong>Settings</strong> tab for your connector.</li>
      </ol>
      <p>
        For more information about installing new connectors, see{' '}
        <a href="../connections">Connections</a>.
      </p>
    </>;
};

export const CommonDatasourceIntroSource = ({datasource = "the data source", siteName = "CData Sync"}) => {
  return <p>
      You can use the {datasource} connector from the {siteName} application to capture data
      from {datasource} and move it to any supported destination. To do so, you need to add
      the connector, authenticate to the connector, and complete your connection.
    </p>;
};

export const driverVersion = "M";

export const siteNameShort = "Sync";

export const siteName = "CData Sync";

export const datasource = "PostgreSQL";
export const pageTitle = "PostgreSQL";
export const advancedurl = "FP";
export const oauthschemes = "AzureAD, AzurePassword, AzureMSI, or GCPServiceAccount";

<CommonDatasourceIntroSource datasource={datasource} siteName={siteName} />

## Add the PostgreSQL Connector

<CommonDatasourceAddConnector datasource={datasource} title={pageTitle} destination={false} siteNameShort={siteNameShort} />

## Authenticate to PostgreSQL

After you add the connector, you need to set the required properties.

**Server:** Enter the host name or IP of the server that hosts the {datasource} database. The default server value is **localhost**.

{siteName} supports authenticating to {pageTitle} in several ways. Select your authentication method below to proceed to the relevant section that contains the authentication details.

* [**Password**](#password) (default)
* [**Azure Active Directory**](#azure-active-directory)
* [**Azure Service Principal**](#azure-service-principal)
* [**Azure Service Principal Certificate**](#azure-service-principal-certificate)
* [**Azure Password**](#azure-password)
* [**Azure Managed Service Identity**](#azure-managed-service-identity)
* [**Aws IAM Roles**](#aws-iam-roles)
* [**Aws EC2 Roles**](#aws-ec2-roles)
* [**GCP Service Account**](#gcp-service-account)

### Password

To connect with user credentials, specify the following properties:

* **Auth Scheme:** Select **Password**.
* **User:** Enter the username that you use to authenticate to your {datasource} account.
* **Password:** Enter the password that you use to authenticate to your {datasource} account.

### Azure Active Directory

To connect with Azure Active Directory, specify the following properties:

* **Auth Scheme:** Select **AzureAD**.
* **User:** Enter the username that you use to authenticate to your {datasource} account.
* **Azure Tenant:** Enter the Microsoft Online tenant to which you want to connect. If you do not specify a tenant, {siteName} uses the default tenant.
* **OAuth Client Id:** Enter the client Id that you were assigned when you registered your application with an OAuth authorization server.
* **OAuth Client Secret:** Enter the client secret that you were assigned when you registered your application with an OAuth authorization server.

### Azure Service Principal

To connect with an Azure service principal and client secret, set the following properties:

* **Auth Scheme:** Select **AzureServicePrincipal**.
* **Azure Tenant:** Enter the Microsoft Online tenant to which you want to connect.
* **User:** Enter the username that you use to authenticate to your {datasource} account.
* **OAuth Client Id:** Enter the client Id that you were assigned when you registered your application with an OAuth authorization server.
* **OAuth Client Secret:** Enter the client secret that you were assigned when you registered your application with an OAuth authorization server.
* (Optional) **Scope:** Specify the scope of your access to the application.

To obtain the OAuth client Id and client secret for your application:

1. Log in to the <a href="https://portal.azure.com" target="_blank" rel="noopener noreferrer">Azure portal</a>.
2. In the left navigation pane, select **All services**. Then, search for and select **App registrations**.
3. Click **New registrations**.
4. Enter an application name and select **Any Azure AD Directory - Multi Tenant**.
5. After you create the application, copy the application (client) Id value that is displayed in the **Overview** section. Use this value as the OAuth client Id.
6. Navigate to the **Certificates & Secrets** section and select **New Client Secret** for the application.
7. Specify the duration and save the client secret. After you save it, the key value is displayed.
8. Copy this value because it is displayed only once. You will use this value as the OAuth client secret.
9. On the **Authentication** tab, make sure to select **Access tokens (used for implicit flows)**.

### Azure Service Principal Certificate

To connect with an Azure service principal and client certificate, set the following properties:

* **Auth Scheme:** Select **AzureServicePrincipalCert**.
* **User:** Enter the username that you use to authenticate to your {datasource} account.
* **Azure Tenant:** Enter the Microsoft Online tenant to which you want to connect.
* **OAuth JWT Cert:** Enter your Java web tokens (JWT) certificate store.
* **OAuth JWT Cert Type:** Enter the type of key store that contains your JWT Certificate. The default type is **PEMKEY\_BLOB**.
* (Optional) **Scope:** Specify the scope of your access to the application.
* (Optional) **OAuth JWT Cert Password:** Enter the password for your OAuth JWT certificate.
* (Optional) **OAuth JWT Cert Subject:** Enter the subject of your OAuth JWT certificate.

To obtain the OAuth certificate for your application:

1. Log in to the <a href="https://portal.azure.com" target="_blank" rel="noopener noreferrer">Azure portal</a>.
2. In the left navigation pane, select **All services**. Then, search for and select **App registrations**.
3. Click **New registrations**.
4. Enter an application name and select **Any Azure AD Directory - Multi Tenant**.
5. After you create the application, copy the application (client) Id value that is displayed in the **Overview** section. Use this value as the OAuth client Id.
6. Navigate to the **Certificates & Secrets** section and select **Upload certificate**. Then, select the certificate to upload from your local machine.
7. Specify the duration and save the client secret. After you save it, the key value is displayed.
8. Copy this value because it is displayed only once. You will use this value as the OAuth client secret.
9. On the **Authentication** tab, make sure to select **Access tokens (used for implicit flows)**.

### Azure Password

To connect with Azure user credentials, specify the following properties:

* **Auth Scheme:** Select **AzurePassword**.
* **User:** Enter the username that you use to authenticate to your {datasource} account.
* **Password:** Enter the password that you use to connect to your {datasource} account.
* **Azure Tenant:** Enter the Microsoft Online tenant to which you want to connect. If you do not specify a tenant, {siteName} uses the default tenant.

### Azure Managed Service Identity

To connect with Azure Managed Service Identity (MSI), specify the following properties:

* **Auth Scheme:** Select **AzureMSI**.
* **User:** Enter the username that you use to authenticate to your {datasource} account.

### AWS IAM Roles

<CommonAuthSchemeAwsiamroles siteName={siteName} siteNameShort={siteNameShort} datasource={datasource} />

### AWS EC2 Roles

<CommonAuthSchemeAwsec2roles siteName={siteName} siteNameShort={siteNameShort} datasource={datasource} />

### GCP Service Account

To connect with a GCP service account, specify the following properties:

* **Auth Scheme:** Select **GCPServiceAccount**.
* **OAuth JWT Cert:** Enter your Java web tokens (JWT) certificate store.
* **OAuth JWT Cert Type:** Enter the type of key store that contains your JWT Certificate. The default type is **PEMKEY\_BLOB**.
* **OAuth JWT Cert Password** (optional) - Enter the password for your OAuth JWT certificate.
* **OAuth JWT Cert Subject** (optional) - Enter the user subject for which the application is requesting delegated access.

## Complete Your Connection

To complete your connection:

1. Specify these settings:
   * **Database:** Enter the name of the database that to which you want to connect when you connect to the {datasource} server.
   * **Port:** Enter the port number of the server that hosts the {datasource} database. The default port value is **5432**.
2. Define advanced connection settings on the **Advanced** tab. (In most cases, though, you should not need these settings.)
3. {oauthschemes ? `If you authenticate with ${oauthschemes}, click` : "Click"} **Connect to {datasource}** to connect to your {pageTitle} account.
4. Click **Create & Test** to create your connection.

## Configure Logical Replication

{siteName} can use logical replication that is configured in {datasource} to update your destination table incrementally. {datasource} uses logical decoding to surface the contents of the write-ahead logs, which track data changes in the database, into a readable format. Those changes are read by {siteNameShort} and pushed into the destination.

### Enable Logical Replication for {siteName}

To enable logical replications for {siteNameShort}:

1. Ensure that the `wal_level=logical` parameter is set in your {datasource} database. You can set this parameter in the postgresql.conf file.

2. Create a logical replication slot for {siteNameShort} by submitting the following SELECT statement:

   ```
   SELECT pg_create_logical_replication_slot('cdatasync_replication_slot', 'test_decoding');
   ```

   <Note>The slot name `cdatasync_replication_slot` is an example slot name. You can substitute any name in its place. You need this slot name when you create your job in {siteNameShort}. It is important that this slot is used by {siteNameShort} only because changes are consumed when it reads from the slot.</Note>

3. Ensure that the user that connects from {siteNameShort} has permission to read the replication slot by submitting the following statement.

   ```
   ALTER ROLE <em>PostreSQL-User</em> WITH REPLICATION;
   ```

4. Create a job in {siteNameShort} with a {datasource} source. After you select the **Change Data Capture** option, enter the replication slot name.

### Deletion Behavior

Logical replication enables {siteNameShort} to track deleted records when the source table contains a primary key. If the source table does not contain a primary key, {siteNameShort} cannot retrieve deleted records.

## Support for Incremental Replication

The {datasource} source supports incremental replication. Incremental replication reduces the workload tremendously and minimizes bandwidth use and latency of synchronization. Moving data in increments offers great flexibility when you are dealing with slow APIs or daily quotas.

You must configure the incremental check column based on the {datasource} source columns. An *incremental check column* is either a datetime or integer-based column that {siteNameShort} uses to identify new or modified records when it replicates data. Therefore, you must configure incremental check on a datetime or integer-based column in your {datasource} table for incremental replication to occur.

For details about how to set up incremental replication, see [Incremental Replication](../../getting-started/features#incremental-replication).

## More Information

<CommonDatasourceMoreInformation datasource={datasource} advancedurl={advancedurl} siteName={siteName} driverVersion={driverVersion} />
