This integration is certified by Stitch. For support, contact Stitch support.
Important: PostgreSQL as an input data source
This article describes how to connect PostgreSQL as an input data source.
If you want to connect a PostgreSQL instance as a destination, refer to the Connecting a Self-Hosted PostgreSQL Destination guide.
A high-level look at Stitch's PostgreSQL (v15-10-2015) integration, including release status, useful links, and the features supported in Stitch.
|Configurable Replication Methods||
|Full Table Replication||
PostgreSQL setup requirements
To set up PostgreSQL in Stitch, you need:
Permissions in PostgreSQL that allow you to create/manage users. This is required to create the Stitch database user.
To verify if the database is a read replica, or follower. While we always recommend connecting a replica over a production database, this also means you may need to verify some of its settings - specifically the
standbysettings - before connecting it to Stitch.
On occasion, the default values for the
standbysettings can prevent Stitch from successfully completing queries, resulting in slow, intermittent replication. This is usually only an issue during historical syncs or when replicating large amounts of data (ex: a large table using Full Table Replication).
If you find that the
on, proactively increasing the following settings from 30 seconds to 8-12 hours can help prevent this issue:
After the initial historical sync completes, you can typically decrease these settings again.
For an official explanation of these settings, check out the Postgres docs.
Step 1: Configure database connection settings
In this step, you’ll configure the database server to allow traffic from Stitch to access it. There are two ways to connect your database:
- A direct connection will work if your database is publicly accessible.
- An SSH tunnel is required if your database isn’t publicly accessible. This method uses a publicly accessible instance, or an SSH server, to act as an intermediary between Stitch and your database. The SSH server will forward traffic from Stitch through an encrypted tunnel to the private database.
Click the option you’re using below and follow the instructions.
For the connection to be successful, you’ll need to configure your firewall to allow access from our IP addresses. Whitelist the following IPs before continuing onto the next step:
- Follow the steps in the Setting up an SSH Tunnel for a database connection guide to set up an SSH tunnel for PostgreSQL.
- Complete the steps in this guide after the SSH setup is complete.
Step 2: Create a Stitch database user
Next, you’ll create a dedicated database user for Stitch. This will ensure Stitch is visible in any logs or audits, and allow you to maintain your privilege hierarchy.
Your organization may require a different process, but the simplest way to create this user is to execute the following query when logged into the PostgreSQL database as a user with the right to grant privileges.
Note: The user performing this step should also own the schema(s) that Stitch is being granted access to.
- Log into your database.
Create a database user named
<password>with a password:
CREATE USER stitch WITH ENCRYPTED PASSWORD '<password>'
CONNECTprivileges to the database, replacing
<database_name>with the name of a database you want to connect Stitch to:
GRANT CONNECT ON DATABASE <database_name> TO stitch
stitchuser schema usage privileges, replacing
<schema_name>with the name of a schema you want to replicate data from:
GRANT USAGE ON SCHEMA <schema_name> TO stitch
SELECTprivileges on the tables in the schema:
GRANT SELECT ON ALL TABLES IN SCHEMA <schema_name> TO stitch
Alter the schema’s default privileges to grant
SELECTprivileges on tables to
stitch. This is required to ensure that objects created in the schema after connecting to Stitch will remain accessible to the
ALTER DEFAULT PRIVILEGES IN SCHEMA <schema_name> GRANT SELECT ON TABLES TO stitch
- If you want to replicate data from multiple databases or schemas, repeat steps 3 - 6 as needed.
See the Privileges list tab for an explanation of why these permissions are required by Stitch.
In the table below are the database user privileges Stitch requires to connect to and replicate data from a PostgreSQL database.
|Privilege name||Reason for requirement|
Required to connect successfully to the specified database.
Required to access the objects contained in the specified schema.
Required to select rows from tables in the specified schema.
|ALTER DEFAULT PRIVILEGES||
Required to ensure that objects created in the schema after connecting to Stitch will be accessible by the Stitch database user.
Step 3: Connect Stitch
In this step, you’ll complete the setup by entering the database’s connection details and defining replication settings in Stitch.
Step 3.1: Define the database connection details
- If you aren’t signed into your Stitch account, sign in now.
On the Stitch Dashboard page, click the Add Integration button.
- Locate and click the PostgreSQL icon.
Fill in the fields as follows:
Integration Name: Enter a name for the integration. This is the name that will display on the Stitch Dashboard for the integration; it’ll also be used to create the schema in your destination.
For example, the name “Stitch PostgreSQL” would create a schema called
stitch_postgresqlin the destination. Note: The schema name cannot be changed after the integration is saved.
Host (Endpoint): Enter the host address (endpoint) used by the PostgreSQL instance. For example: This could be a network address such as
220.127.116.11, or a server endpoint like
Port: Enter the port used by the instance. The default is
Username: Enter the Stitch PostgreSQL database user’s username.
Password: Enter the password for the Stitch PostgreSQL database user.
Database: Enter the name of the PostgreSQL database you want to connect to Stitch. Stitch will ‘find’ all databases you give the Stitch user access to - a default database is only used to complete the connection. This is required for PostgreSQL integrations.
Step 3.2: Define the SSH connection details
If you’re using an SSH tunnel to connect your PostgreSQL database to Stitch, you’ll also need to define the SSH settings. Refer to the Setting up an SSH Tunnel for a database connection guide for assistance with completing these fields.
- Click the Encryption Type menu.
Select SSH to display the SSH fields.
Fill in the fields as follows:
Remote Address: Enter the public IP address or hostname of the server Stitch will SSH into.
SSH Port: Enter the SSH port on your server. (
SSH User: Enter the Stitch Linux (SSH) user’s username.
Step 3.3: Define the SSL connection details
Click the Connect using SSL checkbox if you’re using an SSL connection. Note: The database must support and allow SSL connections for this setting to work correctly.
Step 3.4: Create a replication schedule
In the Replication Frequency section, you’ll create the integration’s replication schedule. An integration’s replication schedule determines how often Stitch runs a replication job, and the time that job begins.
Stitch offers two methods of creating a replication schedule:
- Replication Frequency: This method requires selecting the interval you want replication to run for the integration. Start times of replication jobs are based on the start time and duration of the previous job. Refer to the Replication Frequency documentation for more information and examples.
Anchor scheduling: Based on the Replication Frequency, or interval, you select, this method “anchors” the start times of this integration’s replication jobs to a time you select to create a predictable schedule. Anchor scheduling is a combination of the Anchor Time and Replication Frequency settings, which must both be defined to use this method. Additionally, note that:
- A Replication Frequency of at least one hour is required to use anchor scheduling.
An initial replication job may not begin immediately after saving the integration, depending on the selected Replication Frequency and Anchor Time. Refer to the Anchor Scheduling documentation for more information.
- You’ll need to contact support to request using an Anchor Time with this integration.
To keep your row usage low, consider setting the integration to replicate less frequently. See the Understanding and Reducing Your Row Usage guide for tips on reducing your usage.
Step 4: Select data to replicate
The last step is to select select the tables and columns you want to replicate.
You can select tables and columns by:
- In the Integration Details page, click the Tables to Replicate tab.
- Locate a table you want to replicate.
- Click the checkbox next to the object’s name. A green checkmark means the object is set to replicate.
- If there are child objects, they’ll automatically display and you’ll be prompted to select some.
After you set a table to replicate, the Settings page will display. Note: When you track a table, by default all columns will also be tracked.
In the Settings page, define the table’s Replication Method and, if using Key-based Incremental Replication, its Replication Key.
- Repeat this process for every table you want to replicate.
Initial and historical replication jobs
After you finish setting up PostgreSQL, its Sync Status may show as Pending on either the Stitch Dashboard or in the Integration Details page.
For a new integration, a Pending status indicates that Stitch is in the process of scheduling the initial replication job for the integration. This may take some time to complete.
Initial replication jobs with Anchor Scheduling
If using Anchor Scheduling, an initial replication job may not kick off immediately. This depends on the selected Replication Frequency and Anchor Time. Refer to the Anchor Scheduling documentation for more information.
Free historical data loads
The first seven days of replication, beginning when data is first replicated, are free. Rows replicated from the new integration during this time won’t count towards your quota. Stitch offers this as a way of testing new integrations, measuring usage, and ensuring historical data volumes don’t quickly consume your quota.