概述
pg_rman 是一个专门为pg打造的在线物理备份工具,类似于oracle的rman,今天,我们就来学习一下如何编译安装一个pg_rman
准备工作
postgres环境
既然是为了备份pg而存在的工具,我们安装使用它,首先需要有pg环境,最好是编译安装。不管是root还是postgres用户都要配置好
需要的 packages
zlib-devel
直接 yum install zlib-devel 即可
获取源码包
pg_rman是一个开源工具,工程地址为:https://github.com/ossc-db/pg_rman
可直接使用git使用(需要注意的是:PG的版本不同,可能支持的pg_rman不同,所以需要根据自己数据库的版本,选择合适的pg_rman版本)
版本错误的报错
上面说到,如果版本错误或不对应。在编译的时候可能会报错。如下
[postgres@stephen pg_rman]$ make
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/usr/local/pgsql-9.6/include -lm -I. -I./ -I/usr/local/pgsql-9.6/include/server -I/usr/local/pgsql-9.6/include/internal -D_GNU_SOURCE -c -o backup.o backup.c
backup.c: In function ‘do_backup’:
backup.c:888:2: error: too many arguments to function ‘get_controlfile’
controlFile = get_controlfile(pgdata, "pg_rman", &crc_ok);
^
In file included from backup.c:22:0:
/usr/local/pgsql-9.6/include/server/common/controldata_utils.h:15:25: note: declared here
extern ControlFileData *get_controlfile(char *DataDir, const char *progname);
^
backup.c: In function ‘init_data_checksum_enabled’:
backup.c:2141:3: error: too many arguments to function ‘get_controlfile’
controlFile = get_controlfile(pgdata, "pg_rman", &crc_ok);
^
In file included from backup.c:22:0:
/usr/local/pgsql-9.6/include/server/common/controldata_utils.h:15:25: note: declared here
extern ControlFileData *get_controlfile(char *DataDir, const char *progname);
^
make: *** [backup.o] Error 1
如果出现以上报错,需要查看自己的pg版本与pg_rman 版本是否适配
如我的pg版本为9.6.11 ,pg_rman的版本使用的是REL96
编译安装
进入到源码包中,执行make
[postgres@xl_pg02 pg_rman-REL9_6_STABLE]$ make
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/usr/local/pgsql-9.6.11/include -lm -I. -I./ -I/usr/local/pgsql-9.6.11/include/server -I/usr/local/pgsql-9.6.11/include/internal -D_GNU_SOURCE -c -o backup.o backup.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/usr/local/pgsql-9.6.11/include -lm -I. -I./ -I/usr/local/pgsql-9.6.11/include/server -I/usr/local/pgsql-9.6.11/include/internal -D_GNU_SOURCE -c -o catalog.o catalog.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/usr/local/pgsql-9.6.11/include -lm -I. -I./ -I/usr/local/pgsql-9.6.11/include/server -I/usr/local/pgsql-9.6.11/include/internal -D_GNU_SOURCE -c -o data.o data.c
data.c: In function ‘figure_out_segno’:
data.c:1268:8: warning: variable ‘scanned’ set but not used [-Wunused-but-set-variable]
int scanned;
^
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/usr/local/pgsql-9.6.11/include -lm -I. -I./ -I/usr/local/pgsql-9.6.11/include/server -I/usr/local/pgsql-9.6.11/include/internal -D_GNU_SOURCE -c -o delete.o delete.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/usr/local/pgsql-9.6.11/include -lm -I. -I./ -I/usr/local/pgsql-9.6.11/include/server -I/usr/local/pgsql-9.6.11/include/internal -D_GNU_SOURCE -c -o dir.o dir.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/usr/local/pgsql-9.6.11/include -lm -I. -I./ -I/usr/local/pgsql-9.6.11/include/server -I/usr/local/pgsql-9.6.11/include/internal -D_GNU_SOURCE -c -o init.o init.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/usr/local/pgsql-9.6.11/include -lm -I. -I./ -I/usr/local/pgsql-9.6.11/include/server -I/usr/local/pgsql-9.6.11/include/internal -D_GNU_SOURCE -c -o parray.o parray.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/usr/local/pgsql-9.6.11/include -lm -I. -I./ -I/usr/local/pgsql-9.6.11/include/server -I/usr/local/pgsql-9.6.11/include/internal -D_GNU_SOURCE -c -o pg_rman.o pg_rman.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/usr/local/pgsql-9.6.11/include -lm -I. -I./ -I/usr/local/pgsql-9.6.11/include/server -I/usr/local/pgsql-9.6.11/include/internal -D_GNU_SOURCE -c -o restore.o restore.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/usr/local/pgsql-9.6.11/include -lm -I. -I./ -I/usr/local/pgsql-9.6.11/include/server -I/usr/local/pgsql-9.6.11/include/internal -D_GNU_SOURCE -c -o show.o show.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/usr/local/pgsql-9.6.11/include -lm -I. -I./ -I/usr/local/pgsql-9.6.11/include/server -I/usr/local/pgsql-9.6.11/include/internal -D_GNU_SOURCE -c -o util.o util.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/usr/local/pgsql-9.6.11/include -lm -I. -I./ -I/usr/local/pgsql-9.6.11/include/server -I/usr/local/pgsql-9.6.11/include/internal -D_GNU_SOURCE -c -o validate.o validate.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/usr/local/pgsql-9.6.11/include -lm -I. -I./ -I/usr/local/pgsql-9.6.11/include/server -I/usr/local/pgsql-9.6.11/include/internal -D_GNU_SOURCE -c -o xlog.o xlog.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/usr/local/pgsql-9.6.11/include -lm -I. -I./ -I/usr/local/pgsql-9.6.11/include/server -I/usr/local/pgsql-9.6.11/include/internal -D_GNU_SOURCE -c -o pgsql_src/pg_ctl.o pgsql_src/pg_ctl.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/usr/local/pgsql-9.6.11/include -lm -I. -I./ -I/usr/local/pgsql-9.6.11/include/server -I/usr/local/pgsql-9.6.11/include/internal -D_GNU_SOURCE -c -o pgut/pgut.o pgut/pgut.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I/usr/local/pgsql-9.6.11/include -lm -I. -I./ -I/usr/local/pgsql-9.6.11/include/server -I/usr/local/pgsql-9.6.11/include/internal -D_GNU_SOURCE -c -o pgut/pgut-port.o pgut/pgut-port.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -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/usr/local/pgsql-9.6.11/lib -Wl,--as-needed -Wl,-rpath,'/usr/local/pgsql-9.6.11/lib',--enable-new-dtags -Wl,--build-id -L/usr/local/pgsql-9.6.11/lib -lpgcommon -lpgport -L/usr/local/pgsql-9.6.11/lib -lpq -lpgcommon -lpgport -lz -lreadline -lrt -lcrypt -ldl -lm -o pg_rman
make install
[root@xl_pg02 pg_rman-REL9_6_STABLE]# make install
/usr/bin/mkdir -p '/usr/local/pgsql-9.6.11/bin'
/usr/bin/install -c pg_rman '/usr/local/pgsql-9.6.11/bin'
这样,pg_rman就编译安装完成了
回归测试
在安装完成之后呢,如果觉得有问题,可以跑一下回归测试
make installcheck
[postgres@xl_pg02 pg_rman-REL9_6_STABLE]$ make installcheck
/usr/local/pgsql-9.6.11/lib/pgxs/src/makefiles/../../src/test/regress/pg_regress --inputdir=./ --bindir='/usr/local/pgsql-9.6.11/bin' --dbname=contrib_regression init option show delete purge backup backup_management restore restore_checksum backup_from_standby arc_srv_log_management
(using postmaster on /tmp, default port)
============== dropping database "contrib_regression" ==============
NOTICE: database "contrib_regression" does not exist, skipping
DROP DATABASE
============== creating database "contrib_regression" ==============
CREATE DATABASE
ALTER DATABASE
============== running regression test queries ==============
test init ... ok
test option ... ok
test show ... FAILED
test delete ... ok
test purge ... ok
test backup ... ok
test backup_management ... ok
test restore ... ok
test restore_checksum ... ok
test backup_from_standby ... ok
test arc_srv_log_management ... ok
=======================
1 of 11 tests failed.
=======================
The differences that caused some tests to fail can be viewed in the
file "/opt/pg_rman-REL9_6_STABLE/regression.diffs". A copy of the test summary that you see
above is saved in the file "/opt/pg_rman-REL9_6_STABLE/regression.out".