抢先体验PostgreSQL v17.0
- 说明:在https://www.postgresql.org/ftp/source已支持下载PostgreSQL 17.0 1安装包了,赶快来体验吧!!!
一、PostgreSQL 17.0 1新功能预览
PostgreSQL全球开发团队宣布,PostgreSQL 17的第一个候选版本现已可供下载。作为发布候选版本,PostgreSQL 17.0 1将与PostgreSQL 17的初始版本基本相同,但在PostgreSQL 17普遍可用之前可能会应用更多的修复。
要将 PostgreSQL 17.0 1 从较早的 PostgreSQL 版本升级,您需要使用主要版本升级策略,例如 pg_upgrade 或 pg_dump / pg_restore。有关更多信息,请访问升级文档部分。
这是PostgreSQL 17的第一个发布候选版本。除非发现需要延迟或制作额外的发布候选版本的问题,否则PostgreSQL 17应该在2024年9月26日普遍可用。
有关更多信息,请参阅“测试版”页面。
PostgreSQL beta 和发布候选版本是社区发布新版本之前的预发布测试版本。它们的功能冻结(即不再添加新功能),我们在最终发布之前会将其发布给公众进行测试。PostgreSQL beta 和发布候选版本不适用于生产系统。
测试版和发布候选版会提前向社区开放,以便在首次发布前进行测试。它们对于依赖PostgreSQL的平台、驱动程序、工具和实用程序的开发者特别有用,可以帮助他们为新版本的变化做好准备。虽然发布候选版应该与新的主要版本的PostgreSQL初始发布完全相同,但在正式发布之前可能会做出额外的更改。
每个PostgreSQL版本的稳定性在很大程度上取决于社区测试即将发布的版本,使用您的工作负载和测试工具,以便在初始发布之前发现错误和回归。用户测试的质量有助于确定我们何时可以进行最终发布。
PostgreSQL全球开发团队强烈建议不要在生产安装或活跃开发项目中使用PostgreSQL的测试版本。虽然PostgreSQL代码不断受到许多自动和手动测试,但测试版本可能会存在严重错误。在任何测试版本的开发过程中,功能都可能发生向后不兼容的变化,甚至可能完全被移除。
在PostgreSQL Beta 3期间,为PostgreSQL 17应用了几个错误修复。这些包括:
- 恢复合并/拆分分区功能。
- 修复了提高逻辑解码子事务性能的功能。
- 有关详细修复列表,请访问 未解决问题 页面。
二、部署体验
2.1、环境规划
主机名称 Server
主机IP 117.72.67.88
操作系统 CentOS Linux 7.9
PostgreSQL版本 17.0 1
2.2、环境检查
[root@lavm-y2jz8vut0h ~]# hostnamectl
Static hostname: lavm-y2jz8vut0h
Icon name: computer-vm
Chassis: vm
Machine ID: 22276d54e9754e518df481c64128cd63
Boot ID: ade130202b33421a9d34795e8380255a
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1160.el7.x86_64
Architecture: x86-64
[root@lavm-y2jz8vut0h ~]#
[root@lavm-y2jz8vut0h ~]#
2.3、修改主机名
vi /etc/hostname
或 hostnamectl set-hostname Node1
2.4、关闭SELINUX
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
2.5、关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
或设置开放端口:
查看开放的端口:
firewall-cmd --list-ports
开启防火墙端口:
firewall-cmd --zone=public --add-port=5432/tcp --permanent
命令含义:
–zone #作用域
–add-port=9200/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
重新加载一遍才会生效:
firewall-cmd --reload
2.6、安装插件
yum -y install readline readline-devel zlib zlib-devel gettext gettext-devel openssl openssl-devel pam pam-devel libxml2 libxml2-devel libxslt libxslt-devel perl perl-devel tcl-devel uuid-devel gcc gcc-c++ make flex bison perl-ExtUtils* libicu libicu-devel ntp libcurl-devel
2.7、编辑hosts
cat>>/etc/hosts<<EOF
192.168.1.71 Node1
EOF
2.8、用户limits设置
cat>>/etc/security/limits.conf<<EOF
postgres soft nofile 1048576
postgres hard nofile 1048576
postgres soft nproc 131072
postgres hard nproc 131072
postgres soft stack 10240
postgres hard stack 32768
postgres soft core 6291456
postgres hard core 6291456
EOF
2.9、调整内核参数
cat>>/etc/sysctl.conf<<EOF
fs.file-max = 76724200
kernel.sem = 10000 10240000 10000 1024
kernel.shmmni = 4096
kernel.shmall = 253702
kernel.shmmax = 1039163392
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_max = 1048576
fs.aio-max-nr = 40960000
vm.dirty_ratio=20
vm.dirty_background_ratio=3
vm.dirty_writeback_centisecs=100
vm.dirty_expire_centisecs=500
vm.swappiness=10
vm.min_free_kbytes=524288
vm.swappiness=0
vm.overcommit_memory=2
vm.overcommit_ratio=75
net.ipv4.ip_local_port_range = 10000 65535
EOF
sysctl -p
2.10、检查主机时间
[root@lavm-y2jz8vut0h ~]# date
Fri Sep 6 13:08:10 CST 2024
[root@lavm-y2jz8vut0h ~]#
2.11、创建数据库用户
- 说明:注:在主机上创建DBA用户
groupadd postgres -g 3000
useradd postgres -g 3000 -u 3000
echo "postgres"|passwd --stdin postgres
2.12、配置sudo
sed -i.bak '100apostgres ALL=(ALL) NOPASSWD:ALL' /etc/sudoers
该配置属于个人建议,为方便操作,配置sudo;为安全起见,可以不配置sudo。
2.13、数据库安装目录规划
目录编号 目录名称 备注
1 postgres postgres根目录
2 /postgres/server 软件安装目录
3 /postgres/data 数据目录
4 /postgres/WAL WAL 目录
5 /postgres/archive 归档目录
6 /postgres/backup 备份目录
7 /install 安装包上传目录
8 /postgres/repmgr 集群安装目录
9 /postgres/repmgr/log 集群日志目录
2.14、创建安装目录
mkdir /install
chmod -R 777 /install
mkdir /postgres
mkdir -p /postgres/server /postgres/data /postgres/wal /postgres/archive /postgres/backup
sudo chown -R postgres:postgres /postgres /install
chmod 0775 /postgres
chmod 0700 /postgres/data
2.15、下载安装包
su postgres
cd /install
wget https://ftp.postgresql.org/pub/source/v17.0/postgresql-17.0.tar.gz
tar -zxvf postgresql-17.0.tar.gz
[postgres@Node2 install]$ wget https://ftp.postgresql.org/pub/source/v17.0/postgresql-17.0.tar.gz
--2024-09-29 21:30:01-- https://ftp.postgresql.org/pub/source/v17.0/postgresql-17.0.tar.gz
Resolving ftp.postgresql.org (ftp.postgresql.org)... 147.75.85.69, 217.196.149.55, 87.238.57.227, ...
Connecting to ftp.postgresql.org (ftp.postgresql.org)|147.75.85.69|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 27865263 (27M) [application/octet-stream]
Saving to: ‘postgresql-17.0.tar.gz’
100%[=================================================>] 27,865,263 3.11MB/s in 8.3s
2024-09-29 21:31:10 (3.22 MB/s) - ‘postgresql-17.0.tar.gz’ saved [27865263/27865263]
[postgres@Node2 install]$
2.16、解压安装包
[postgres@Node2 install]$ tar -zxvf postgresql-17.0.tar.gz
postgresql-17.0/
postgresql-17.0/.cirrus.star
postgresql-17.0/.cirrus.tasks.yml
postgresql-17.0/.cirrus.yml
postgresql-17.0/.dir-locals.el
postgresql-17.0/.editorconfig
postgresql-17.0/.git-blame-ignore-revs
postgresql-17.0/.gitattributes
postgresql-17.0/.gitignore
postgresql-17.0/COPYRIGHT
postgresql-17.0/GNUmakefile.in
postgresql-17.0/HISTORY
postgresql-17.0/Makefile
postgresql-17.0/README.md
postgresql-17.0/aclocal.m4
postgresql-17.0/config/
.............................................................
postgresql-17.0/src/tools/win32tzlist.pl
postgresql-17.0/src/tutorial/
postgresql-17.0/src/tutorial/.gitignore
postgresql-17.0/src/tutorial/Makefile
postgresql-17.0/src/tutorial/README
postgresql-17.0/src/tutorial/advanced.source
postgresql-17.0/src/tutorial/basics.source
postgresql-17.0/src/tutorial/complex.c
postgresql-17.0/src/tutorial/complex.source
postgresql-17.0/src/tutorial/funcs.c
postgresql-17.0/src/tutorial/funcs.source
postgresql-17.0/src/tutorial/syscat.source
[postgres@Node2 install]$
2.17、切换安装目录
[postgres@Node2 install]$ cd /install/postgresql-17.0
[postgres@Node2 postgresql-17rc1]$
2.18、编译安装
- 语法:
./configure --prefix=/postgres/server --with-pgport=5432 --with-openssl
使用 make 或者 make world
$ make world
使用 make install 或者 make install-world 进行安装
$ make install-world #包含扩展包和文档
- 安装过程:
[postgres@Node2 postgresql-17.0]$ ./configure --prefix=/postgres/server --with-pgport=5432 --with-openssl
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking which template to use... linux
checking whether NLS is wanted... no
checking for default port number... 5432
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for gcc option to accept ISO C99... -std=gnu99
checking for g++... g++
.......................................
checking whether gcc -std=gnu99 supports -Wl,--as-needed, for LDFLAGS... yes
checking whether gcc -std=gnu99 supports -Wl,--export-dynamic, for LDFLAGS_EX_BE... yes
configure: using compiler=gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
configure: using CFLAGS=-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
configure: using CPPFLAGS= -D_GNU_SOURCE
configure: using LDFLAGS= -Wl,--as-needed
configure: creating ./config.status
config.status: creating GNUmakefile
config.status: creating src/Makefile.global
config.status: creating src/include/pg_config.h
config.status: creating src/include/pg_config_ext.h
config.status: creating src/interfaces/ecpg/include/ecpg_config.h
config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s
config.status: linking src/backend/port/posix_sema.c to src/backend/port/pg_sema.c
config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c
config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
config.status: linking src/makefiles/Makefile.linux to src/Makefile.port
[postgres@Node2 postgresql-17.0]$
[postgres@Node2 postgresql-17.0]$ make && make install
make -C ./src/backend generated-headers
make[1]: Entering directory `/install/postgresql-17.0/src/backend'
make -C ../include/catalog generated-headers
make[2]: Entering directory `/install/postgresql-17.0/src/include/catalog'
'/usr/bin/perl' ../../../src/backend/catalog/genbki.pl --include-path=../../../src/include/ \
............................................................................................
make[2]: Leaving directory `/install/postgresql-17.0/src/test/isolation'
make -C test/perl install
make[2]: Entering directory `/install/postgresql-17.0/src/test/perl'
make[2]: Nothing to be done for `install'.
make[2]: Leaving directory `/install/postgresql-17.0/src/test/perl'
/usr/bin/mkdir -p '/postgres/server/lib/pgxs/src'
/usr/bin/install -c -m 644 Makefile.global '/postgres/server/lib/pgxs/src/Makefile.global'
/usr/bin/install -c -m 644 Makefile.port '/postgres/server/lib/pgxs/src/Makefile.port'
/usr/bin/install -c -m 644 ./Makefile.shlib '/postgres/server/lib/pgxs/src/Makefile.shlib'
/usr/bin/install -c -m 644 ./nls-global.mk '/postgres/server/lib/pgxs/src/nls-global.mk'
make[1]: Leaving directory `/install/postgresql-17.0/src'
make -C config install
make[1]: Entering directory `/install/postgresql-17.0/config'
/usr/bin/mkdir -p '/postgres/server/lib/pgxs/config'
/usr/bin/install -c -m 755 ./install-sh '/postgres/server/lib/pgxs/config/install-sh'
/usr/bin/install -c -m 755 ./missing '/postgres/server/lib/pgxs/config/missing'
make[1]: Leaving directory `/install/postgresql-17.0/config'
[postgres@Node2 postgresql-17.0]$
2.19、创建软连接
su root
mkdir /postgresql
chmod -R 777 /postgresql
chown -R postgres:postgres /postgresql
cd /postgres
ln -s /postgres/server /postgresql
2.20、设置环境变量
vi /home/postgres/.bashrc
export PGPORT=5432
export PGUSER=postgres
export PGHOME=/postgres/server
export PGDATA=/postgres/data
export PATH=$PGHOME/bin:$PATH
source /home/postgres/.bashrc
2.21、初始化数据库
/postgresql/server/bin/initdb -D /postgres/data -X/postgres/wal -EUTF8 -Upostgres -W --data-checksums --pwprompt
[postgres@Node2 ~]$ /postgresql/server/bin/initdb -D /postgres/data -X/postgres/wal -EUTF8 -Upostgres -W --data-checksums --pwprompt
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default text search configuration will be set to "english".
Data page checksums are enabled.
Enter new superuser password:
Enter it again:
fixing permissions on existing directory /postgres/data ... ok
fixing permissions on existing directory /postgres/wal ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default "max_connections" ... 100
selecting default "shared_buffers" ... 128MB
selecting default time zone ... Asia/Shanghai
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
/postgresql/server/bin/pg_ctl -D /postgres/data -l logfile start
[postgres@Node2 ~]$
2.22、修改postgresql.conf配置信息
echo "PORT=5432">> /postgres/data/postgresql.conf
echo "listen_addresses='*'">> /postgres/data/postgresql.conf
2.23、修改pg_hba.conf配置信息,可以在内网访问
[postgres@Server ~]$ vi $PGDATA/pg_hba.conf
增加一列:
host all all 0.0.0.0/0 scram-sha-256
2.24、启动数据库
[postgres@Node2 ~]$ pg_ctl -D $PGDATA -l logfile start
waiting for server to start.... done
server started
[postgres@Node2 ~]$
三.新增功能演示
3.1、pg_basebackup新增增量备份
1、重要提示:
- pg_basebackup用于对正在运行的PostgreSQL数据库集群进行基本备份。备份不会影响数据库的其他客户端,并且可以用于时间点恢复(请参见第 25.3 节),也可以用作日志传送或流复制备用服务器的起点(请参见第 26.2 节) 。
- pg_basebackup可以对数据库进行完整或增量基本备份。当用于进行完整备份时,它会制作数据库集群文件的精确副本。当用于进行增量备份时,一些本来属于完整备份的文件可能会被替换为相同文件的增量版本,仅包含自参考备份以来已修改的那些块。增量备份不能直接使用;相反,必须首先使用pg_combinebackup将其与它所依赖的先前备份组合起来。有关增量备份的更多信息,请参阅第 25.3.3 节,有关从备份恢复的步骤,请参阅第 25.3.5 节。
- 在任何模式下,pg_basebackup确保服务器自动进入和退出备份模式。始终对整个数据库集群进行备份;无法备份单个数据库或数据库对象。对于选择性备份,必须使用另一个工具,例如pg_dump 。
- 备份是通过使用复制协议的常规PostgreSQLREPLICATION连接进行的。连接必须使用具有权限(请参阅第 21.2 节)或者是超级用户的用户 ID 进行,并且pg_hba.conf必须允许复制连接。服务器还必须将max_wal_senders配置得足够高,以提供至少一个用于备份的 walsender 以及一个用于 WAL 流(如果使用)的 walsender。
- 可以有多个pg_basebackup同时运行,但从性能角度来看,通常最好只进行一次备份并复制结果。
- pg_basebackup不仅可以从主服务器也可以从备用服务器进行基本备份。要从备用数据库进行备份,请设置备用数据库,以便它可以接受复制连接(即设置max_wal_senders和hot_standby,并对其进行pg_hba.conf适当配置)。您还需要在主数据库上启用full_page_writes 。
请注意,从备用数据库进行备份有一些限制:
备份历史文件不会在备份的数据库集群中创建。
- pg_basebackup无法强制备用数据库在备份结束时切换到新的 WAL 文件。当您使用 时-X none,如果主服务器上的写入活动较低,pg_basebackup可能需要等待很长时间才能切换和归档备份所需的最后一个 WAL 文件。在这种情况下,pg_switch_wal在主服务器上运行以触发立即 WAL 文件切换可能会很有用。
- 如果在备份过程中将备用数据库提升为主数据库,则备份会失败。
- 备份所需的所有 WAL 记录必须包含足够的整页写入,这需要您full_page_writes在主服务器上启用。
- 每当pg_basebackup进行基本备份时,服务器的pg_stat_progress_basebackup视图都会报告备份的进度。详细信息请参见第 27.4.6 节。
2、创建备份目录、日志目录
```
mkdir -p /postgres/backup/manifest /postgres/backup/incremental
chmod -R 750 /postgres/backup
chown -R postgres:postgres /postgres/backup
```
mkdir -p /postgres/data/log
chmod -R 777 /postgres/data/log
chown -R postgres:postgres /postgres/data/log
3、修改配置文件
cat >> /postgres/data/postgresql.conf <<EOF
listen_addresses = '*'
port = 5432
archive_mode = on
archive_command = 'test ! -f /postgres/archive/%f && cp %p /postgres/archive/%f'
log_directory = '/postgres/data/log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
EOF
cat >> /postgres/data/pg_hba.conf <<EOF
host all postgres 192.168.1.0/24 scram-sha-256
host replication postgres 192.168.1.0/24 scram-sha-256
EOF
4、如果要使用pg_basebackup做增量备份,需开启以下配置项
以下设置控制WAL摘要,必须启用此功能才能执行增量备份。
- summarize_wal(布尔值)
启用WAL汇总程序。请注意,WAL摘要可以在主服务器或备用服务器上启用。此参数只能在postgresql.conf文件或服务器命令行上设置。默认设置为关闭。
如果wal_level设置为最小值,则无法在summarize_wal=on的情况下启动服务器。如果summarze_wal=on是在服务器启动后配置的,而wal_level=minimal,则汇总程序将运行,但拒绝为wal_level=minimal生成的任何wal生成摘要文件。- wal_summary_keep_time(整数)
配置WAL摘要生成器自动删除旧WAL摘要的时间量。文件时间戳用于确定哪些文件足够旧,可以删除。通常,您应该将其设置得比备份和依赖于它的后续增量备份之间可能经过的时间要长。从之前的备份到正在进行的新备份之间的整个WAL记录范围都必须有WAL摘要;否则,增量备份将失败。如果此参数设置为零,WAL摘要将不会自动删除,但手动删除您知道未来增量备份不需要的文件是安全的。此参数只能在postgresql.conf文件或服务器命令行上设置。如果指定此值时没有单位,则将其视为分钟。默认值为10天。如果summarze_wal=off,则无论此参数的值如何,现有的wal摘要都不会被删除,因为wal摘要生成器将不会运行。
cat >> /postgres/data/postgresql.conf <<EOF
summarize_wal = on
wal_summary_keep_time = 10d
EOF
重启PG服务
pg_ctl restart
5、导入测试数据,并做全量备份
- 脚本如下:
- pg_basebackup -h localhost -p 5432 -U postgres -Xs -Ft -z -Pv -Z9 -D /postgres/backup/manifest
[postgres@Node2 ~]$ pg_basebackup -h localhost -p 5432 -U postgres -Xs -Ft -z -Pv -Z9 -D /postgres/backup/manifest
pg_basebackup: initiating base backup, waiting for checkpoint to complete
2024-09-29 21:35:01.472 CST [1971] LOG: checkpoint starting: force wait
2024-09-29 21:35:01.535 CST [1971] LOG: checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 2 recycled; write=0.002 s, sync=0.002 s, total=0.064 s; sync files=2, longest=0.001 s, average=0.001 s; distance=16384 kB, estimate=16384 kB; lsn=0/4000080, redo lsn=0/4000028
pg_basebackup: checkpoint completed
pg_basebackup: write-ahead log start point: 0/4000028 on timeline 1
pg_basebackup: starting background WAL receiver
pg_basebackup: created temporary replication slot "pg_basebackup_1983"
31539/31539 kB (100%), 1/1 tablespace
pg_basebackup: write-ahead log end point: 0/4000120
pg_basebackup: waiting for background process to finish streaming ...
pg_basebackup: syncing data to disk ...
pg_basebackup: renaming backup_manifest.tmp to backup_manifest
pg_basebackup: base backup completed
[postgres@Node2 ~]$
6、增量备份
添加测试数据:
ANALYZE
ANALYZE
postgres=# CREATE TABLE t_test(ID INT PRIMARY KEY NOT NULL,NAME TEXT NOT NULL,AGE INT NOT NULL,ADDRESS CHAR(50),SALARY REAL);
CREATE TABLE
postgres=# insert into t_test SELECT generate_series(1,500000) as key,repeat( chr(int4(random()*26)+65),4), (random()*(6^2))::in
teger,null,(random()*(10^4))::integer;
INSERT 0 500000
postgres=#
增量备份脚本:
pg_basebackup -h localhost -p 5432 -U postgres -i /postgres/backup/manifest/backup_manifest -Xs -Ft -z -Pv -Z9 -D /postgres/backup/incremental
[postgres@Node2 ~]$ pg_basebackup -h localhost -p 5432 -U postgres -i /postgres/backup/manifest/backup_manifest -Xs -Ft -z -Pv -Z9 -D /postgres/backup/incremental
pg_basebackup: initiating base backup, waiting for checkpoint to complete
2024-09-29 21:36:27.658 CST [14926] LOG: checkpoint starting: force wait
2024-09-29 21:36:27.671 CST [14926] LOG: checkpoint complete: wrote 0 buffers (0.0%); 0 WAL file(s) added, 0 removed, 1 recycled; write=0.001 s, sync=0.001 s, total=0.013 s; sync files=0, longest=0.000 s, average=0.000 s; distance=16384 kB, estimate=16384 kB; lsn=0/9000080, redo lsn=0/9000028
2024-09-29 21:36:27.672 CST [14950] WARNING: aborting backup due to backend exiting before pg_backup_stop was called
2024-09-29 21:36:27.672 CST [14950] ERROR: WAL summaries are required on timeline 1 from 0/5000028 to 0/9000028, but the summaries for that timeline and LSN range are incomplete
2024-09-29 21:36:27.672 CST [14950] DETAIL: The first unsummarized LSN in this range is 0/5000028.
2024-09-29 21:36:27.672 CST [14950] STATEMENT: BASE_BACKUP ( INCREMENTAL, LABEL 'pg_basebackup base backup', PROGRESS, WAIT 0, TABLESPACE_MAP, MANIFEST 'yes', TARGET 'client')
WARNING: aborting backup due to backend exiting before pg_backup_stop was called
pg_basebackup: error: could not initiate base backup: ERROR: WAL summaries are required on timeline 1 from 0/5000028 to 0/9000028, but the summaries for that timeline and LSN range are incomplete
DETAIL: The first unsummarized LSN in this range is 0/5000028.
pg_basebackup: removing contents of data directory "/postgres/backup/incremental"
[postgres@Node2 ~]$
说明:此处显示错误,说明和第一场全量备份未开启summarize_wal有关,再次做全量备份。
[postgres@Node2 ~]$ rm -rf /postgres/backup/manifest/*
[postgres@Node2 ~]$
[postgres@Node2 ~]$ rm -rf /postgres/backup/incremental/*
[postgres@Node2 ~]$
[postgres@Node2 ~]$ pg_basebackup -h localhost -p 5432 -U postgres -Xs -Ft -z -Pv -Z9 -D /postgres/backup/manifest
pg_basebackup: initiating base backup, waiting for checkpoint to complete
2024-09-29 21:38:30.165 CST [1971] LOG: checkpoint starting: force wait
2024-09-29 21:38:30.177 CST [1971] LOG: checkpoint complete: wrote 0 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.001 s, sync=0.001 s, total=0.012 s; sync files=0, longest=0.000 s, average=0.000 s; distance=32768 kB, estimate=32768 kB; lsn=0/8000080, redo lsn=0/8000028
pg_basebackup: checkpoint completed
pg_basebackup: write-ahead log start point: 0/8000028 on timeline 1
pg_basebackup: starting background WAL receiver
pg_basebackup: created temporary replication slot "pg_basebackup_2019"
31414/31414 kB (100%), 1/1 tablespace
pg_basebackup: write-ahead log end point: 0/8000158
pg_basebackup: waiting for background process to finish streaming ...
pg_basebackup: syncing data to disk ...
pg_basebackup: renaming backup_manifest.tmp to backup_manifest
pg_basebackup: base backup completed
[postgres@Node2 ~]$
[postgres@Node2 ~]$ pg_basebackup -h localhost -p 5432 -U postgres -i /postgres/backup/manifest/backup_manifest -Xs -Ft -z -Pv -Z9 -D /postgres/backup/incremental
pg_basebackup: initiating base backup, waiting for checkpoint to complete
2024-09-29 21:40:19.685 CST [1971] LOG: checkpoint starting: force wait
2024-09-29 21:40:19.850 CST [1971] LOG: checkpoint complete: wrote 0 buffers (0.0%); 0 WAL file(s) added, 0 removed, 2 recycled; write=0.001 s, sync=0.001 s, total=0.166 s; sync files=0, longest=0.000 s, average=0.000 s; distance=32768 kB, estimate=32768 kB; lsn=0/A000080, redo lsn=0/A000028
pg_basebackup: checkpoint completed
pg_basebackup: write-ahead log start point: 0/A000028 on timeline 1
pg_basebackup: starting background WAL receiver
pg_basebackup: created temporary replication slot "pg_basebackup_2045"
4111/31403 kB (100%), 1/1 tablespace
pg_basebackup: write-ahead log end point: 0/A000120
pg_basebackup: waiting for background process to finish streaming ...
pg_basebackup: syncing data to disk ...
pg_basebackup: renaming backup_manifest.tmp to backup_manifest
pg_basebackup: base backup completed
[postgres@Node2 ~]$
3.2、合并备份
1、解压全量备份文件
[postgres@Node2 ~]$ cd /postgres/backup/manifest/
[postgres@Node2 manifest]$ ls
backup_manifest base.tar.gz pg_wal.tar.gz
[postgres@Node2 manifest]$ tar xzvf base.tar.gz
backup_label
tablespace_map
pg_wal/
./pg_wal/archive_status/
./pg_wal/summaries/
global/
..................
pg_logical/snapshots/
pg_logical/mappings/
pg_logical/replorigin_checkpoint
PG_VERSION
postgresql.auto.conf
pg_hba.conf
pg_ident.conf
log/
postgresql.conf
global/pg_control
[postgres@Node2 manifest]$ tar xzvf pg_wal.tar.gz
00000001000000000000000A
archive_status/00000001000000000000000A.done
00000001000000000000000B
[postgres@Node2 manifest]$
2、解压增量备份文件
[postgres@Node2 manifest]$ cd ../incremental/
[postgres@Node2 incremental]$ ls
backup_manifest base.tar.gz pg_wal.tar.gz
[postgres@Node2 incremental]$ tar xzvf base.tar.gz
backup_label
tablespace_map
pg_wal/
./pg_wal/archive_status/
./pg_wal/summaries/
global/
........................
postgresql.auto.conf
pg_hba.conf
pg_ident.conf
log/
postgresql.conf
global/pg_control
[postgres@Node2 incremental]$ tar xzvf pg_wal.tar.gz
00000001000000000000000C
[postgres@Node2 incremental]$
3、合并备份文件
[postgres@Node2 incremental]$ pg_combinebackup /postgres/backup/manifest /postgres/backup/incremental -o /postgres/backup/restore
pg_combinebackup: warning: manifest file "/postgres/backup/incremental/backup_manifest" contains no entry for file "base.tar.gz"
pg_combinebackup: warning: manifest file "/postgres/backup/incremental/backup_manifest" contains no entry for file "pg_wal.tar.gz"
pg_combinebackup: warning: manifest file "/postgres/backup/incremental/backup_manifest" contains no entry for file "00000001000000000000000B"
pg_combinebackup: warning: manifest file "/postgres/backup/incremental/backup_manifest" contains no entry for file "archive_status/00000001000000000000000B.done"
pg_combinebackup: warning: manifest file "/postgres/backup/incremental/backup_manifest" contains no entry for file "00000001000000000000000C"
[postgres@Node2 incremental]$
[postgres@Node2 ~]$ pg_ctl stop
waiting for server to shut down....2024-09-29 21:39:09.439 CST [1970] LOG: received fast shutdown request
2024-09-29 21:39:09.440 CST [1970] LOG: aborting any active transactions
2024-09-29 21:39:09.443 CST [1970] LOG: background worker "logical replication launcher" (PID 1978) exited with exit code 1
2024-09-29 21:39:09.443 CST [1971] LOG: shutting down
2024-09-29 21:39:09.471 CST [1971] LOG: checkpoint starting: shutdown immediate
2024-09-29 21:39:09.474 CST [1971] LOG: checkpoint complete: wrote 0 buffers (0.0%); 0 WAL file(s) added, 0 removed, 1 recycled; write=0.001 s, sync=0.001 s, total=0.005 s; sync files=0, longest=0.000 s, average=0.000 s; distance=16383 kB, estimate=29655 kB; lsn=0/C000028, redo lsn=0/C000028
2024-09-29 21:39:09.567 CST [1970] LOG: database system is shut down
done
server stopped
[postgres@Node2 ~]$ rm -rf /postgres/data/*
[postgres@Node2 ~]$
[postgres@Node2 ~]$ cp -r /postgres/backup/databack/* /postgres/data/
[postgres@Node2 ~]$
[postgres@Node2 ~]$
[postgres@Node2 ~]$
[postgres@Node2 ~]$ pg_ctl start
waiting for server to start....2024-09-29 21:43:27.537 CST [2209] LOG: starting PostgreSQL 17.0 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
2024-09-29 21:43:27.537 CST [2209] LOG: listening on IPv4 address "0.0.0.0", port 5432
2024-09-29 21:43:27.537 CST [2209] LOG: listening on IPv6 address "::", port 5432
2024-09-29 21:43:27.539 CST [2209] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2024-09-29 21:43:27.549 CST [2212] LOG: database system was shut down at 2024-09-29 21:39:09 CST
2024-09-29 21:43:27.556 CST [2209] LOG: database system is ready to accept connections
done
server started
[postgres@Node2 ~]$
四、注意事项
4.1、问题记录:Navicat连接PostgreSql时出现 “ERROR: column “datlastsysoid” does not exist LINE 1: SELECT DISTINCT datlastsysoid FROM pg_database”
解决方案:升级Navicat工具至17版本。
4.2、使用pg_combinebackup合并备份文件时错误如下
[postgres@Node2 ~]$ pg_basebackup -h localhost -p 5432 -U postgres -i /postgres/backup/manifest/backup_manifest -Xs -Ft -z -Pv -Z9 -D /postgres/backup/incremental/
pg_basebackup: initiating base backup, waiting for checkpoint to complete
pg_basebackup: error: could not initiate base backup: ERROR: incremental backups cannot be taken unless WAL summarization is enabled
pg_basebackup: removing contents of data directory "/postgres/backup/incremental/"
[postgres@Node2 ~]$
[postgres@Node2 ~]$
[postgres@Node2 ~]$ ls /postgres/backup/incremental/
[postgres@Node2 ~]$ ll /postgres/backup/incremental/
total 0
[postgres@Node2 ~]$
解决方案:开启summarize_wal = on。
4.3、在执行合并备份文件时,需解压备份文件后,再使用pg_combinebackup合并。
五.总结
5.1、详细版本说明
官网地址:
https://www.postgresql.org/docs/17/release-17.html
5.2、版本详情
当前测试版本是 PostgreSQL 17.01。有关当前测试版本的信息以及如何进行测试,请查看下面的链接。
- PostgreSQL 17.01 发布公告
https://www.postgresql.org/about/news/postgresql-17-rc1-released-2926/- 下载 PostgreSQL 17.01 源代码
https://www.postgresql.org/ftp/source/v17rc1/- PostgreSQL 17 文档
https://www.postgresql.org/docs/17/- PostgreSQL 17 发布说明
https://www.postgresql.org/docs/17/release-17.html- PostgreSQL 17 未完成事项
https://wiki.postgresql.org/wiki/PostgreSQL_17_Open_Items- 《PostgreSQL 测试指南》
https://wiki.postgresql.org/wiki/HowToBetaTest





