PG 16.1归档archive_command按天划分目录保存
本次问题首先源于数据库版本的升级,记录一下。原数据库版本为14.9.经过升级16.1后,出现archive_command归档参数设置报错:(经测试15.5版本无此问题)
2024-01-09 23:33:35.759 CST,,,25341,,659d674f.62fd,1,,2024-01-09 23:33:35 CST,,0,FATAL,22023,"invalid value for parameter ""archive_command"": ""DIR=/opt/pgdata/pg_archive/`date +%F`; test ! -d $DIR && mkdir -p $DIR; test ! -f $DIR/%f && cp %p $DIR/%f""","String contains unexpected placeholder ""%F"".",,,,,,,,"","archiver",,0
参数设置为:
archive_command = 'DIR=/opt/pgdata/archive/`date +%F`; test ! -d $DIR && mkdir -p $DIR; test ! -f $DIR/%f && cp %p $DIR/%f'
报错提示很明显,在archive_command中的配置%F占位符失效了。这可能是16.1的一个bug,由于不知道怎么提交bug,所以只能选择绕开这个报错。
从而我们选择使用.sh脚本的方式,来继续实现归档按天划分目录保存。
编写.sh脚本:
[postgres@pgnode1 pgdata]$ more /opt/pgdata/archive/archive.sh
#!/bin/bash
WALFilePath=$1
WALFileName=$2
DIR=/opt/pgdata/archive/`date +%F`
test ! -d $DIR && mkdir -p $DIR
test ! -f $DIR/%f && cp "$WALFilePath" $DIR/"$WALFileName"
cp "$WALFilePath" $DIR/"$WALFileName"
[postgres@pgnode1 pgdata]$
archive_command参数设置如下:
archive_command = '/opt/pgdata/archive/archive.sh %p %f'
参数设置完成,但是日志报错
2024-01-09 23:56:39.167 CST,,,25657,,659d6cb7.6439,1,,2024-01-09 23:56:39 CST,,0,FATAL,XX000,"archive command failed with exit code 126","The failed archive command was: /opt/pgdata/archive/archive.sh pg_wal/000000010000000000000016 000000010000000000000016",,,,,,,,"","archiver",,0
使用sh脚本报错archive command failed with exit code 126
报错原因是以为脚本权限不足,无执行权限。
[postgres@pgnode1 pgdata]$ cd archive/
[postgres@pgnode1 archive]$ ll
total 4
drwxrwxr-x. 2 postgres postgres 6 Jan 9 22:44 2024-01-09
-rw-rw-r--. 1 postgres postgres 298 Jan 9 23:45 archive.sh
[postgres@pgnode1 archive]$ chmod +x archive.sh
[postgres@pgnode1 archive]$ pg_ctl restart
waiting for server to shut down..... done
server stopped
waiting for server to start....2024-01-10 00:05:41.332 CST [25845] LOG: redirecting log output to logging collector process
2024-01-10 00:05:41.332 CST [25845] HINT: Future log output will appear in directory "pg_log".
done
server started
[postgres@pgnode1 2024-01-09]$
添加执行权限后,日志无报错,查看归档已成功生成,参数生效。
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




