postgresql アーカイブのリカバリとクリーンアップに関するドキュメントをいくつか読みましたが、私の postgresql サーバーはまだアーカイブをパージしていないか、その仕組みをよく理解していませんでした。
簡単に言うと、WAL アーカイブをクリーンアップするためのシェル スクリプトを作成しました。コマンド ラインからスクリプトを実行すると、スクリプトが機能し、アーカイブが消去されます (3 日より新しいアーカイブのみを残します)。私のスクリプトはpg_archive_cleanupという名前で、実行可能で、ここに配置されます: /usr/sbin/
そして、/etc/postgresql/9.3/main/recovery.confを次のように構成します。
# -------------------------------
# PostgreSQL recovery config file
# -------------------------------
#
# Edit this file to provide the parameters that PostgreSQL needs to
# perform an archive recovery of a database, or to act as a replication
# standby.
#
# If "recovery.conf" is present in the PostgreSQL data directory, it is
# read on postmaster startup. After successful recovery, it is renamed
# to "recovery.done" to ensure that we do not accidentally re-enter
# archive recovery or standby mode.
#
# This file consists of lines of the form:
#
# name = value
#
# Comments are introduced with '#'.
#
# The complete list of option names and allowed values can be found
# in the PostgreSQL documentation.
#
#---------------------------------------------------------------------------
# ARCHIVE RECOVERY PARAMETERS
#---------------------------------------------------------------------------
# archive_cleanup_command
#
# specifies an optional shell command to execute at every restartpoint.
# This can be useful for cleaning up the archive of a standby server.
#
archive_cleanup_command = '/usr/sbin/pg_archive_cleanup'
#
#---------------------------------------------------------------------------
# RECOVERY TARGET PARAMETERS
#---------------------------------------------------------------------------
#
# By default, recovery will rollforward to the end of the WAL log.
# If you want to stop rollforward at a specific point, you
# must set a recovery target.
#
# You may set a recovery target either by transactionId, by name,
# or by timestamp. Recovery may either include or exclude the
# transaction(s) with the recovery target value (ie, stop either
# just after or just before the given target, respectively).
#
#
#recovery_target_name = '' # e.g. 'daily backup 2011-01-26'
#
#recovery_target_time = '' # e.g. '2004-07-14 22:39:00 EST'
#
#recovery_target_xid = ''
#
#recovery_target_inclusive = true
#
#
# If you want to recover into a timeline other than the "main line" shown in
# pg_control, specify the timeline number here, or write 'latest' to get
# the latest branch for which there's a history file.
#
#recovery_target_timeline = 'latest'
#
#
# If pause_at_recovery_target is enabled, recovery will pause when
# the recovery target is reached. The pause state will continue until
# pg_xlog_replay_resume() is called. This setting has no effect if
# hot standby is not enabled, or if no recovery target is set.
#
#pause_at_recovery_target = true
#
#---------------------------------------------------------------------------
# STANDBY SERVER PARAMETERS
#---------------------------------------------------------------------------
#
# standby_mode
#
# When standby_mode is enabled, the PostgreSQL server will work as a
# standby. It will continuously wait for the additional XLOG records, using
# restore_command and/or primary_conninfo.
#
standby_mode = on
restore_command = 'cp /var/lib/postgresql/database/archive/%f "%p"'
#
# primary_conninfo
#
# If set, the PostgreSQL server will try to connect to the primary using this
# connection string and receive XLOG records continuously.
#
primary_conninfo = 'host=db-master port=5432 user=repli password=Esibfegiav4' # e.g. 'host=localhost port=5432'
#
#
# By default, a standby server keeps restoring XLOG records from the
# primary indefinitely. If you want to stop the standby mode, finish recovery
# and open the system in read/write mode, specify path to a trigger file.
# The server will poll the trigger file path periodically and start as a
# primary server when it's found.
#
trigger_file = '/var/lib/postgresql/database/failover_trigger'
#
#---------------------------------------------------------------------------
# HOT STANDBY PARAMETERS
#---------------------------------------------------------------------------
#
# Hot Standby related parameters are listed in postgresql.conf
#
#---------------------------------------------------------------------------
ラインが見えます
archive_cleanup_command = '/usr/sbin/pg_archive_cleanup'
私のクリーンアップスクリプト:
#!/bin/bash
ARCHIVEDIR='/var/lib/postgresql/database/archive'
CHECKPOINT=$(find $ARCHIVEDIR -type f -mtime +3 -type f -printf '%f\n' | sort -r | head -1)
cd $ARCHIVEDIR
/usr/bin/pg_archivecleanup $ARCHIVEDIR $CHECKPOINT
find $ARCHIVEDIR -type f -mtime +3 -a -type f -a ! -newer $CHECKPOINT -delete
しかし、4 日後にはディスク容量が増えました。ドキュメントで、recovery.confファイルがcheck_point とrestart_pointで読み取られることを確認しました... アーカイブが自動的に削除されない理由を知りたいですか? オカレンスはどこで設定しますか? postgresl はいつパージを開始することになっていますか? これを毎日実行したいのですが、代わりにクリーンアップ スクリプトを crontab に配置する必要がありますか? それとも別の場所ですか?また、postgresql ログ ファイルにもトレースがありません。クリーンアップ ログはどこに書き込まれますか?
返信ありがとうございます。