一测试环境,在启动后,在日志中发现归档进程频繁启动失败:
$ more postgresql-Sun.csv 2021-05-09 11:16:42.586 CST,,,3619,,6097541a.e23,1,,2021-05-09 11:16:42 CST,,0,LOG,00000,"ending log output to stderr",,"Future log output will go to log destination " "csvlog"".",,,,,,,"" 2021-05-09 11:16:42.606 CST,,,3621,,6097541a.e25,1,,2021-05-09 11:16:42 CST,,0,LOG,00000,"database system was shut down at 2021-05-09 11:12:24 CST",,,,,,,,,"" 2021-05-09 11:16:42.656 CST,,,3619,,6097541a.e23,2,,2021-05-09 11:16:42 CST,,0,LOG,00000,"database system is ready to accept connections",,,,,,,,,"" 2021-05-09 11:16:42.667 CST,,,3626,,6097541a.e2a,1,,2021-05-09 11:16:42 CST,,0,LOG,00000,"archive command failed with exit code 1","The failed archive command was: /us r/bin/cp pg_wal/000000010000004B00000052 /pg/11/wal_archive/000000010000004B00000052",,,,,,,,"" 2021-05-09 11:16:43.674 CST,,,3626,,6097541a.e2a,2,,2021-05-09 11:16:42 CST,,0,LOG,00000,"archive command failed with exit code 1","The failed archive command was: /us r/bin/cp pg_wal/000000010000004B00000052 /pg/11/wal_archive/000000010000004B00000052",,,,,,,,"" 2021-05-09 11:16:44.681 CST,,,3626,,6097541a.e2a,3,,2021-05-09 11:16:42 CST,,0,LOG,00000,"archive command failed with exit code 1","The failed archive command was: /us r/bin/cp pg_wal/000000010000004B00000052 /pg/11/wal_archive/000000010000004B00000052",,,,,,,,"" 2021-05-09 11:16:44.849 CST,,,3619,,6097541a.e23,3,,2021-05-09 11:16:42 CST,,0,LOG,00000,"archiver process (PID 3626) was terminated by signal 11: Segmentation fault", ,,,,,,,,"" 2021-05-09 11:16:52.695 CST,,,3656,,60975424.e48,1,,2021-05-09 11:16:52 CST,,0,LOG,00000,"archive command failed with exit code 1","The failed archive command was: /us r/bin/cp pg_wal/000000010000004B00000052 /pg/11/wal_archive/000000010000004B00000052",,,,,,,,"" 2021-05-09 11:16:53.703 CST,,,3656,,60975424.e48,2,,2021-05-09 11:16:52 CST,,0,LOG,00000,"archive command failed with exit code 1","The failed archive command was: /us r/bin/cp pg_wal/000000010000004B00000052 /pg/11/wal_archive/000000010000004B00000052",,,,,,,,"" 2021-05-09 11:16:54.711 CST,,,3656,,60975424.e48,3,,2021-05-09 11:16:52 CST,,0,LOG,00000,"archive command failed with exit code 1","The failed archive command was: /us r/bin/cp pg_wal/000000010000004B00000052 /pg/11/wal_archive/000000010000004B00000052",,,,,,,,"" 2021-05-09 11:16:54.735 CST,,,3619,,6097541a.e23,4,,2021-05-09 11:16:42 CST,,0,LOG,00000,"archiver process (PID 3656) was terminated by signal 11: Segmentation fault", ,,,,,,,,"" 2021-05-09 11:17:02.695 CST,,,3663,,6097542e.e4f,1,,2021-05-09 11:17:02 CST,,0,LOG,00000,"archive command failed with exit code 1","The failed archive command was: /us r/bin/cp pg_wal/000000010000004B00000052 /pg/11/wal_archive/000000010000004B00000052",,,,,,,,"" 2021-05-09 11:17:03.702 CST,,,3663,,6097542e.e4f,2,,2021-05-09 11:17:02 CST,,0,LOG,00000,"archive command failed with exit code 1","The failed archive command was: /us r/bin/cp pg_wal/000000010000004B00000052 /pg/11/wal_archive/000000010000004B00000052",,,,,,,,"" 2021-05-09 11:17:04.708 CST,,,3663,,6097542e.e4f,3,,2021-05-09 11:17:02 CST,,0,LOG,00000,"archive command failed with exit code 1","The failed archive command was: /us r/bin/cp pg_wal/000000010000004B00000052 /pg/11/wal_archive/000000010000004B00000052",,,,,,,,"" 2021-05-09 11:17:04.849 CST,,,3619,,6097541a.e23,5,,2021-05-09 11:16:42 CST,,0,LOG,00000,"archiver process (PID 3663) was terminated by signal 11: Segmentation fault", ,,,,,,,,"" 2021-05-09 11:17:12.701 CST,,,3687,,60975438.e67,1,,2021-05-09 11:17:12 CST,,0,LOG,00000,"archive command failed with exit code 1","The failed archive command was: /us r/bin/cp pg_wal/000000010000004B00000052 /pg/11/wal_archive/000000010000004B00000052",,,,,,,,"" 2021-05-09 11:17:13.707 CST,,,3687,,60975438.e67,2,,2021-05-09 11:17:12 CST,,0,LOG,00000,"archive command failed with exit code 1","The failed archive command was: /us r/bin/cp pg_wal/000000010000004B00000052 /pg/11/wal_archive/000000010000004B00000052",,,,,,,,"" 2021-05-09 11:17:14.714 CST,,,3687,,60975438.e67,3,,2021-05-09 11:17:12 CST,,0,LOG,00000,"archive command failed with exit code 1","The failed archive command was: /us r/bin/cp pg_wal/000000010000004B00000052 /pg/11/wal_archive/000000010000004B00000052",,,,,,,,"" 2021-05-09 11:17:14.739 CST,,,3619,,6097541a.e23,6,,2021-05-09 11:16:42 CST,,0,LOG,00000,"archiver process (PID 3687) was terminated by signal 11: Segmentation fault", ,,,,,,,,"" 2021-05-09 11:17:22.702 CST,,,3693,,60975442.e6d,1,,2021-05-09 11:17:22 CST,,0,LOG,00000,"archive command failed with exit code 1","The failed archive command was: /us r/bin/cp pg_wal/000000010000004B00000052 /pg/11/wal_archive/000000010000004B00000052",,,,,,,,""
查看pg_wal目录中的日志
$ ll ../pg_wal/ total 65900 -rw-------. 1 postgres postgres 343 May 8 18:03 0000000100000155000000ED.00000028.backup -rw-------. 1 postgres postgres 343 May 9 10:02 0000000100000155000000F0.00000028.backup -rw-------. 1 postgres postgres 343 May 9 10:33 0000000100000155000000F4.00000028.backup -rw-------. 1 postgres postgres 16777216 May 9 11:06 000000010000015600000001 -rw-------. 1 postgres postgres 16777216 May 9 11:16 000000010000015600000002 -rw-------. 1 postgres postgres 16777216 May 9 10:52 000000010000015600000003 -rw-------. 1 postgres postgres 16777216 Apr 14 13:56 000000010000015600000015 drwx------. 2 postgres postgres 352256 May 9 11:06 archive_status -rw-------. 1 postgres postgres 1300 Feb 25 08:35 logfile
可以看到,这里没有日志文件000000010000004B00000052
查看归档设置
postgres=# select name,setting from pg_settings where name like 'archive%' or name = 'wal_level'; name | setting -----------------+----------------------------------------------- archive_command | /usr/bin/cp %p /pg/11/wal_archive/%f archive_mode | on archive_timeout | 600 wal_level | logical (4 rows) postgres=#
因为是测试环境而已,直接尝试先关闭归档,然后再次开启归档
1.修改postgresql.conf中archive_mode =off,然后重启pg
2.然后再修改为archive_mode=on,再重启pg
启动后,还是报相同的错误!
然后尝试在开启归档的同时,将归档命令设置成空命令,重启pg:
修改postgresql.conf
archive_mode=on archive_command = ''
启动后,还是报错!
尝试修改成其他的命令,比如:
archive_mode=on archive_command = 'ls -l /pg/11/wal_archive/'
发现重启后,不再报错!
最终,再将归档命令还原成最初的命令:
archive_mode=on archive_command = '/usr/bin/cp %p /pg/11/wal_archive/%f'
重启后,系统恢复正常!