postgresql_以pg_basebackup的方式部署流复制

部署流复制备库的数据复制环节主要包括以下3个步骤:
1.pg_stat_backup('francs_bk1');

2.拷贝主节点$PGDATA数据文件和表空间文件到备节点;

3.pg_stop_backup();

pg_basebackup工具对数据库实例级别进行物理备份,此工具需要超级用户权限或者replication权限,注意max_wal_sender的参数配置,因为pg_basebackup将至少消耗一个wal发送进程

在备库做一个基准备份

[postgres@localhost pg10]$ pg_basebackup -D /database/pg10/pg_root -Fp -Xs -v -P -h 192.168.12.10 -p 1921 -U repuser
pg_basebackup: initiating base backup, waiting for checkpoint to complete
pg_basebackup: checkpoint completed
pg_basebackup: write-ahead log start point: 0/E000028 on timeline 1
pg_basebackup: starting background WAL receiver
23784/23784 kB (100%), 1/1 tablespace
pg_basebackup: write-ahead log end point: 0/E0000F8
pg_basebackup: waiting for background process to finish streaming ...
pg_basebackup: base backup completed

pg_basebackup命令详解Options controlling the output:

-D, --pgdata=DIRECTORY receive base backup into directory  #指定备节点接收主数据库的目标路径,与主库保持一致
  -F, --format=p|t       output format (plain (default), tar)  #生成的备份数据格式,p(plain)格式(完全一样)和t(tar)格式(被打包成.tar)
-r, --max-rate=RATE maximum transfer rate to transfer data directory (in kB/s, or use suffix "k" or "M") -R, --write-recovery-conf write recovery.conf for replication -S, --slot=SLOTNAME replication slot to use --no-slot prevent creation of temporary replication slot -T, --tablespace-mapping=OLDDIR=NEWDIR relocate tablespace in OLDDIR to NEWDIR -X, --wal-method=none|fetch|stream                  
#在备份工程中产生的wal日志包含在备份中的方式:
f(fetch)wal日志在基准备份完成后被传送到备节点,这是主库上的wal_keep_segments参数必须设置的较大,以免备份过程中的wal还没发送到备节点之前就被主库覆盖掉,主库只启动一个基准备份wal发送进程
s(stream),主库除了启动一个基准备份wal发送进程还会额外另起一个发送进程用于发送主库生产的wal增量日志流,避免主库中wal被覆盖(生产库推荐此方式特别是大库)
    include required WAL files with specified method --waldir=WALDIR location for the write-ahead log directory -z, --gzip compress tar output -Z, --compress=0-9 compress tar output with given compression level General options: -c, --checkpoint=fast|spread set fast or spread checkpointing -l, --label=LABEL set backup label -n, --no-clean do not clean up after errors -N, --no-sync do not wait for changes to be written safely to disk -P, --progress show progress information    #显示数据文件、表空间文件近似传输百分比 -v, --verbose output verbose messages    #打印各阶段的日志 -V, --version output version information, then exit -?, --help show this help, then exit Connection options: -d, --dbname=CONNSTR connection string -h, --host=HOSTNAME database server host or socket directory -p, --port=PORT database server port number -s, --status-interval=INTERVAL time between status packets sent to server (in seconds) -U, --username=NAME connect as specified database user -w, --no-password never prompt for password -W, --password force password prompt (should happen automatically) Report bugs to <pgsql-bugs@postgresql.org>.

 

上一篇:项目开发流程 | 学习笔记


下一篇:对iOS10新增Api的详细探究