pg_rman备份pg数据库(在备库执行)
https://github.com/ossc-db/pg_rman
主库的备份无需输入密码:
主库备份:
[postgres@centos01 pg_rman-1.3.17]$ pg_rman init --backup-path=/home/postgres/bak
INFO: ARCLOG_PATH is set to '/postgres/archive'
INFO: SRVLOG_PATH is set to '/postgres/data/log'
[postgres@centos01 pg_rman-1.3.17]$ ll /home/postgres/bak
total 8
drwx------ 4 postgres postgres 34 Apr 9 09:52 backup
-rw-rw-r-- 1 postgres postgres 66 Apr 9 09:52 pg_rman.ini
-rw-rw-r-- 1 postgres postgres 40 Apr 9 09:52 system_identifier
drwx------ 2 postgres postgres 6 Apr 9 09:52 timeline_history
[postgres@centos01 pg_rman-1.3.17]$
[postgres@centos01 pg_rman-1.3.17]$
[postgres@centos01 pg_rman-1.3.17]$ pg_rman backup --backup-mode=full --with-serverlog
ERROR: required parameter not specified: BACKUP_PATH (-B, --backup-path)
[postgres@centos01 pg_rman-1.3.17]$ pg_rman backup --backup-mode=full --with-serverlog --backup-path=/home/postgres/bak
INFO: copying database files
2025-04-09 09:52:53.537 CST [6189] LOG: checkpoint starting: immediate force wait
2025-04-09 09:52:53.633 CST [6189] LOG: checkpoint complete: wrote 4 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.001 s, sync=0.004 s, total=0.096 s; sync files=3, longest=0.002 s, average=0.002 s; distance=10685 kB, estimate=10685 kB
INFO: copying archived WAL files
INFO: copying server log files
INFO: backup complete
INFO: Please execute 'pg_rman validate' to verify the files are correctly copied.
[postgres@centos01 pg_rman-1.3.17]$ pwd
/home/postgres/pg_rman-1.3.17
[postgres@centos01 pg_rman-1.3.17]$ pwd
/home/postgres/pg_rman-1.3.17
[postgres@centos01 pg_rman-1.3.17]$ cd ..
[postgres@centos01 ~]$ ll
total 160
drwxrwxr-x 5 postgres postgres 104 Apr 9 09:52 bak
drwxrwxr-x 9 postgres postgres 4096 Apr 9 09:37 pg_rman-1.3.17
-rw-r--r-- 1 postgres postgres 152583 Apr 9 09:33 pg_rman-1.3.17.zip
drwxrwxrwx. 6 postgres postgres 4096 Apr 7 10:48 postgresql-15.12
[postgres@centos01 ~]$ scp pg_rman-1.3.17.zip centos02:/home/postgres/
pg_rman-1.3.17.zip 100% 149KB 33.1MB/s 00:00
[postgres@centos01 ~]$ 2025-04-09 09:57:53.666 CST [6189] LOG: checkpoint starting: time
2025-04-09 09:57:53.989 CST [6189] LOG: checkpoint complete: wrote 4 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.302 s, sync=0.017 s, total=0.324 s; sync files=3, longest=0.015 s, average=0.006 s; distance=16417 kB, estimate=16417 kB
2025-04-09 09:59:40.224 CST [6189] LOG: checkpoint starting: immediate force wait
2025-04-09 09:59:40.373 CST [6189] LOG: checkpoint complete: wrote 6 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.001 s, sync=0.004 s, total=0.150 s; sync files=3, longest=0.003 s, average=0.002 s; distance=16350 kB, estimate=16410 kB
^C
[postgres@centos01 ~]$
[postgres@centos01 ~]$
[postgres@centos01 ~]$
[postgres@centos01 ~]$ pg_rman show -B /home/postgres/bak
=====================================================================
StartTime EndTime Mode Size TLI Status
=====================================================================
2025-04-09 09:52:53 2025-04-09 09:52:56 FULL 63MB 13 DONE
[postgres@centos01 ~]$ 2025-04-09 10:02:59.279 CST [6189] LOG: checkpoint starting: immediate force wait
2025-04-09 10:02:59.373 CST [6189] LOG: checkpoint complete: wrote 4 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.001 s, sync=0.003 s, total=0.095 s; sync files=3, longest=0.002 s, average=0.001 s; distance=32768 kB, estimate=32768 kB
^C
[postgres@centos01 ~]$
[postgres@centos01 ~]$
[postgres@centos01 ~]$ pg_rman backup --backup-mode=full --with-serverlog --backup-path=/home/postgres/bak
INFO: copying database files
2025-04-09 10:05:01.350 CST [6189] LOG: checkpoint starting: immediate force wait
2025-04-09 10:05:01.645 CST [6189] LOG: checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.001 s, sync=0.003 s, total=0.296 s; sync files=3, longest=0.002 s, average=0.001 s; distance=32768 kB, estimate=32768 kB
INFO: copying archived WAL files
INFO: copying server log files
INFO: backup complete
INFO: Please execute 'pg_rman validate' to verify the files are correctly copied.
[postgres@centos01 ~]$
[postgres@centos01 ~]$
[postgres@centos01 ~]$ pg_rman show -B /home/postgres/bak
=====================================================================
StartTime EndTime Mode Size TLI Status
=====================================================================
2025-04-09 10:05:01 2025-04-09 10:05:03 FULL 164MB 13 DONE
2025-04-09 09:52:53 2025-04-09 09:52:56 FULL 63MB 13 DONE
[postgres@centos01 ~]$
备库备份:
备库执行备份,但需指定host和port连接主库并输入密码。
不想输入密码则可以配置环境变量(方法1):
[postgres@centos02 ~]$ export PGPASSWORD='abcd1234'
[postgres@centos02 ~]$ backup --backup-mode=full --with-serverlog --backup-path=/home/postgres/bak --standby-host=centos02 --standby-port=5432 --host=centos01 --port=5432
INFO: copying database files
2025-04-09 10:08:07.639 CST [13083] LOG: restartpoint starting: immediate wait
2025-04-09 10:08:07.646 CST [13083] LOG: restartpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.002 s, sync=0.002 s, total=0.007 s; sync files=3, longest=0.002 s, average=0.001 s; distance=32768 kB, estimate=32768 kB
2025-04-09 10:08:07.646 CST [13083] LOG: recovery restart point at 0/10000028
2025-04-09 10:08:07.646 CST [13083] DETAIL: Last completed transaction was at log time 2025-04-09 10:08:05.758944+08.
INFO: copying archived WAL files
INFO: copying server log files
INFO: backup complete
INFO: Please execute 'pg_rman validate' to verify the files are correctly copied.
[postgres@centos02 ~]$ pg_rman show -B /home/postgres/bak
=====================================================================
StartTime EndTime Mode Size TLI Status
=====================================================================
2025-04-09 10:08:06 2025-04-09 10:08:09 FULL 30MB 13 DONE
2025-04-09 10:04:35 2025-04-09 10:04:35 FULL 0B 0 ERROR
2025-04-09 10:02:50 2025-04-09 10:03:02 FULL 30MB 13 DONE
2025-04-09 09:59:34 2025-04-09 09:59:43 FULL 30MB 13 DONE
2025-04-09 09:56:45 2025-04-09 09:56:45 FULL 0B 0 ERROR
或者(方法2)配置.pgpass如下:
[postgres@centos02 ~]$ cat .pgpass
centos01:5432:*:postgres:abcd1234
centos02:5432:*:postgres:abcd1234
[postgres@centos02 ~]$ chmod 600 ~/.pgpass
[postgres@centos02 ~]$ chown postgres:postgres ~/.pgpass
[postgres@centos02 ~]$ cat .pgpass
192.168.207.7:5432:*:postgres:abcd1234
[postgres@centos02 ~]$ chmod 600 ~/.pgpass
[postgres@centos02 ~]$ chown postgres:postgres ~/.pgpass
[postgres@centos02 ~]$ cat .pgpass
192.168.207.7:5432:*:postgres:abcd1234
[postgres@centos02 ~]$ pg_rman backup --backup-mode=full --with-serverlog --backup-path=/home/postgres/bak --standby-host=centos02 --standby-port=5432 --host=centos01 --port=5432
Password:
Password:
ERROR: could not connect to database postgres: connection to server at "centos01" (192.168.207.7), port 5432 failed: FATAL: password authentication failed for user "postgres"
[postgres@centos02 ~]$ vi .pgpass
centos01:5432:*:postgres:abcd1234
~
~
".pgpass" 1L, 34C written
[postgres@centos02 ~]$ cat .pgpass
centos01:5432:*:postgres:abcd1234
[postgres@centos02 ~]$ pg_rman backup --backup-mode=full --with-serverlog --backup-path=/home/postgres/bak --standby-host=centos02 --standby-port=5432 --host=centos01 --port=5432
INFO: copying database files
Password:
2025-04-09 10:19:05.213 CST [14377] FATAL: password authentication failed for user "postgres"
2025-04-09 10:19:05.213 CST [14377] DETAIL: Connection matched pg_hba.conf line 96: "host all all 0.001.0/0 scram-sha-256"
ERROR: could not connect to database postgres: connection to server at "centos02" (192.168.207.8), port 5432 failed: FATAL: password authentication failed for user "postgres"
[postgres@centos02 ~]$ vi .pgpass
centos01:5432:*:postgres:abcd1234
centos02:5432:*:postgres:abcd1234
~
~
".pgpass" 2L, 68C written
[postgres@centos02 ~]$ cat .pgpass
centos01:5432:*:postgres:abcd1234
centos02:5432:*:postgres:abcd1234
[postgres@centos02 ~]$ pg_rman backup --backup-mode=full --with-serverlog --backup-path=/home/postgres/bak --standby-host=centos02 --standby-port=5432 --host=centos01 --port=5432
INFO: copying database files
2025-04-09 10:19:36.275 CST [13083] LOG: restartpoint starting: immediate wait
2025-04-09 10:19:36.340 CST [13083] LOG: restartpoint complete: wrote 7 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.002 s, sync=0.060 s, total=0.066 s; sync files=3, longest=0.057 s, average=0.020 s; distance=49152 kB, estimate=49152 kB
2025-04-09 10:19:36.340 CST [13083] LOG: recovery restart point at 0/15000028
2025-04-09 10:19:36.340 CST [13083] DETAIL: Last completed transaction was at log time 2025-04-09 10:19:35.553681+08.
INFO: copying archived WAL files
INFO: copying server log files
INFO: backup complete
INFO: Please execute 'pg_rman validate' to verify the files are correctly copied.
[postgres@centos02 ~]$
[postgres@centos02 ~]$ pwd
/home/postgres
[postgres@centos02 ~]$ ll
total 156
-rw-r--r-- 1 postgres postgres 152583 Apr 9 09:53 pg_rman-1.3.17.zip
drwxrwxrwx. 6 postgres postgres 4096 Apr 7 10:53 postgresql-15.12
[postgres@centos02 ~]$ unzip pg_rman-1.3.17.zip
Archive: pg_rman-1.3.17.zip
0ab83ca41822ee4eddc86386990ef60c8f76f949
creating: pg_rman-1.3.17/
creating: pg_rman-1.3.17/.github/
creating: pg_rman-1.3.17/.github/workflows/
inflating: pg_rman-1.3.17/.github/workflows/Dockerfile
inflating: pg_rman-1.3.17/.github/workflows/build.yml
inflating: pg_rman-1.3.17/.github/workflows/release.yml
inflating: pg_rman-1.3.17/.gitignore
inflating: pg_rman-1.3.17/COPYRIGHT
inflating: pg_rman-1.3.17/Makefile
inflating: pg_rman-1.3.17/README.md
inflating: pg_rman-1.3.17/backup.c
inflating: pg_rman-1.3.17/catalog.c
inflating: pg_rman-1.3.17/data.c
inflating: pg_rman-1.3.17/delete.c
inflating: pg_rman-1.3.17/dir.c
creating: pg_rman-1.3.17/docs/
inflating: pg_rman-1.3.17/docs/index-ja.html
inflating: pg_rman-1.3.17/docs/index.html
inflating: pg_rman-1.3.17/docs/style.css
creating: pg_rman-1.3.17/expected/
inflating: pg_rman-1.3.17/expected/arc_srv_log_management.out
inflating: pg_rman-1.3.17/expected/backup.out
inflating: pg_rman-1.3.17/expected/backup_from_standby.out
inflating: pg_rman-1.3.17/expected/backup_management.out
inflating: pg_rman-1.3.17/expected/delete.out
inflating: pg_rman-1.3.17/expected/init.out
inflating: pg_rman-1.3.17/expected/option.out
inflating: pg_rman-1.3.17/expected/purge.out
inflating: pg_rman-1.3.17/expected/restore.out
inflating: pg_rman-1.3.17/expected/restore_checksum.out
inflating: pg_rman-1.3.17/expected/restore_checksum_1.out
inflating: pg_rman-1.3.17/expected/show.out
inflating: pg_rman-1.3.17/idxpagehdr.h
inflating: pg_rman-1.3.17/init.c
inflating: pg_rman-1.3.17/parray.c
inflating: pg_rman-1.3.17/parray.h
inflating: pg_rman-1.3.17/pg_rman.c
inflating: pg_rman-1.3.17/pg_rman.h
creating: pg_rman-1.3.17/pgsql_src/
inflating: pg_rman-1.3.17/pgsql_src/COPYRIGHT.pgsql_src
inflating: pg_rman-1.3.17/pgsql_src/pg_ctl.c
creating: pg_rman-1.3.17/pgut/
inflating: pg_rman-1.3.17/pgut/pgut-port.c
inflating: pg_rman-1.3.17/pgut/pgut-port.h
inflating: pg_rman-1.3.17/pgut/pgut.c
inflating: pg_rman-1.3.17/pgut/pgut.h
inflating: pg_rman-1.3.17/restore.c
creating: pg_rman-1.3.17/script/
inflating: pg_rman-1.3.17/script/snapshot_script_lvm.sh
inflating: pg_rman-1.3.17/show.c
creating: pg_rman-1.3.17/sql/
inflating: pg_rman-1.3.17/sql/arc_srv_log_management.sh
extracting: pg_rman-1.3.17/sql/arc_srv_log_management.sql
inflating: pg_rman-1.3.17/sql/backup.sh
extracting: pg_rman-1.3.17/sql/backup.sql
inflating: pg_rman-1.3.17/sql/backup_from_standby.sh
extracting: pg_rman-1.3.17/sql/backup_from_standby.sql
inflating: pg_rman-1.3.17/sql/backup_management.sh
extracting: pg_rman-1.3.17/sql/backup_management.sql
inflating: pg_rman-1.3.17/sql/common.sh
inflating: pg_rman-1.3.17/sql/delete.sh
extracting: pg_rman-1.3.17/sql/delete.sql
inflating: pg_rman-1.3.17/sql/init.sh
extracting: pg_rman-1.3.17/sql/init.sql
inflating: pg_rman-1.3.17/sql/option.sh
extracting: pg_rman-1.3.17/sql/option.sql
inflating: pg_rman-1.3.17/sql/purge.sh
extracting: pg_rman-1.3.17/sql/purge.sql
inflating: pg_rman-1.3.17/sql/restore.sh
extracting: pg_rman-1.3.17/sql/restore.sql
extracting: pg_rman-1.3.17/sql/restore_checksum.sql
inflating: pg_rman-1.3.17/sql/show.sh
extracting: pg_rman-1.3.17/sql/show.sql
inflating: pg_rman-1.3.17/util.c
inflating: pg_rman-1.3.17/validate.c
inflating: pg_rman-1.3.17/xlog.c
[postgres@centos02 ~]$ cd pg_rman-1.3.17/
[postgres@centos02 pg_rman-1.3.17]$ ll
total 288
-rw-rw-r-- 1 postgres postgres 60038 Jan 28 13:34 backup.c
-rw-rw-r-- 1 postgres postgres 19759 Jan 28 13:34 catalog.c
-rw-rw-r-- 1 postgres postgres 1716 Jan 28 13:34 COPYRIGHT
-rw-rw-r-- 1 postgres postgres 31219 Jan 28 13:34 data.c
-rw-rw-r-- 1 postgres postgres 14501 Jan 28 13:34 delete.c
-rw-rw-r-- 1 postgres postgres 16358 Jan 28 13:34 dir.c
drwxrwxr-x 2 postgres postgres 62 Jan 28 13:34 docs
drwxrwxr-x 2 postgres postgres 280 Jan 28 13:34 expected
-rw-rw-r-- 1 postgres postgres 4432 Jan 28 13:34 idxpagehdr.h
-rw-rw-r-- 1 postgres postgres 5895 Jan 28 13:34 init.c
-rw-rw-r-- 1 postgres postgres 874 Jan 28 13:34 Makefile
-rw-rw-r-- 1 postgres postgres 3863 Jan 28 13:34 parray.c
-rw-rw-r-- 1 postgres postgres 1377 Jan 28 13:34 parray.h
-rw-rw-r-- 1 postgres postgres 13154 Jan 28 13:34 pg_rman.c
-rw-rw-r-- 1 postgres postgres 12542 Jan 28 13:34 pg_rman.h
drwxrwxr-x 2 postgres postgres 49 Jan 28 13:34 pgsql_src
drwxrwxr-x 2 postgres postgres 72 Jan 28 13:34 pgut
-rw-rw-r-- 1 postgres postgres 4278 Jan 28 13:34 README.md
-rw-rw-r-- 1 postgres postgres 43166 Jan 28 13:34 restore.c
drwxrwxr-x 2 postgres postgres 36 Jan 28 13:34 script
-rw-rw-r-- 1 postgres postgres 7076 Jan 28 13:34 show.c
drwxrwxr-x 2 postgres postgres 4096 Jan 28 13:34 sql
-rw-rw-r-- 1 postgres postgres 1407 Jan 28 13:34 util.c
-rw-rw-r-- 1 postgres postgres 6833 Jan 28 13:34 validate.c
-rw-rw-r-- 1 postgres postgres 1986 Jan 28 13:34 xlog.c
[postgres@centos02 pg_rman-1.3.17]$ make
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/postgres/server/include -lm -I. -I./ -I/postgres/server/include/server -I/postgres/server/include/internal -D_GNU_SOURCE -c -o backup.o backup.c
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/postgres/server/include -lm -I. -I./ -I/postgres/server/include/server -I/postgres/server/include/internal -D_GNU_SOURCE -c -o catalog.o catalog.c
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/postgres/server/include -lm -I. -I./ -I/postgres/server/include/server -I/postgres/server/include/internal -D_GNU_SOURCE -c -o data.o data.c
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/postgres/server/include -lm -I. -I./ -I/postgres/server/include/server -I/postgres/server/include/internal -D_GNU_SOURCE -c -o delete.o delete.c
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/postgres/server/include -lm -I. -I./ -I/postgres/server/include/server -I/postgres/server/include/internal -D_GNU_SOURCE -c -o dir.o dir.c
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/postgres/server/include -lm -I. -I./ -I/postgres/server/include/server -I/postgres/server/include/internal -D_GNU_SOURCE -c -o init.o init.c
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/postgres/server/include -lm -I. -I./ -I/postgres/server/include/server -I/postgres/server/include/internal -D_GNU_SOURCE -c -o parray.o parray.c
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/postgres/server/include -lm -I. -I./ -I/postgres/server/include/server -I/postgres/server/include/internal -D_GNU_SOURCE -c -o pg_rman.o pg_rman.c
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/postgres/server/include -lm -I. -I./ -I/postgres/server/include/server -I/postgres/server/include/internal -D_GNU_SOURCE -c -o restore.o restore.c
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/postgres/server/include -lm -I. -I./ -I/postgres/server/include/server -I/postgres/server/include/internal -D_GNU_SOURCE -c -o show.o show.c
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/postgres/server/include -lm -I. -I./ -I/postgres/server/include/server -I/postgres/server/include/internal -D_GNU_SOURCE -c -o util.o util.c
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/postgres/server/include -lm -I. -I./ -I/postgres/server/include/server -I/postgres/server/include/internal -D_GNU_SOURCE -c -o validate.o validate.c
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/postgres/server/include -lm -I. -I./ -I/postgres/server/include/server -I/postgres/server/include/internal -D_GNU_SOURCE -c -o xlog.o xlog.c
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/postgres/server/include -lm -I. -I./ -I/postgres/server/include/server -I/postgres/server/include/internal -D_GNU_SOURCE -c -o pgsql_src/pg_ctl.o pgsql_src/pg_ctl.c
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/postgres/server/include -lm -I. -I./ -I/postgres/server/include/server -I/postgres/server/include/internal -D_GNU_SOURCE -c -o pgut/pgut.o pgut/pgut.c
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/postgres/server/include -lm -I. -I./ -I/postgres/server/include/server -I/postgres/server/include/internal -D_GNU_SOURCE -c -o pgut/pgut-port.o pgut/pgut-port.c
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 backup.o catalog.o data.o delete.o dir.o init.o parray.o pg_rman.o restore.o show.o util.o validate.o xlog.o pgsql_src/pg_ctl.o pgut/pgut.o pgut/pgut-port.o -L/postgres/server/lib -Wl,--as-needed -Wl,-rpath,'/postgres/server/lib',--enable-new-dtags -L/postgres/server/lib -lpgcommon -lpgport -L/postgres/server/lib -lpq -lpgcommon -lpgport -lssl -lcrypto -lz -lreadline -lpthread -lrt -ldl -lm -o pg_rman
[postgres@centos02 pg_rman-1.3.17]$ make install
/bin/mkdir -p '/postgres/server/bin'
/bin/install -c pg_rman '/postgres/server/bin'
[postgres@centos02 pg_rman-1.3.17]$ pwd
/home/postgres/pg_rman-1.3.17
[postgres@centos02 pg_rman-1.3.17]$ cd ..
[postgres@centos02 ~]$ ll
total 160
drwxrwxr-x 9 postgres postgres 4096 Apr 9 09:54 pg_rman-1.3.17
-rw-r--r-- 1 postgres postgres 152583 Apr 9 09:53 pg_rman-1.3.17.zip
drwxrwxrwx. 6 postgres postgres 4096 Apr 7 10:53 postgresql-15.12
[postgres@centos02 ~]$ mkdir bak
[postgres@centos02 ~]$
[postgres@centos02 ~]$
[postgres@centos02 ~]$ pg_rman backup --backup-mode=full --with-serverlog
ERROR: required parameter not specified: BACKUP_PATH (-B, --backup-path)
[postgres@centos02 ~]$ pg_rman backup --backup-mode=full --with-serverlog --backup-path=/home/postgres/bak
ERROR: required parameter not specified: ARCLOG_PATH (-A, --arclog-path)
[postgres@centos02 ~]$ pg_rman init --backup-path=/home/postgres/bak
INFO: ARCLOG_PATH is set to '/postgres/archive'
INFO: SRVLOG_PATH is set to '/postgres/data/log'
[postgres@centos02 ~]$
[postgres@centos02 ~]$ pg_rman backup --backup-mode=full --with-serverlog --backup-path=/home/postgres/bak
ERROR: please specify both standby host and port
[postgres@centos02 ~]$ 2025-04-09 09:55:38.550 CST [13083] LOG: restartpoint starting: time
2025-04-09 09:55:38.863 CST [13083] LOG: restartpoint complete: wrote 4 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.303 s, sync=0.006 s, total=0.314 s; sync files=3, longest=0.004 s, average=0.002 s; distance=10738 kB, estimate=10738 kB
2025-04-09 09:55:38.863 CST [13083] LOG: recovery restart point at 0/8000028
2025-04-09 09:55:38.863 CST [13083] DETAIL: Last completed transaction was at log time 2025-04-09 09:55:37.178072+08.
[postgres@centos02 ~]$
[postgres@centos02 ~]$
[postgres@centos02 ~]$ pg_rman backup --backup-mode=full --with-serverlog --backup-path=/home/postgres/bak --standby-host=centos02 --standby-port=5432
INFO: copying database files
2025-04-09 09:56:45.171 CST [13546] ERROR: recovery is in progress
2025-04-09 09:56:45.171 CST [13546] HINT: pg_walfile_name_offset() cannot be executed during recovery.
2025-04-09 09:56:45.171 CST [13546] STATEMENT: SELECT * from pg_walfile_name_offset(pg_backup_start($1, $2))
ERROR: query failed: ERROR: recovery is in progress
HINT: pg_walfile_name_offset() cannot be executed during recovery.
query was: SELECT * from pg_walfile_name_offset(pg_backup_start($1, $2))
[postgres@centos02 ~]$ 2025-04-09 09:56:45.171 CST [13546] WARNING: aborting backup due to backend exiting before pg_backup_stop was called
[postgres@centos02 ~]$
[postgres@centos02 ~]$
[postgres@centos02 ~]$ psql
psql (15.12)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges
-----------+----------+----------+-------------+-------------+------------+-----------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
repmgr | repmgr | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
test | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc | =Tc/postgres +
| | | | | | | postgres=CTc/postgres+
| | | | | | | test=CTc/postgres
(5 rows)
postgres=# exit
[postgres@centos02 ~]$ pg_rman backup --backup-mode=full --with-serverlog --backup-path=/home/postgres/bak --standby-host=centos02 --standby-port=54322025-04-09 09:58:00.240 CST [13083] LOG: restartpoint starting: time
2025-04-09 09:58:00.547 CST [13083] LOG: restartpoint complete: wrote 4 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.302 s, sync=0.004 s, total=0.308 s; sync files=3, longest=0.003 s, average=0.002 s; distance=16417 kB, estimate=16417 kB
2025-04-09 09:58:00.547 CST [13083] LOG: recovery restart point at 0/9008540
2025-04-09 09:58:00.547 CST [13083] DETAIL: Last completed transaction was at log time 2025-04-09 09:57:59.947378+08.
repmgr cluster show
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | Connection string
----+----------+---------+-----------+----------+----------+----------+----------+--------------------------------------------------------------------------
1 | centos01 | primary | * running | | default | 100 | 13 | host=192.168.207.7 user=repmgr dbname=repmgr port=5432 connect_timeout=2
2 | centos02 | standby | running | centos01 | default | 100 | 13 | host=192.168.207.8 user=repmgr dbname=repmgr port=5432 connect_timeout=2
[postgres@centos02 ~]$
[postgres@centos02 ~]$
[postgres@centos02 ~]$
[postgres@centos02 ~]$ pg_rman backup --backup-mode=full --with-serverlog --backup-path=/home/postgres/bak --standby-host=centos02 --standby-port=5432 --host=centos01 --port=5432
Password:
INFO: copying database files
2025-04-09 09:59:41.391 CST [13083] LOG: restartpoint starting: immediate wait
2025-04-09 09:59:41.426 CST [13083] LOG: restartpoint complete: wrote 6 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.002 s, sync=0.024 s, total=0.035 s; sync files=3, longest=0.017 s, average=0.008 s; distance=16350 kB, estimate=16410 kB
2025-04-09 09:59:41.426 CST [13083] LOG: recovery restart point at 0/A000028
2025-04-09 09:59:41.426 CST [13083] DETAIL: Last completed transaction was at log time 2025-04-09 09:59:40.468618+08.
INFO: copying archived WAL files
INFO: copying server log files
INFO: backup complete
INFO: Please execute 'pg_rman validate' to verify the files are correctly copied.
[postgres@centos02 ~]$ pg_rman show -B /home/pgsql/bak
WARNING: could not open directory "/home/pgsql/bak": No such file or directory
ERROR: could not get list of backup already taken
[postgres@centos02 ~]$ pg_rman show -B /home/postgres/bak
=====================================================================
StartTime EndTime Mode Size TLI Status
=====================================================================
2025-04-09 09:59:34 2025-04-09 09:59:43 FULL 30MB 13 DONE
2025-04-09 09:56:45 2025-04-09 09:56:45 FULL 0B 0 ERROR
[postgres@centos02 ~]$
相关参考:
PostgreSQL 16.3+pg_rman 1.3.16的测试 - 墨天轮