Skip to main content

Postgres Setup Guide

Prerequisites

(Optional) Create a dedicated read-only user

Creating a dedicated read-only user is recommended for better permission control and auditing. If you choose to skip this step, you can use an existing Postgres user in your database.

 

To create a dedicated user, run the following command:

CREATE USER <user_name> PASSWORD 'your_password_here';

Grant the user access to the relevant schema:

GRANT USAGE ON SCHEMA <schema_name> TO <user_name>

Grant the user SELECT access to every existing table in that schema:

GRANT SELECT ON ALL TABLES IN SCHEMA <schema_name> TO <user_name>;

Grant the user read access to tables created in the future:

ALTER DEFAULT PRIVILEGES IN SCHEMA <schema_name> GRANT SELECT ON TABLES TO <user_name>;

(Optional) Grant the user read access to the pg_read_all_stats system role, this is required for us to monitor concurrent index creation and prevent locking the process.

GRANT pg_read_all_stats TO <user_name>;

Change Data Capture (CDC)

  1. Logical replication keeps logs on your server, and the more changes you commit, the more disk space those logs take. Check that the database has enough free space before you start.

  2. In your postgresql.conf file, add or verify the following settings:

    • Disable the statement_timeout and wal_sender_timeout parameter settings by setting both to 0.
    • Set the wal_level parameter to 'logical'.
    • Add up the PostgreSQL connectors that use WAL and any other replication slots your database already uses, and set max_replication_slots to that total or higher.
    • max_wal_senders caps how many WAL connections can run at once. Set it to at least two per logical replication slot.
    • Apply the changes by restarting the server.
  3. Open a PostgreSQL console as a superuser. On AWS Aurora, use an account that holds the rds_superuser role instead.

  4. Create a publication, either for every table or for a chosen list of tables. With a chosen list, you can change which tables are included later.

    • To create publication for all tables execute the following query:

      CREATE PUBLICATION matia_pub FOR ALL TABLES;
    • To create publication for only certain tables execute the following query:

      CREATE PUBLICATION matia_pub FOR TABLE table1, table2, table3;

      Note that we will be able to get changes only for tables included to publication.

  5. On the database you plan to sync, run the command below to give Matia its own replication slot. Matia will use this slot to track changes in your database and flush it during each successful sync.

    SELECT pg_create_logical_replication_slot('name_of_your_slot', 'pgoutput')
  6. Grant replication privileges to your PostgreSQL user.

    ALTER ROLE <user_name> WITH REPLICATION;

    For AWS Aurora/RDS, execute the following query instead:

    GRANT rds_replication TO <user_name>;
  7. To check that your PostgreSQL user can read from the slot, run this query with matia_slot changed to your slot name from step 5.

    SELECT count(*) FROM pg_logical_slot_peek_binary_changes('matia_slot', NULL, NULL, 'proto_version', '1', 'publication_names', 'matia_pub');

Whitelist Matia IPs

Matia IP addresses to whitelist on the bastion:

  • 52.20.96.22/32
  • 23.21.86.124/32
  • 44.219.180.239/32

Setup Guide

  1. Fill in the Username, Password, Hostname, Port and Database for your Postgres database.
  2. If using SSH - Copy Matia's public SSH key and add the public key to the authorized_keys file of your SSH server. The key must be all on one line, so make sure that you don't introduce any line breaks when cutting and pasting.
  3. If the SSL configuration of your database is either allow, require or prefer, set the SSL toggle to ON.
  4. Enter a Name for the connector.
  5. (Optional) Enter a Description for the connector.
  6. Select the Owner of the connector.
  7. (Optional) Verify that your Postgres database is successfully connected by clicking on Test Connection.
  8. Click Connect.

Supported Sync Modes

  • Full Refresh
  • Incremental
  • Incremental XMIN

Incremental XMIN

The XMIN Incremental Sync is based on the hidden XMIN system column that is present in all PostgreSQL tables. This will be used as the default cursor if a user-defined cursor is not selected. XMIN needs a long statement_timeout: anything over 5 minutes works, and so does the default of 0, which turns the timeout off.

 

Note: An XMIN Incremental Sync will not sync deleted records.

Supported Cursors

  • TIMESTAMP
  • TIMESTAMP_WITH_TIMEZONE
  • TIME
  • TIME_WITH_TIMEZONE
  • DATE
  • BIT
  • BOOLEAN
  • TINYINT/SMALLINT
  • INTEGER
  • BIGINT
  • FLOAT/DOUBLE
  • REAL
  • NUMERIC/DECIMAL
  • CHAR/NCHAR/NVARCHAR/VARCHAR/LONGVARCHAR
  • BINARY/BLOB