Skip to content

Instantly share code, notes, and snippets.

@edib
Forked from ratnakri/pglogical
Last active April 26, 2023 09:50
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save edib/402d7d29d54a025265c2a5b4d0ee7fe6 to your computer and use it in GitHub Desktop.
Save edib/402d7d29d54a025265c2a5b4d0ee7fe6 to your computer and use it in GitHub Desktop.
short tutorial to setup replication using pglogical
Edit /var/lib/postgres/data/postgresql.conf:
# change IP on subscriber
listen_addresses = '*'
wal_level = logical
shared_preload_libraries = 'pglogical'
max_worker_processes = 16
max_wal_senders = 16
max_replication_slots = 16
track_commit_timestamp = on
log_min_messages = debug3
Add to /var/lib/postgres/data/pg_hba.conf:
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
# change IP on subscriber
host all all all trust
host replication all all trust
Create user and database:
sudo -u postgres createuser -s --replication -P eax
sudo -u postgres createdb -O eax eax
Run psql as user eax and execute:
create extension pglogical;
On this point both provider and subscriber have user, database, and enabled pglogical.
(4) On provider:
create table test (k serial primary key, v text);
insert into test (v) values ('aaa');
select pglogical.create_node(
node_name := 'provider',
dsn := 'host=10.128.0.11 port=5432 user=eax dbname=eax'
);
select pglogical.create_replication_set('replication_set');
select pglogical.replication_set_add_table(
set_name := 'replication_set',
relation := 'test',
synchronize_data := true
);
(5) On subscriber:
create table test (k serial primary key, v text);
select pglogical.create_node(
node_name := 'subscriber',
dsn := 'host=10.128.0.12 port=5432 dbname=eax user=eax'
);
select pglogical.create_subscription(
subscription_name := 'subscription',
replication_sets := array['replication_set'],
provider_dsn := 'host=10.128.0.11 port=5432 dbname=eax user=eax'
);
# schema as table array
SELECT pglogical.replication_set_add_all_tables('<my replication set>', ARRAY['<a schema>']);
## drop node
SELECT pglogical.drop_node(
node_name := '<node name>'
);
# in second node, create tables, replication set and in first node, create subscription
@edib
Copy link
Author

edib commented Feb 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment