From 436c0c8b6cefca8aedb0c3699a4b71d18885a248 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Wed, 24 Jul 2024 18:04:54 +0200 Subject: [PATCH] chore(postgresql): add replication slots and publication commands --- snippets/postgresql.sql | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/snippets/postgresql.sql b/snippets/postgresql.sql index 8930824..637424e 100644 --- a/snippets/postgresql.sql +++ b/snippets/postgresql.sql @@ -74,13 +74,14 @@ ALTER DEFAULT PRIVILEGES FOR ROLE juan IN SCHEMA cache REVOKE all ON TABLES FROM \du \du+ -- List users only -select usename FROM pg_catalog.pg_user; +SELECT usename FROM pg_catalog.pg_user; -- Check the current user has SuperUser privileges -SHOW is_superuser +SHOW is_superuser; -- Create roles --- Roles *are* users and groups since PostgreSQL vFIXME +-- Roles *are* users *and* groups since PostgreSQL vFIXME +-- Users are just roles that can LOGIN -- Does *not* support IF NOT EXISTS CREATE ROLE miriam; CREATE ROLE miriam WITH LOGIN PASSWORD 'jw8s0F4' VALID UNTIL '2005-01-01'; @@ -89,18 +90,23 @@ CREATE USER mike; -- Grant roles SuperUser privileges -- The role granting privileges must be already SuperUser ALTER USER joel WITH SUPERUSER; + -- Revoke SuperUser privileges ALTER USER joel WITH NOSUPERUSER; + -- Grant privileges to users -ALTER USER mark CREATEDB; +ALTER USER mark CREATEDB REPLICATION; ALTER ROLE miriam CREATEROLE CREATEDB; + -- Change passwords ALTER USER jonathan WITH PASSWORD 'seagull5-pantomime-Resting'; ALTER ROLE samantha WITH PASSWORD 'Wing5+Trunks3+Relic2' VALID UNTIL 'August 4 12:00:00 2024 +1'; + -- Change password's validity ALTER ROLE fred VALID UNTIL 'infinity'; + -- Rename -ALTER ROLE manager RENAME TO boss +ALTER ROLE manager RENAME TO boss; -- Assign roles to users GRANT rds_superuser TO mike; @@ -141,6 +147,7 @@ SELECT transport.import_from_server( 'destination.password', true ); + -- Run DB transfers -- Requires 'pg_transport' to be installed on both the source and destination DBs -- Requires 'pg_transport' to be the *only* extension active on the source @@ -150,3 +157,24 @@ SELECT transport.import_from_server( 'destination.password', false ); + + +-- List replication slots +SELECT * FROM pg_replication_slots; + +-- Create replication slots +-- Requires the executor to be superuser or replication role +SELECT pg_create_physical_replication_slot('peerflow_slot_prod'); +SELECT pg_create_logical_replication_slot('airbyte_slot', 'pgoutput'); + +-- Drop replication slots +SELECT pg_drop_replication_slot('airbyte_slot'); + + +-- List publications +\dRp +\dRp+ + +-- Create publications +CREATE PUBLICATION peerflow_prod FOR ALL TABLES; +CREATE PUBLICATION airbyte FOR TABLE call_log, queue_log;