PostgreSQL备份工具:pg_rman编译安装

本文涉及的产品
云原生数据库 PolarDB PostgreSQL 版,标准版 2核4GB 50GB
云原生数据库 PolarDB MySQL 版,通用型 2核4GB 50GB
简介: 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数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
2月前
|
存储 关系型数据库 MySQL
mysql数据库备份与恢复
MySQL数据库的备份与恢复是确保数据安全性和业务连续性的关键操作。
65 4
|
3月前
|
存储 关系型数据库 数据库
PostgreSQL的备份策略
【8月更文挑战第4天】PostgreSQL的备份策略
125 4
|
5月前
|
存储 SQL 关系型数据库
|
1月前
|
安全 关系型数据库 MySQL
MySQL用户备份
【10月更文挑战第2天】MySQL用户备份
52 3
|
1月前
|
存储 关系型数据库 MySQL
MySQL如何备份?
【10月更文挑战第2天】MySQL如何备份?
82 3
|
3月前
|
SQL 关系型数据库 MySQL
在Linux中,如何备份和恢复MySQL数据库?
在Linux中,如何备份和恢复MySQL数据库?
|
3月前
|
SQL 数据可视化 关系型数据库
MySQL 备份可视化巡检系统
MySQL 备份可视化巡检系统
|
3月前
|
SQL 存储 关系型数据库
MySQL备份:mydumper 备份恢复工具生产实战
MySQL备份:mydumper 备份恢复工具生产实战
|
3月前
|
安全 关系型数据库 MySQL
揭秘MySQL海量数据迁移终极秘籍:从逻辑备份到物理复制,解锁大数据迁移的高效与安全之道
【8月更文挑战第2天】MySQL数据量很大的数据库迁移最优方案
606 17
|
3月前
|
存储 Ubuntu 关系型数据库
如何在 Ubuntu VPS 上备份 PostgreSQL 数据库
如何在 Ubuntu VPS 上备份 PostgreSQL 数据库
27 1