数据库
首页 > 数据库> > postgresql整机迁移后主从恢复

postgresql整机迁移后主从恢复

作者:互联网

postgresql整机迁移后主从恢复

pg迁移后的环境

pg主库:10.113.217.6
PG从库:10.113.217.9

登录主机,启动postgresql

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

查看配置文件 postgresql.conf,检查监听

listen_addresses = '0.0.0.0' 是否放通对端
hba_file = '/etc/postgresql/9.6/main/pg_hba.conf'   文件位置

主备库都执行修改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目录重建下

/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 为主库。

标签:整机,postgres,后主,pg,postgresql,main,data,pg9.6
来源: https://blog.csdn.net/weixin_44871069/article/details/120178866