麒麟v10 上部署 TiDB v5.1.2 生产环境优化实践
548
2023-05-02
***数据库单机扩展为流复制
1. 在standby服务器安装postgres数据库,不需要初始化.
2. 在primary服务器创建具有REPLICATION权限的复制用户
postgres=# CREATE ROLE repl WITH REPLICATION PASSWORD ‘repl‘ LOGIN;
3. 允许复制用户远程连接到primary服务器
$ grep "^host" pg_hba.conf host all all 127.0.0.1/32 trust host replication repl 0.0.0.0/0 md5 host all all ::1/128 trust
4. 在primary服务器设置流复制相关的参数
5. 重新启动primary服务器进程
$ pg_ctl stop -m fast $ pg_ctl start
6. 对primary服务器做一个全备并传输到standby服务器
在primary服务器通过pg_(start|stop)_backup函数进行备份
在standby服务器通过pg_basebackup命令进行备份,要求standby的PGDATA目录为空
7. 设置standby数据库复制相关参数,使得standby失效转移后可以作为主库工作
8. 在standby文件创建恢复文件
9. 启动standby数据库进程,自动启动流复制
$ pg_ctl start -w waiting for server to start....LOG: could not create IPv6 socket: Address family not supported by protocol LOG: redirecting log output to logging collector process HINT: Future log output will appear in directory "pg_log". done server started
10. 检查primary和standby数据库的延迟
通过函数和系统表查看
edbstore=# select * from pg_stat_replication; #在primary主库查看 -[ RECORD 1 ]----+------------------------------ pid | 15013 usesysid | 19206 usename | repl application_name | walreceiver client_addr | 10.189.100.195 client_hostname | client_port | 56072 backend_start | 2017-06-13 08:10:35.400508-07 backend_xmin | state | streaming sent_location | 7/EC01A588 write_location | 7/EC01A588 flush_location | 7/EC01A588 replay_location | 7/EC01A588 sync_priority | 0 sync_state | async edbstore=# SELECT pg_current_xlog_location(); #在primary主库查看 pg_current_xlog_location -------------------------- 7/EC01A588 (1 row) postgres=# select pg_last_xlog_receive_location(),pg_last_xlog_replay_location(),pg_last_xact_replay_timestamp(); #在standby备库查看 pg_last_xlog_receive_location | pg_last_xlog_replay_location | pg_last_xact_replay_timestamp -------------------------------+------------------------------+------------------------------- 7/EC01A588 | 7/EC01A588 | 2017-06-13 08:25:20.281568-07 (1 row)
通过进程查看
$ ps -ef | grep sender | grep -v grep #在primary库查看 postgres 15013 24883 0 08:10 ? 00:00:00 postgres: wal sender process repl 10.189.100.195(56072) streaming 7/EC01A668 $ ps -ef | grep receiver | grep -v grep #在standby库查看 postgres 12857 12843 0 08:10 ? 00:00:00 postgres: wal receiver process streaming 7/EC01A668
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。