Module W5
Dalibo SCOP
24.09
29 août 2024
Cette formation est sous licence CC-BY-NC-SA. Vous êtes libre de la redistribuer et/ou modifier aux conditions suivantes :
PostgreSQL® Postgres® et le logo Slonik sont des marques déposées par PostgreSQL Community Association of Canada.
Ce document ne couvre que les versions supportées de PostgreSQL au moment de sa rédaction, soit les versions 12 à 16.
La réplication logique utilise le streaming :
wal_level
logical
wal sender
wal receiver
logical replication worker
INSERT
UPDATE
DELETE
TRUNCATE
COMMIT
Étapes :
CREATE ROLE logrepli LOGIN REPLICATION ; GRANT SELECT ON ALL TABLES IN SCHEMA monschema TO logrepli ;
# pg_hba.conf host base_publication logrepli XXX.XXX.XXX.XXX/XX scram-sha-256
wal_level = logical
logical_decoding_work_mem = 64MB
pg_dump -h origine -s -t la_table la_base | psql la_base
CREATE PUBLICATION pub_t1 FOR TABLE t1 ; CREATE PUBLICATION pub_t1part FOR TABLE t1 (c1, c3); -- v15 CREATE PUBLICATION pub_tout FOR ALL TABLES ; CREATE PUBLICATION pub_public FOR TABLES IN SCHEMA public ; -- v15
CREATE PUBLICATION pub_filtree FOR TABLE employes WHERE ( ville = 'Brest' ) ; --v15
… WITH ( publish = 'update, delete, insert, truncate') -- défaut
… WITH (publish_via_partition_root = false) -- défaut, v13
CREATE SUBSCRIPTION nom CONNECTION 'infos_connexion' PUBLICATION nom_publication [, ...] [ WITH ( parametre_souscription [= value] [, ... ] ) ]
infos_connexion
pg_create_subscription
Par défaut :
connect = true
copy_data = true
create_slot = true
enabled = true
slot_name = <nom de la souscription>
streaming = off
true
parallel
binary = off
disable_on_error = false
synchronous_commit = off
synchronous_commit
CREATE ROLE logrepli LOGIN REPLICATION; GRANT SELECT ON ALL TABLES IN SCHEMA public TO logrepli;
postgresql.conf
pg_hba.conf
host b1 logrepli 192.168.10.0/24 trust
trust
.pgpass
CREATE ROLE logrepli LOGIN REPLICATION;
createdb -h s2 b1 pg_dump -h s1 -s b1 | psql -h s2 b1
CREATE PUBLICATION publi_complete FOR ALL TABLES;
CREATE SUBSCRIPTION subscr_complete CONNECTION 'host=192.168.10.1 user=logrepli dbname=b1' PUBLICATION publi_complete;
CREATE PUBLICATION publi_partielle FOR TABLE t1,t2 ;
CREATE SUBSCRIPTION subscr_partielle CONNECTION 'host=192.168.10.1 user=logrepli dbname=b1' PUBLICATION publi_partielle;
CREATE PUBLICATION publi_t3_1 FOR TABLE t3_1;
CREATE SUBSCRIPTION subscr_t3_1 CONNECTION 'host=192.168.10.1 user=logrepli dbname=b1' PUBLICATION publi_t3_1;
CREATE PUBLICATION publi_t3_2 FOR TABLE t3_2;
CREATE SUBSCRIPTION subscr_t3_2 CONNECTION 'host=192.168.10.4 user=logrepli dbname=b1' PUBLICATION publi_t3_2;
t3
logical replication launcher
logical_decoding_work_mem
64MB
max_slot_wal_keep_size
wal_sender_timeout
max_wal_senders
max_replication_slots
max_worker_processes
max_logical_replication_workers
pg_replslot
state
.spill
pg_logical
FOR ALL TABLES
FOR TABLES IN SCHEMA
-- origine ALTER PUBLICATION … ADD TABLE …, TABLE … ; ALTER SUBSCRIPTION … REFRESH PUBLICATION ;
pg_replication_slot_advance()
pg_waldump
pg_walinspect
VACUUM
ANALYZE
REINDEX
pg_dumpall
pg_dump
--no-publications
--no-subscriptions
ENABLE
REFRESH PUBLICATION
Comme pour la réplication physique :
streaming = on
pg_publication
\dRp
pg_publication_tables
pg_subscription
\dRs
pg_stat_replication
pg_replication_slots
pg_stat_replication_slots
pg_stat_subscription
pg_replication_origin_status
pg_stat_database_conflicts
check_pgactivity
replication_slots
check_postgres
same_schema
N’hésitez pas, c’est le moment !
https://dali.bo/w5_quiz