未开启归档时的参数
postgres=# select name,setting from pg_settings where name like 'archive%' or name = 'wal_level'; name | setting -------------------------+------------ archive_cleanup_command | archive_command | (disabled) archive_mode | off archive_timeout | 0 wal_level | replica (5 rows)
WAL日志被存放在数据目录的pg_wal目录里
修改参数
修改postgresql.conf
archive_mode = on archive_command = 'cp %p /var/lib/postgresql/12/main/pg_archive/pg_%f'
修改完成后
postgres=# select name,setting from pg_settings where name like 'archive%' or name = 'wal_level'; name | setting -------------------------+---------------------------------------------------- archive_cleanup_command | archive_command | cp %p /var/lib/postgresql/12/main/pg_archive/pg_%f archive_mode | on archive_timeout | 0 wal_level | replica (5 rows) root@scutech:/var/lib/postgresql/12/main# ll pg_archive/ total 32780 drwxr-xr-x 2 postgres postgres 4096 Jul 13 08:09 ./ drwx------ 21 postgres postgres 4096 Jul 13 08:09 ../ -rw------- 1 postgres postgres 16777216 Jul 13 08:09 pg_000000010000000000000004 -rw------- 1 postgres postgres 16777216 Jul 13 08:09 pg_000000010000000000000005 -rw------- 1 postgres postgres 334 Jul 13 08:09 pg_000000010000000000000005.00000028.backup root@scutech:/var/lib/postgresql/12/main#