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)
-
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.
-
In your postgresql.conf file, add or verify the following settings:
- Disable the
statement_timeoutandwal_sender_timeoutparameter settings by setting both to0. - Set the
wal_levelparameter to'logical'. - Add up the PostgreSQL connectors that use WAL and any other replication slots your database already uses, and set
max_replication_slotsto that total or higher. max_wal_senderscaps 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.
- Disable the
-
Open a PostgreSQL console as a superuser. On AWS Aurora, use an account that holds the
rds_superuserrole instead. -
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.
-
-
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') -
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>; -
To check that your PostgreSQL user can read from the slot, run this query with
matia_slotchanged 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/3223.21.86.124/3244.219.180.239/32
Setup Guide
- Fill in the Username, Password, Hostname, Port and Database for your Postgres database.
- 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.
- If the SSL configuration of your database is either
allow,requireorprefer, set the SSL toggle to ON. - Enter a Name for the connector.
- (Optional) Enter a Description for the connector.
- Select the Owner of the connector.
- (Optional) Verify that your Postgres database is successfully connected by clicking on Test Connection.
- 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