PostgreSQL备份工具:pg_rman编译安装

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
简介: pg_rman编译安装

概述

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".
相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
1月前
|
关系型数据库 Java 数据库连接
PostgreSQL从小白到高手教程 - 第47讲:JMETER工具使用
PostgreSQL从小白到高手教程 - 第47讲:JMETER工具使用
101 3
|
3月前
|
关系型数据库 MySQL 数据库
rds备份与恢复
rds备份与恢复
53 3
|
3月前
|
关系型数据库 MySQL 数据库
Python tk dos命令备份mysql数据库
Python tk dos命令备份mysql数据库
23 0
|
3月前
|
存储 关系型数据库 MySQL
mysql数据库如何做到定期备份
mysql数据库如何做到定期备份
288 2
|
3月前
|
存储 关系型数据库 Java
polardb有没有搞过pg 全量及增量备份管理的
【1月更文挑战第3天】【1月更文挑战第11篇】 polardb有没有搞过pg 全量及增量备份管理的
33 1
|
2月前
|
SQL 关系型数据库 MySQL
mysql怎么备份
mysql怎么备份
185 7
|
3月前
|
存储 关系型数据库 MySQL
利用Xtrabackup进行mysql增量备份和全量备份
利用Xtrabackup进行mysql增量备份和全量备份
165 0
|
2月前
|
关系型数据库 MySQL Linux
Linux环境下定时备份mysql数据库
Linux环境下定时备份mysql数据库
|
2月前
|
存储 关系型数据库 MySQL
mysql怎么备份
mysql怎么备份
21 7
|
2月前
|
监控 容灾 安全
规划阿里云RDS跨区迁移并构建容灾与备份策略
规划阿里云RDS(Relational Database Service)跨区迁移并构建容灾与备份策略
107 2