pg主库:10.113.217.6
PG从库:10.113.217.9
systemctl start postgresql
ps -ef|grep postgresql postgres 62405 1 0 11:34 ? 00:00:00 /usr/lib/postgresql/9.6/bin/postgres -D /data/pg9.6/main -c config_file=/etc/postgresql/9.6/main/postgresql.conf
listen_addresses = '0.0.0.0' 是否放通对端 hba_file = '/etc/postgresql/9.6/main/pg_hba.conf' 文件位置
主备配置文件放通对端:
添加
host all postgres 10.113.217.9/27 md5 host replication repl 10.113.217.9/27 md5
/data/pg9.6# mv main/ main_bak /data/pg9.6# mkdir main /data/pg9.6# chown -R postgres.postgres main /data/pg9.6# chmod 0700 main/
# su - postgres [postgres@VM-217-9-ubuntu:/var/lib/postgresql]$pg_basebackup -D /data/pg9.6/main --format=p -h 10.113.217.6 -p 5432 -U repl -W -Fp -Xs -Pv -R 【注意Data目录,ip 、端口】
systemctl restart postgresql
SELECT pid,status,last_msg_send_time,last_msg_receipt_time,conninfo FROM pg_stat_wal_receiver ; postgres=# select pg_is_in_recovery(); pg_is_in_recovery ------------------- t (1 row) t为备库 postgres=# select pg_is_in_recovery(); pg_is_in_recovery ------------------- f (1 row) f 为主库。