我试图强制将 WAL 文件刷新到磁盘上,以便我可以将它们复制到其他地方。我相信CHECKPOINT
这是我感兴趣的命令,但它似乎不起作用。
我有一个运行 Postgres 的 docker 容器,我使用 adminer 将新记录添加到我创建的表中。我尝试手动刷新 WAL 文件:
$ docker exec db psql pgtest -U postgres -c "CHECKPOINT;"
CHECKPOINT
我相信应该刷新数据,并且我会看到创建了一个新的 WAL 文件,但是没有新文件 - 我只看到旧的 WAL 文件。当我重新启动容器时:
$ docker restart db
db
然后我看到一个新的 WAL 文件。
这是我的 postgresql.conf 的样子:
#------------------------------------------------------------------------------
# WRITE AHEAD LOG
#------------------------------------------------------------------------------
# - Settings -
wal_level = logical # minimal, replica, or logical
# (change requires restart)
fsync = on # flush data to disk for crash safety
# (turning this off can cause
# unrecoverable data corruption)
synchronous_commit = local # synchronization level;
# off, local, remote_write, remote_apply, or on
wal_sync_method = fsync # the default is the first option
# supported by the operating system:
# open_datasync
# fdatasync (default on Linux)
# fsync
# fsync_writethrough
# open_sync
#full_page_writes = on # recover from partial page writes
#wal_compression = off # enable compression of full-page writes
#wal_log_hints = off # also do full page writes of non-critical updates
# (change requires restart)
#wal_buffers = -1 # min 32kB, -1 sets based on shared_buffers
# (change requires restart)
#wal_writer_delay = 200ms # 1-10000 milliseconds
wal_writer_flush_after = 1MB # measured in pages, 0 disables
#commit_delay = 0 # range 0-100000, in microseconds
#commit_siblings = 5 # range 1-1000
# - Checkpoints -
#checkpoint_timeout = 1min # range 30s-1d
#max_wal_size = 1GB
#min_wal_size = 4MB
#checkpoint_completion_target = 0.5 # checkpoint target duration, 0.0 - 1.0
#checkpoint_flush_after = 256kB # measured in pages, 0 disables
#checkpoint_warning = 30s # 0 disables
# - Archiving -
archive_mode = on # enables archiving; off, on, or always
# (change requires restart)
archive_command = 'test ! -f /var/lib/postgresql/data/wal/%f && cp %p /var/lib/postgresql/data/wal/%f'
# placeholders: %p = path of file to archive
# %f = file name only
# e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f'
#archive_timeout = 0 # force a logfile segment switch after this
# number of seconds; 0 disables
对于 postgreSQL 9.6 及以下版本,您可以使用
pg_switch_xlog()
pg_switch_xlog()强制切换到新的事务日志文件。
对于 postgreSQL 10 及更高版本,请使用
pg_switch_wal()