version: '2'
services:
postgresql-slave:
image: 'postgres:13'
ports:
- '5433:5433'
environment:
- POSTGRES_USERNAME=postgres
- POSTGRES_PASSWORD=password
volumes:
- ../postgresql/data:/var/lib/postgresql/data
networks:
- disable_ipv6
networks:
disable_ipv6:
external: true
postgresql-master
su postgres psql -p 5433 CREATE USER replicator WITH REPLICATION ENCRYPTED PASSWORD 'password'; SELECT * FROM pg_create_physical_replication_slot('replication_slot_slave1');
postgresql.conf: wal_level = replica pg_hba.conf: host replication replicator 0.0.0.0/0 trust
postgresql-slaveexec docker-compose
docker-compose exec -it postgresql-slave bash cd /var/lib/postgresql/data
postgresql.conf: wal_level = replica primary_conninfo = 'user=replicator password=password channel_binding=prefer host=masterip port=5433 sslmode=prefer sslcompression=0 ssl_min_protocol_version=TLSv1.2 gssencmode=prefer krbsrvname=postgres target_session_attrs=any' primary_slot_name = 'replication_slot_slave1'
hot_standby = on restore_command = 'cp /var/lib/postgresql/data/pg_wal/%f "%p"' mkdir masterdata cd masterdata pg_basebackup -h masterip -U replicator -p 5433 -D ./ -Fp -Xs -P -R -W exit docker-compose stop postgresq/data: mv *.conf ../ mv masterdata ../ rm -rf * mv ../*.conf ./ mv masterdata/* ./ docker-compose start
postgresql-master
su postgres psql -p 5433 select * from pg_stat_replication;
SELECT * FROM pg_replication_slots;
沒有留言:
張貼留言