概述

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版本)

版本错误的报错

上面说到,如果版本错误或不对应。在编译的时候可能会报错。如下

  1. [postgres@stephen pg_rman]$ make
  2. 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
  3. backup.c: In function do_backup’:
  4. backup.c:888:2: error: too many arguments to function get_controlfile
  5. controlFile = get_controlfile(pgdata, "pg_rman", &crc_ok);
  6. ^
  7. In file included from backup.c:22:0:
  8. /usr/local/pgsql-9.6/include/server/common/controldata_utils.h:15:25: note: declared here
  9. extern ControlFileData *get_controlfile(char *DataDir, const char *progname);
  10. ^
  11. backup.c: In function init_data_checksum_enabled’:
  12. backup.c:2141:3: error: too many arguments to function get_controlfile
  13. controlFile = get_controlfile(pgdata, "pg_rman", &crc_ok);
  14. ^
  15. In file included from backup.c:22:0:
  16. /usr/local/pgsql-9.6/include/server/common/controldata_utils.h:15:25: note: declared here
  17. extern ControlFileData *get_controlfile(char *DataDir, const char *progname);
  18. ^
  19. make: *** [backup.o] Error 1

如果出现以上报错,需要查看自己的pg版本与pg_rman 版本是否适配

如我的pg版本为9.6.11 ,pg_rman的版本使用的是REL96

编译安装

进入到源码包中,执行make

  1. [postgres@xl_pg02 pg_rman-REL9_6_STABLE]$ make
  2. 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
  3. 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
  4. 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
  5. data.c: In function figure_out_segno’:
  6. data.c:1268:8: warning: variable scanned set but not used [-Wunused-but-set-variable]
  7. int scanned;
  8. ^
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. 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

  1. [root@xl_pg02 pg_rman-REL9_6_STABLE]# make install
  2. /usr/bin/mkdir -p '/usr/local/pgsql-9.6.11/bin'
  3. /usr/bin/install -c pg_rman '/usr/local/pgsql-9.6.11/bin'

这样,pg_rman就编译安装完成了

回归测试

在安装完成之后呢,如果觉得有问题,可以跑一下回归测试
make installcheck

  1. [postgres@xl_pg02 pg_rman-REL9_6_STABLE]$ make installcheck
  2. /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
  3. (using postmaster on /tmp, default port)
  4. ============== dropping database "contrib_regression" ==============
  5. NOTICE: database "contrib_regression" does not exist, skipping
  6. DROP DATABASE
  7. ============== creating database "contrib_regression" ==============
  8. CREATE DATABASE
  9. ALTER DATABASE
  10. ============== running regression test queries ==============
  11. test init ... ok
  12. test option ... ok
  13. test show ... FAILED
  14. test delete ... ok
  15. test purge ... ok
  16. test backup ... ok
  17. test backup_management ... ok
  18. test restore ... ok
  19. test restore_checksum ... ok
  20. test backup_from_standby ... ok
  21. test arc_srv_log_management ... ok
  22. =======================
  23. 1 of 11 tests failed.
  24. =======================
  25. The differences that caused some tests to fail can be viewed in the
  26. file "/opt/pg_rman-REL9_6_STABLE/regression.diffs". A copy of the test summary that you see
  27. above is saved in the file "/opt/pg_rman-REL9_6_STABLE/regression.out".
本站文章,未经作者同意,请勿转载,如需转载,请邮件customer@csudata.com.
0 评论  
添加一条新评论