原 【DB宝72】pgpool-II和pgpoolAdmin的使用
Tags: 原创PGLinux高可用监控Pgpool-IIpgpoolAdmin
3.3、从库操作
3.3.1、在从库对主库进行备份
这里,我们在第一个从库上进行备份即可。
1 2 3 4 5 6 7 8 | docker exec -it lhrpg64303 bash mkdir -p /bk chown postgres:postgres /bk su - postgres pg_basebackup -h 172.72.6.2 -p 5432 -U replhr -l bk20210422 -F p -P -R -D /bk |
执行完成后,会产生文件standby.signal,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | root@lhrpg64303:/# mkdir -p /bk root@lhrpg64303:/# chown postgres:postgres /bk root@lhrpg64303:/# root@lhrpg64303:/# su - postgres postgres@lhrpg64303:~$ postgres@lhrpg64303:~$ pg_basebackup -h 172.72.6.2 -p 5432 -U replhr -l bk20210422 -F p -P -R -D /postgresql/pgdata Password: 24560/24560 kB (100%), 1/1 tablespace postgres@lhrpg64303:~$ cd /postgresql/pgdata/ postgres@lhrpg64303:/postgresql/pgdata$ ll -bash: ll: command not found postgres@lhrpg64303:/postgresql/pgdata$ ls -l total 116 -rw------- 1 postgres postgres 3 Apr 22 10:52 PG_VERSION -rw------- 1 postgres postgres 209 Apr 22 10:52 backup_label drwx------ 5 postgres postgres 4096 Apr 22 10:52 base drwx------ 2 postgres postgres 4096 Apr 22 10:52 global drwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_commit_ts drwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_dynshmem -rw-r--r-- 1 postgres postgres 243 Apr 22 10:52 pg_hba.conf -rw------- 1 postgres postgres 1636 Apr 22 10:52 pg_ident.conf drwx------ 4 postgres postgres 4096 Apr 22 10:52 pg_logical drwx------ 4 postgres postgres 4096 Apr 22 10:52 pg_multixact drwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_notify drwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_replslot drwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_serial drwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_snapshots drwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_stat drwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_stat_tmp drwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_subtrans drwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_tblspc drwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_twophase drwx------ 3 postgres postgres 4096 Apr 22 10:52 pg_wal drwx------ 2 postgres postgres 4096 Apr 22 10:52 pg_xact -rw------- 1 postgres postgres 255 Apr 22 10:52 postgresql.auto.conf -rw------- 1 postgres postgres 26756 Apr 22 10:52 postgresql.conf -rw------- 1 postgres postgres 0 Apr 22 10:52 standby.signal postgres@lhrpg64303:/postgresql/pgdata$ |
? 在PG12之前,-R备份结束之后会自动生成recovery.conf文件,用来做流复制判断主从同步的信息。但是从PG12开始,这个文件已经不需要了。只需要在参数文件postgresql.conf中配置primary_conninfo参数即可。
3.3.2、还原从库1
1 2 3 4 | -- 关闭从库1,删除从库的数据文件,并且将备份文件覆盖从库的数据文件 docker stop lhrpg64303 rm -rf /docker_data/pg/lhrpg64303/data/* cp -r /docker_data/pg/lhrpg64303/bk/* /docker_data/pg/lhrpg64303/data/ |
3.3.3、还原从库2
1 2 3 4 | -- 关闭从库2,删除从库的数据文件,并且将备份文件覆盖从库的数据文件 docker stop lhrpg64304 rm -rf /docker_data/pg/lhrpg64304/data/* cp -r /docker_data/pg/lhrpg64303/bk/* /docker_data/pg/lhrpg64304/data/ |
3.3.4、修改2个从库的primary_conninfo参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | -- 从库1 cat >> /docker_data/pg/lhrpg64303/data/postgresql.conf <<"EOF" primary_conninfo = 'host=172.72.6.2 port=5432 user=replhr password=lhr' EOF -- 从库2 cat >> /docker_data/pg/lhrpg64304/data/postgresql.conf <<"EOF" primary_conninfo = 'host=172.72.6.2 port=5432 user=replhr password=lhr' EOF |
3.3.5、启动从库
1 | docker start lhrpg64303 lhrpg64304 |
主库进程:
1 2 3 4 5 6 7 8 9 10 11 | root@lhrpg64302:/# ps -ef|grep post postgres 1 0 0 11:35 ? 00:00:00 postgres postgres 26 1 0 11:35 ? 00:00:00 postgres: checkpointer postgres 27 1 0 11:35 ? 00:00:00 postgres: background writer postgres 28 1 0 11:35 ? 00:00:00 postgres: walwriter postgres 29 1 0 11:35 ? 00:00:00 postgres: autovacuum launcher postgres 30 1 0 11:35 ? 00:00:00 postgres: archiver last was 000000010000000000000006.00000028.backup postgres 31 1 0 11:35 ? 00:00:00 postgres: stats collector postgres 32 1 0 11:35 ? 00:00:00 postgres: logical replication launcher postgres 33 1 0 11:35 ? 00:00:00 postgres: postgres postgres 172.72.6.1(52776) idle postgres 129 1 0 11:48 ? 00:00:00 postgres: walsender replhr 172.72.6.3(40056) streaming 0/7000148 |
不错不错哈