{"Entry":{"collection":"tool","key":"pg-archivecleanup","name":"pg_archivecleanup","aliases":["pg_archivecleanup"],"metadata":{"aliases":["pg_archivecleanup"],"category":"Server applications","content_hash":"fd7e17ef53e64339c1e0732987939789b3737b7d1d2b704006363f6d77c43f3b","derived_content_hash":"d2fee4e538ed959f668987e63608ecce9ef49edcd8a4f9cbcd7b548dc0ee0a75","imported_at":"2026-09-30T00:40:34.02289+08:00","name":"pg_archivecleanup","name_zh":"","slug":"pg-archivecleanup","summary":"pg_archivecleanup — clean up PostgreSQL WAL archive files"}},"Definition":{"Collection":"tool","Key":"pg-archivecleanup","SourceDatabase":"center","Version":"18","SourceTable":"command_tool","SourceKey":"pg-archivecleanup","SourceRevision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","Facts":{"comparison_data":{"environment":[],"options":[{"description":"Remove backup history files as well. See Section 25.3.2 for details about backup history files.","names":["-b","--clean-backup-history"],"signature":"-b --clean-backup-history"},{"description":"Print lots of debug logging output on stderr .","names":["-d","--debug"],"signature":"-d --debug"},{"description":"Print the names of the files that would have been removed on stdout (performs a dry run).","names":["-n","--dry-run"],"signature":"-n --dry-run"},{"description":"Print the pg_archivecleanup version and exit.","names":["-V","--version"],"signature":"-V --version"},{"description":"Provide an extension that will be stripped from all file names before deciding if they should be deleted. This is typically useful for cleaning up archives that have been compressed during storage, and therefore have had an extension added by the compression program. For example: -x .gz .","names":["-x extension","--strip-extension= extension"],"signature":"-x extension --strip-extension= extension"},{"description":"Show help about pg_archivecleanup command line arguments, and exit.","names":["-?","--help"],"signature":"-? --help"}],"synopsis":["pg_archivecleanup [ option ...] archivelocation oldestkeptwalfile"]},"comparison_hash":"18d66c08cf423bd426b6c3ea916de5ab0a2b1ae3ecbe75bc0b1efbbf13ec32db","description":["pg_archivecleanup — clean up PostgreSQL WAL archive files"],"description_zh":"描述 pg_archivecleanup 设计为在服务器作为备库运行时用作 archive_cleanup_command ，以清理 WAL 文件归档（见 第 26.2 节 ）。 pg_archivecleanup 也可作为独立程序使用，以清理 WAL 文件归档。 要将备库配置为使用 pg_archivecleanup ，请将以下内容写入其 postgresql.conf 配置文件： archive_cleanup_command = 'pg_archivecleanup archivelocation %r' 其中 archivelocation 是应移除 WAL 段文件的目录。 当在 archive_cleanup_command 中使用时，逻辑上早于 %r 参数值的所有 WAL 文件都会从 archivelocation 中移除。这样既能将需要保留的文件数量降到最低，又能保留崩溃后重启能力。如果 archivelocation 只是该特定备库的临时暂存区，那么使用此参数是合适的；但如果 archivelocation 打算作为长期 WAL 归档区域，或者有多个备库正从同一归档位置恢复，则 不 适合使用此参数。 作为独立程序使用时，逻辑上早于 oldestkeptwalfile 的所有 WAL 文件都会从 archivelocation 中移除。在此模式下，如果指定的是 .partial 或 .backup 文件名，则仅使用其文件名前缀作为 oldestkeptwalfile 。这样处理 .backup 文件名后，就可以无误地删除某个特定基础备份之前归档的所有 WAL 文件。例如，下例会移除所有早于 WAL 文件名 000000010000003700000010 的文件： pg_archivecleanup -d archive 000000010000003700000010.00000020.backup pg_archivecleanup: keep WAL file \"archive/000000010000003700000010\" and later ","description_zh_html":"\u003cp\u003e命令行工具 pg_archivecleanup [ option ...] archivelocation oldestkeptwalfile。\u003c/p\u003e\u003ch3\u003e同版本中文手册节选\u003c/h3\u003e\u003cdiv class=\"refsect1\"\u003e\u003ch2\u003e描述\u003c/h2\u003e\u003cp\u003e\n\u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e 设计为在服务器作为备库运行时用作\n  \u003ccode class=\"literal\"\u003earchive_cleanup_command\u003c/code\u003e，以清理 WAL 文件归档（见\u003ca class=\"xref\" href=\"/zh/docs/18/warm-standby.html\"\u003e第 26.2 节\u003c/a\u003e）。\u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e 也可作为独立程序使用，以清理 WAL\n  文件归档。\n \u003c/p\u003e\u003cp\u003e\n   要将备库配置为使用 \u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e，请将以下内容写入其\n   \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e 配置文件：\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003earchive_cleanup_command = 'pg_archivecleanup \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e %r'\n\u003c/pre\u003e\u003cp\u003e\n   其中 \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e 是应移除 WAL 段文件的目录。\n  \u003c/p\u003e\u003cp\u003e\n   当在 \u003ca class=\"xref\" href=\"/zh/docs/18/runtime-config-wal.html#GUC-ARCHIVE-CLEANUP-COMMAND\"\u003earchive_cleanup_command\u003c/a\u003e 中使用时，逻辑上早于\n   \u003ccode class=\"literal\"\u003e%r\u003c/code\u003e 参数值的所有 WAL 文件都会从 \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e\n   中移除。这样既能将需要保留的文件数量降到最低，又能保留崩溃后重启能力。如果\n   \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e 只是该特定备库的临时暂存区，那么使用此参数是合适的；但如果 \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e 打算作为长期 WAL 归档区域，或者有多个备库正从同一归档位置恢复，则\u003cspan class=\"emphasis\"\u003e\u003cem\u003e不\u003c/em\u003e\u003c/span\u003e适合使用此参数。\n  \u003c/p\u003e\u003cp\u003e\n   作为独立程序使用时，逻辑上早于 \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoldestkeptwalfile\u003c/code\u003e\u003c/em\u003e 的所有 WAL\n   文件都会从 \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e 中移除。在此模式下，如果指定的是\n   \u003ccode class=\"filename\"\u003e.partial\u003c/code\u003e 或 \u003ccode class=\"filename\"\u003e.backup\u003c/code\u003e 文件名，则仅使用其文件名前缀作为 \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoldestkeptwalfile\u003c/code\u003e\u003c/em\u003e。这样处理 \u003ccode class=\"filename\"\u003e.backup\u003c/code\u003e\n   文件名后，就可以无误地删除某个特定基础备份之前归档的所有 WAL 文件。例如，下例会移除所有早于 WAL 文件名 \u003ccode class=\"filename\"\u003e000000010000003700000010\u003c/code\u003e 的文件：\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003epg_archivecleanup -d archive 000000010000003700000010.00000020.backup\n\npg_archivecleanup:  keep WAL file \"archive/000000010000003700000010\" and later\npg_archivecleanup:  removing file \"archive/00000001000000370000000F\"\npg_archivecleanup:  removing file \"archive/00000001000000370000000E\"\n\u003c/pre\u003e\u003cp\u003e\n\u003c/p\u003e\u003cp\u003e\n\u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e 假定 \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e\n   是服务器属主用户可读写的目录。\n  \u003c/p\u003e\u003c/div\u003e\u003cdiv class=\"refsect1\"\u003e\u003ch2\u003e选项\u003c/h2\u003e\u003cp\u003e\n\u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e 接受下列命令行参数：\n\n    \u003c/p\u003e\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-b\u003c/code\u003e\u003cbr/\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--clean-backup-history\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n         同时移除备份历史文件。关于备份历史文件的详细信息，见\u003ca class=\"xref\" href=\"/zh/docs/18/continuous-archiving.html#BACKUP-BASE-BACKUP\"\u003e第 25.3.2 节\u003c/a\u003e。\n       \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-d\u003c/code\u003e\u003cbr/\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--debug\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n        在 \u003ccode class=\"filename\"\u003estderr\u003c/code\u003e 上输出大量调试日志。\n       \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-n\u003c/code\u003e\u003cbr/\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--dry-run\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n        在 \u003ccode class=\"filename\"\u003estdout\u003c/code\u003e 上打印原本会被移除的文件名（执行试运行）。\n       \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-V\u003c/code\u003e\u003cbr/\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--version\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n        输出 \u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e 的版本号并退出。\n       \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-x \u003cem class=\"replaceable\"\u003e\u003ccode\u003eextension\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr/\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--strip-extension=\u003cem class=\"replaceable\"\u003e\u003ccode\u003eextension\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n        指定一个扩展名；在判断文件是否应删除之前，会先从所有文件名中去掉该扩展名。这通常适用于清理由于存储时经过压缩、因而被压缩程序附加了扩展名的归档。例如：\u003ccode class=\"literal\"\u003e-x .gz\u003c/code\u003e。\n       \u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-?\u003c/code\u003e\u003cbr/\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--help\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n        显示有关 \u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e 命令行参数的帮助并退出。\n       \u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003cp\u003e\n\u003c/p\u003e\u003c/div\u003e\u003cp\u003e\u003ca href=\"/zh/docs/18/pgarchivecleanup.html\"\u003e查看完整中文手册与上下文\u003c/a\u003e。\u003c/p\u003e","environment":[],"facts":[{"label":"Documented executable","value":"pg_archivecleanup"},{"label":"Executable version","value":"18.6"},{"label":"Reference inventory","value":"Server applications"},{"label":"Option definition groups","value":"6"}],"facts_zh":[{"label":"手册中的可执行程序","value":"pg_archivecleanup"},{"label":"程序版本","value":"18.6"},{"label":"参考清单","value":"服务端程序"},{"label":"选项定义组","value":"6"}],"manual_html":"\u003cdiv\u003e\u003cdiv class=\"refentry\" id=\"PGARCHIVECLEANUP\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\u003c/div\u003e\n\u003cdiv class=\"refnamediv\"\u003e\n\u003ch2\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e\u003c/span\u003e\u003c/h2\u003e\n\u003cp\u003epg_archivecleanup — clean up \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e WAL archive files\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsynopsisdiv\"\u003e\n\u003ch2\u003eSynopsis\u003c/h2\u003e\n\u003cdiv class=\"cmdsynopsis\"\u003e\n\u003cp id=\"id-1.9.5.4.4.1\"\u003e\u003ccode class=\"command\"\u003epg_archivecleanup\u003c/code\u003e [\u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e...] \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoldestkeptwalfile\u003c/code\u003e\u003c/em\u003e\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.4.5\"\u003e\n\u003ch2\u003eDescription\u003c/h2\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e is designed to be used as an \u003ccode class=\"literal\"\u003earchive_cleanup_command\u003c/code\u003e to clean up WAL file archives when running as a standby server (see \u003ca class=\"xref\" href=\"/docs/18/warm-standby.html\" title=\"26.2. Log-Shipping Standby Servers\"\u003eSection 26.2\u003c/a\u003e). \u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e can also be used as a standalone program to clean WAL file archives.\u003c/p\u003e\n\u003cp\u003eTo configure a standby server to use \u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e, put this into its \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e configuration file:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003earchive_cleanup_command = 'pg_archivecleanup \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e %r'\n\u003c/pre\u003e\n\u003cp\u003ewhere \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e is the directory from which WAL segment files should be removed.\u003c/p\u003e\n\u003cp\u003eWhen used within \u003ca class=\"xref\" href=\"/docs/18/runtime-config-wal.html#GUC-ARCHIVE-CLEANUP-COMMAND\"\u003earchive_cleanup_command\u003c/a\u003e, all WAL files logically preceding the value of the \u003ccode class=\"literal\"\u003e%r\u003c/code\u003e argument will be removed from \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e. This minimizes the number of files that need to be retained, while preserving crash-restart capability. Use of this parameter is appropriate if the \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e is a transient staging area for this particular standby server, but \u003cspan class=\"emphasis\"\u003e\u003cem\u003enot\u003c/em\u003e\u003c/span\u003e when the \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e is intended as a long-term WAL archive area, or when multiple standby servers are recovering from the same archive location.\u003c/p\u003e\n\u003cp\u003eWhen used as a standalone program all WAL files logically preceding the \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoldestkeptwalfile\u003c/code\u003e\u003c/em\u003e will be removed from \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e. In this mode, if you specify a \u003ccode class=\"filename\"\u003e.partial\u003c/code\u003e or \u003ccode class=\"filename\"\u003e.backup\u003c/code\u003e file name, then only the file prefix will be used as the \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoldestkeptwalfile\u003c/code\u003e\u003c/em\u003e. This treatment of \u003ccode class=\"filename\"\u003e.backup\u003c/code\u003e file name allows you to remove all WAL files archived prior to a specific base backup without error. For example, the following example will remove all files older than WAL file name \u003ccode class=\"filename\"\u003e000000010000003700000010\u003c/code\u003e:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003epg_archivecleanup -d archive 000000010000003700000010.00000020.backup\n\npg_archivecleanup:  keep WAL file \"archive/000000010000003700000010\" and later\npg_archivecleanup:  removing file \"archive/00000001000000370000000F\"\npg_archivecleanup:  removing file \"archive/00000001000000370000000E\"\n\u003c/pre\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e assumes that \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e is a directory readable and writable by the server-owning user.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.4.6\"\u003e\n\u003ch2\u003eOptions\u003c/h2\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e accepts the following command-line arguments:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-b\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--clean-backup-history\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eRemove backup history files as well. See \u003ca class=\"xref\" href=\"/docs/18/continuous-archiving.html#BACKUP-BASE-BACKUP\" title=\"25.3.2. Making a Base Backup\"\u003eSection 25.3.2\u003c/a\u003e for details about backup history files.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-d\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--debug\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ePrint lots of debug logging output on \u003ccode class=\"filename\"\u003estderr\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-n\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--dry-run\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ePrint the names of the files that would have been removed on \u003ccode class=\"filename\"\u003estdout\u003c/code\u003e (performs a dry run).\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-V\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--version\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ePrint the \u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e version and exit.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-x \u003cem class=\"replaceable\"\u003e\u003ccode\u003eextension\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--strip-extension=\u003cem class=\"replaceable\"\u003e\u003ccode\u003eextension\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eProvide an extension that will be stripped from all file names before deciding if they should be deleted. This is typically useful for cleaning up archives that have been compressed during storage, and therefore have had an extension added by the compression program. For example: \u003ccode class=\"literal\"\u003e-x .gz\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-?\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--help\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eShow help about \u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e command line arguments, and exit.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.4.7\"\u003e\n\u003ch2\u003eEnvironment\u003c/h2\u003e\n\u003cp\u003eThe environment variable \u003ccode class=\"envar\"\u003ePG_COLOR\u003c/code\u003e specifies whether to use color in diagnostic messages. Possible values are \u003ccode class=\"literal\"\u003ealways\u003c/code\u003e, \u003ccode class=\"literal\"\u003eauto\u003c/code\u003e and \u003ccode class=\"literal\"\u003enever\u003c/code\u003e.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.4.8\"\u003e\n\u003ch2\u003eNotes\u003c/h2\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e is designed to work with \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 8.0 and later when used as a standalone utility, or with \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 9.0 and later when used as an archive cleanup command.\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e is written in C and has an easy-to-modify source code, with specifically designated sections to modify for your own needs\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.4.9\"\u003e\n\u003ch2\u003eExamples\u003c/h2\u003e\n\u003cp\u003eOn Linux or Unix systems, you might use:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003earchive_cleanup_command = 'pg_archivecleanup -d /mnt/standby/archive %r 2\u0026gt;\u0026gt;cleanup.log'\n\u003c/pre\u003e\n\u003cp\u003ewhere the archive directory is physically located on the standby server, so that the \u003ccode class=\"varname\"\u003earchive_command\u003c/code\u003e is accessing it across NFS, but the files are local to the standby. This will:\u003c/p\u003e\n\u003cdiv class=\"itemizedlist\"\u003e\n\u003cul class=\"itemizedlist\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eproduce debugging output in \u003ccode class=\"filename\"\u003ecleanup.log\u003c/code\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eremove no-longer-needed files from the archive directory\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003c/div\u003e","manual_path":"pgarchivecleanup.html","options":[{"description":"Remove backup history files as well. See Section 25.3.2 for details about backup history files.","names":["-b","--clean-backup-history"],"signature":"-b --clean-backup-history","source_url":"/docs/18/pgarchivecleanup.html","summary":"Remove backup history files as well. See Section 25.3.2 for details about backup history files."},{"description":"Print lots of debug logging output on stderr .","names":["-d","--debug"],"signature":"-d --debug","source_url":"/docs/18/pgarchivecleanup.html","summary":"Print lots of debug logging output on stderr ."},{"description":"Print the names of the files that would have been removed on stdout (performs a dry run).","names":["-n","--dry-run"],"signature":"-n --dry-run","source_url":"/docs/18/pgarchivecleanup.html","summary":"Print the names of the files that would have been removed on stdout (performs a dry run)."},{"description":"Print the pg_archivecleanup version and exit.","names":["-V","--version"],"signature":"-V --version","source_url":"/docs/18/pgarchivecleanup.html","summary":"Print the pg_archivecleanup version and exit."},{"description":"Provide an extension that will be stripped from all file names before deciding if they should be deleted. This is typically useful for cleaning up archives that have been compressed during storage, and therefore have had an extension added by the compression program. For example: -x .gz .","names":["-x extension","--strip-extension= extension"],"signature":"-x extension --strip-extension= extension","source_url":"/docs/18/pgarchivecleanup.html","summary":"Provide an extension that will be stripped from all file names before deciding if they should be deleted. This is typically useful for cleaning up archives that have been compressed during storage, and therefore have had an extension added by the compression program. For example: -x .gz ."},{"description":"Show help about pg_archivecleanup command line arguments, and exit.","names":["-?","--help"],"signature":"-? --help","source_url":"/docs/18/pgarchivecleanup.html","summary":"Show help about pg_archivecleanup command line arguments, and exit."}],"related":[],"release":{"channel":"stable","evidence_kind":"English manual and source declarations","label":"18.6","major":"18","manifest":{"index":"index.html","major":"18","pages":1148,"pdf":{"A4":{"built_at":"2026-09-26","bytes":15865106,"pages":3154,"sha256":"19512c405da53f9f7fcf0abba359223aa65f021be025bf3411381918f92e3190","url":"/files/documentation/pdf/18/postgresql-18-A4.pdf"},"US":{"built_at":"2026-09-26","bytes":15748059,"pages":3328,"sha256":"facbe6c229e598b872d3d98bef53308f46e06746006fa4590de9a7de9dd46319","url":"/files/documentation/pdf/18/postgresql-18-US.pdf"}},"release":"18.6","source_mode":"en SGML built with pinned official archive","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","svg_assets":3,"tree":"18"},"ref":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","revision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"},"sections":[],"sections_zh":[],"signature":"pg_archivecleanup [ option ...] archivelocation oldestkeptwalfile","sources":[{"anchor":"","file":"pgarchivecleanup.html","label":"18.6 English manual · pgarchivecleanup.html","sha256":"430282b0bbc63a05afa75dce3a9f5abd25be1c155de79c0274537e341914d7b4","url":"/docs/18/pgarchivecleanup.html"},{"anchor":"","file":"reference-server.html","label":"Server applications inventory","sha256":"e9f8bbcc8e3641fadd1d20991e8aad6b532155b786ba5a1b7b364ec4f1a5bef3","url":"/docs/18/reference-server.html"}],"synopsis":["pg_archivecleanup [ option ...] archivelocation oldestkeptwalfile"],"tables":[{"columns":[{"key":"signature","label":"Option and arguments"},{"key":"summary","label":"Description"}],"key":"options","rows":[{"signature":{"text":"-b --clean-backup-history","url":"/docs/18/pgarchivecleanup.html"},"summary":"Remove backup history files as well. See Section 25.3.2 for details about backup history files."},{"signature":{"text":"-d --debug","url":"/docs/18/pgarchivecleanup.html"},"summary":"Print lots of debug logging output on stderr ."},{"signature":{"text":"-n --dry-run","url":"/docs/18/pgarchivecleanup.html"},"summary":"Print the names of the files that would have been removed on stdout (performs a dry run)."},{"signature":{"text":"-V --version","url":"/docs/18/pgarchivecleanup.html"},"summary":"Print the pg_archivecleanup version and exit."},{"signature":{"text":"-x extension --strip-extension= extension","url":"/docs/18/pgarchivecleanup.html"},"summary":"Provide an extension that will be stripped from all file names before deciding if they should be deleted. This is typically useful for cleaning up archives that have been compressed during storage, and therefore have had an extension added by the compression program. For example: -x .gz ."},{"signature":{"text":"-? --help","url":"/docs/18/pgarchivecleanup.html"},"summary":"Show help about pg_archivecleanup command line arguments, and exit."}],"title":"Documented options"}],"tables_zh":[{"columns":[{"key":"signature","label":"选项与参数"},{"key":"summary","label":"说明"}],"key":"options","rows":[{"signature":{"text":"-b --clean-backup-history","url":"/docs/18/pgarchivecleanup.html"},"summary":"同时移除备份历史文件。关于备份历史文件的详细信息，见 第 25.3.2 节 。"},{"signature":{"text":"-d --debug","url":"/docs/18/pgarchivecleanup.html"},"summary":"在 stderr 上输出大量调试日志。"},{"signature":{"text":"-n --dry-run","url":"/docs/18/pgarchivecleanup.html"},"summary":"在 stdout 上打印原本会被移除的文件名（执行试运行）。"},{"signature":{"text":"-V --version","url":"/docs/18/pgarchivecleanup.html"},"summary":"输出 pg_archivecleanup 的版本号并退出。"},{"signature":{"text":"-x extension --strip-extension= extension","url":"/docs/18/pgarchivecleanup.html"},"summary":"指定一个扩展名；在判断文件是否应删除之前，会先从所有文件名中去掉该扩展名。这通常适用于清理由于存储时经过压缩、因而被压缩程序附加了扩展名的归档。例如： -x .gz 。"},{"signature":{"text":"-? --help","url":"/docs/18/pgarchivecleanup.html"},"summary":"显示有关 pg_archivecleanup 命令行参数的帮助并退出。"}],"title":"手册中的选项"}],"zh_from":{"authored_translation":"source-derived-identity","body_sha256":"941261e3f1fecb68ed24a43db2be2408a3d63ec78d22c30d054f5734834541ff","kind":"same-version-chinese-manual-with-source-derived-identity","manual":{"anchor":"","build_id":107,"extraction":"command-description-and-options","fragment_sha256":"5f30191d172ffdd6154111b258765b9d89222202fec7b76c3cb33bea9100d4c6","locale":"zh-Hans","page_key":"pgarchivecleanup.html","source_hash":"ce6a1d4f291d010faa809253f29fe21f42fa3ddc74b2e158ed1ddf4e37bdc2c8","source_revision":"unknown:rendered-translation-baseline","translated_from_revision":null,"translation_revision":"git:b1b500221dbe5437cfca004d6b04d3f6e422765d;html-sha256:08e987a66af27b98444a8057c256314eafa13611a3fb9e888214fc436824244b","url":"/zh/docs/18/pgarchivecleanup.html","version":"18"},"runtime_rerun":false,"source_facts_revision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8"}},"ManualEvidence":{"manual_path":"pgarchivecleanup.html","release":{"channel":"stable","evidence_kind":"English manual and source declarations","label":"18.6","major":"18","manifest":{"index":"index.html","major":"18","pages":1148,"pdf":{"A4":{"built_at":"2026-09-26","bytes":15865106,"pages":3154,"sha256":"19512c405da53f9f7fcf0abba359223aa65f021be025bf3411381918f92e3190","url":"/files/documentation/pdf/18/postgresql-18-A4.pdf"},"US":{"built_at":"2026-09-26","bytes":15748059,"pages":3328,"sha256":"facbe6c229e598b872d3d98bef53308f46e06746006fa4590de9a7de9dd46319","url":"/files/documentation/pdf/18/postgresql-18-US.pdf"}},"release":"18.6","source_mode":"en SGML built with pinned official archive","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","svg_assets":3,"tree":"18"},"ref":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","revision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"},"sources":[{"anchor":"","file":"pgarchivecleanup.html","label":"18.6 English manual · pgarchivecleanup.html","sha256":"430282b0bbc63a05afa75dce3a9f5abd25be1c155de79c0274537e341914d7b4","url":"/docs/18/pgarchivecleanup.html"},{"anchor":"","file":"reference-server.html","label":"Server applications inventory","sha256":"e9f8bbcc8e3641fadd1d20991e8aad6b532155b786ba5a1b7b364ec4f1a5bef3","url":"/docs/18/reference-server.html"}]},"MeasuredEvidence":{}},"Text":{"Collection":"tool","Key":"pg-archivecleanup","SourceDatabase":"center","Version":"18","Locale":"en","Title":"pg_archivecleanup","Summary":"pg_archivecleanup — clean up PostgreSQL WAL archive files","BodyHTML":"\u003cdiv\u003e\u003cdiv id=\"PGARCHIVECLEANUP\"\u003e\n\u003cdiv\u003e\u003c/div\u003e\n\u003cdiv\u003e\n\u003ch2\u003e\u003cspan\u003e\u003cspan\u003epg_archivecleanup\u003c/span\u003e\u003c/span\u003e\u003c/h2\u003e\n\u003cp\u003epg_archivecleanup — clean up \u003cspan\u003ePostgreSQL\u003c/span\u003e WAL archive files\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv\u003e\n\u003ch2\u003eSynopsis\u003c/h2\u003e\n\u003cdiv\u003e\n\u003cp id=\"id-1.9.5.4.4.1\"\u003e\u003ccode\u003epg_archivecleanup\u003c/code\u003e [\u003cem\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e...] \u003cem\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e \u003cem\u003e\u003ccode\u003eoldestkeptwalfile\u003c/code\u003e\u003c/em\u003e\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"id-1.9.5.4.5\"\u003e\n\u003ch2\u003eDescription\u003c/h2\u003e\n\u003cp\u003e\u003cspan\u003epg_archivecleanup\u003c/span\u003e is designed to be used as an \u003ccode\u003earchive_cleanup_command\u003c/code\u003e to clean up WAL file archives when running as a standby server (see \u003ca href=\"/docs/18/warm-standby.html\" rel=\"nofollow\"\u003eSection 26.2\u003c/a\u003e). \u003cspan\u003epg_archivecleanup\u003c/span\u003e can also be used as a standalone program to clean WAL file archives.\u003c/p\u003e\n\u003cp\u003eTo configure a standby server to use \u003cspan\u003epg_archivecleanup\u003c/span\u003e, put this into its \u003ccode\u003epostgresql.conf\u003c/code\u003e configuration file:\u003c/p\u003e\n\u003cpre\u003earchive_cleanup_command = \u0026#39;pg_archivecleanup \u003cem\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e %r\u0026#39;\n\u003c/pre\u003e\n\u003cp\u003ewhere \u003cem\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e is the directory from which WAL segment files should be removed.\u003c/p\u003e\n\u003cp\u003eWhen used within \u003ca href=\"/docs/18/runtime-config-wal.html#GUC-ARCHIVE-CLEANUP-COMMAND\" rel=\"nofollow\"\u003earchive_cleanup_command\u003c/a\u003e, all WAL files logically preceding the value of the \u003ccode\u003e%r\u003c/code\u003e argument will be removed from \u003cem\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e. This minimizes the number of files that need to be retained, while preserving crash-restart capability. Use of this parameter is appropriate if the \u003cem\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e is a transient staging area for this particular standby server, but \u003cspan\u003e\u003cem\u003enot\u003c/em\u003e\u003c/span\u003e when the \u003cem\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e is intended as a long-term WAL archive area, or when multiple standby servers are recovering from the same archive location.\u003c/p\u003e\n\u003cp\u003eWhen used as a standalone program all WAL files logically preceding the \u003cem\u003e\u003ccode\u003eoldestkeptwalfile\u003c/code\u003e\u003c/em\u003e will be removed from \u003cem\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e. In this mode, if you specify a \u003ccode\u003e.partial\u003c/code\u003e or \u003ccode\u003e.backup\u003c/code\u003e file name, then only the file prefix will be used as the \u003cem\u003e\u003ccode\u003eoldestkeptwalfile\u003c/code\u003e\u003c/em\u003e. This treatment of \u003ccode\u003e.backup\u003c/code\u003e file name allows you to remove all WAL files archived prior to a specific base backup without error. For example, the following example will remove all files older than WAL file name \u003ccode\u003e000000010000003700000010\u003c/code\u003e:\u003c/p\u003e\n\u003cpre\u003epg_archivecleanup -d archive 000000010000003700000010.00000020.backup\n\npg_archivecleanup:  keep WAL file \u0026#34;archive/000000010000003700000010\u0026#34; and later\npg_archivecleanup:  removing file \u0026#34;archive/00000001000000370000000F\u0026#34;\npg_archivecleanup:  removing file \u0026#34;archive/00000001000000370000000E\u0026#34;\n\u003c/pre\u003e\n\u003cp\u003e\u003cspan\u003epg_archivecleanup\u003c/span\u003e assumes that \u003cem\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e is a directory readable and writable by the server-owning user.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv id=\"id-1.9.5.4.6\"\u003e\n\u003ch2\u003eOptions\u003c/h2\u003e\n\u003cp\u003e\u003cspan\u003epg_archivecleanup\u003c/span\u003e accepts the following command-line arguments:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cdl\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-b\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--clean-backup-history\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eRemove backup history files as well. See \u003ca href=\"/docs/18/continuous-archiving.html#BACKUP-BASE-BACKUP\" rel=\"nofollow\"\u003eSection 25.3.2\u003c/a\u003e for details about backup history files.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-d\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--debug\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ePrint lots of debug logging output on \u003ccode\u003estderr\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-n\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--dry-run\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ePrint the names of the files that would have been removed on \u003ccode\u003estdout\u003c/code\u003e (performs a dry run).\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-V\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--version\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ePrint the \u003cspan\u003epg_archivecleanup\u003c/span\u003e version and exit.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-x \u003cem\u003e\u003ccode\u003eextension\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--strip-extension=\u003cem\u003e\u003ccode\u003eextension\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eProvide an extension that will be stripped from all file names before deciding if they should be deleted. This is typically useful for cleaning up archives that have been compressed during storage, and therefore have had an extension added by the compression program. For example: \u003ccode\u003e-x .gz\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan\u003e\u003ccode\u003e-?\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan\u003e\u003ccode\u003e--help\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eShow help about \u003cspan\u003epg_archivecleanup\u003c/span\u003e command line arguments, and exit.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv id=\"id-1.9.5.4.7\"\u003e\n\u003ch2\u003eEnvironment\u003c/h2\u003e\n\u003cp\u003eThe environment variable \u003ccode\u003ePG_COLOR\u003c/code\u003e specifies whether to use color in diagnostic messages. Possible values are \u003ccode\u003ealways\u003c/code\u003e, \u003ccode\u003eauto\u003c/code\u003e and \u003ccode\u003enever\u003c/code\u003e.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv id=\"id-1.9.5.4.8\"\u003e\n\u003ch2\u003eNotes\u003c/h2\u003e\n\u003cp\u003e\u003cspan\u003epg_archivecleanup\u003c/span\u003e is designed to work with \u003cspan\u003ePostgreSQL\u003c/span\u003e 8.0 and later when used as a standalone utility, or with \u003cspan\u003ePostgreSQL\u003c/span\u003e 9.0 and later when used as an archive cleanup command.\u003c/p\u003e\n\u003cp\u003e\u003cspan\u003epg_archivecleanup\u003c/span\u003e is written in C and has an easy-to-modify source code, with specifically designated sections to modify for your own needs\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv id=\"id-1.9.5.4.9\"\u003e\n\u003ch2\u003eExamples\u003c/h2\u003e\n\u003cp\u003eOn Linux or Unix systems, you might use:\u003c/p\u003e\n\u003cpre\u003earchive_cleanup_command = \u0026#39;pg_archivecleanup -d /mnt/standby/archive %r 2\u0026gt;\u0026gt;cleanup.log\u0026#39;\n\u003c/pre\u003e\n\u003cp\u003ewhere the archive directory is physically located on the standby server, so that the \u003ccode\u003earchive_command\u003c/code\u003e is accessing it across NFS, but the files are local to the standby. This will:\u003c/p\u003e\n\u003cdiv\u003e\n\u003cul\u003e\n\u003cli\u003e\n\u003cp\u003eproduce debugging output in \u003ccode\u003ecleanup.log\u003c/code\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003eremove no-longer-needed files from the archive directory\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003c/div\u003e","SourceRevision":"ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8","ContentHash":"399bcf299e5d47c7090594f0118dc925563a2059001760afb4c5c83f65684cfd","Payload":{"description":["pg_archivecleanup — clean up PostgreSQL WAL archive files"],"manual_html":"\u003cdiv\u003e\u003cdiv class=\"refentry\" id=\"PGARCHIVECLEANUP\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\u003c/div\u003e\n\u003cdiv class=\"refnamediv\"\u003e\n\u003ch2\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e\u003c/span\u003e\u003c/h2\u003e\n\u003cp\u003epg_archivecleanup — clean up \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e WAL archive files\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsynopsisdiv\"\u003e\n\u003ch2\u003eSynopsis\u003c/h2\u003e\n\u003cdiv class=\"cmdsynopsis\"\u003e\n\u003cp id=\"id-1.9.5.4.4.1\"\u003e\u003ccode class=\"command\"\u003epg_archivecleanup\u003c/code\u003e [\u003cem class=\"replaceable\"\u003e\u003ccode\u003eoption\u003c/code\u003e\u003c/em\u003e...] \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoldestkeptwalfile\u003c/code\u003e\u003c/em\u003e\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.4.5\"\u003e\n\u003ch2\u003eDescription\u003c/h2\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e is designed to be used as an \u003ccode class=\"literal\"\u003earchive_cleanup_command\u003c/code\u003e to clean up WAL file archives when running as a standby server (see \u003ca class=\"xref\" href=\"/docs/18/warm-standby.html\" title=\"26.2. Log-Shipping Standby Servers\"\u003eSection 26.2\u003c/a\u003e). \u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e can also be used as a standalone program to clean WAL file archives.\u003c/p\u003e\n\u003cp\u003eTo configure a standby server to use \u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e, put this into its \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e configuration file:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003earchive_cleanup_command = 'pg_archivecleanup \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e %r'\n\u003c/pre\u003e\n\u003cp\u003ewhere \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e is the directory from which WAL segment files should be removed.\u003c/p\u003e\n\u003cp\u003eWhen used within \u003ca class=\"xref\" href=\"/docs/18/runtime-config-wal.html#GUC-ARCHIVE-CLEANUP-COMMAND\"\u003earchive_cleanup_command\u003c/a\u003e, all WAL files logically preceding the value of the \u003ccode class=\"literal\"\u003e%r\u003c/code\u003e argument will be removed from \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e. This minimizes the number of files that need to be retained, while preserving crash-restart capability. Use of this parameter is appropriate if the \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e is a transient staging area for this particular standby server, but \u003cspan class=\"emphasis\"\u003e\u003cem\u003enot\u003c/em\u003e\u003c/span\u003e when the \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e is intended as a long-term WAL archive area, or when multiple standby servers are recovering from the same archive location.\u003c/p\u003e\n\u003cp\u003eWhen used as a standalone program all WAL files logically preceding the \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoldestkeptwalfile\u003c/code\u003e\u003c/em\u003e will be removed from \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e. In this mode, if you specify a \u003ccode class=\"filename\"\u003e.partial\u003c/code\u003e or \u003ccode class=\"filename\"\u003e.backup\u003c/code\u003e file name, then only the file prefix will be used as the \u003cem class=\"replaceable\"\u003e\u003ccode\u003eoldestkeptwalfile\u003c/code\u003e\u003c/em\u003e. This treatment of \u003ccode class=\"filename\"\u003e.backup\u003c/code\u003e file name allows you to remove all WAL files archived prior to a specific base backup without error. For example, the following example will remove all files older than WAL file name \u003ccode class=\"filename\"\u003e000000010000003700000010\u003c/code\u003e:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003epg_archivecleanup -d archive 000000010000003700000010.00000020.backup\n\npg_archivecleanup:  keep WAL file \"archive/000000010000003700000010\" and later\npg_archivecleanup:  removing file \"archive/00000001000000370000000F\"\npg_archivecleanup:  removing file \"archive/00000001000000370000000E\"\n\u003c/pre\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e assumes that \u003cem class=\"replaceable\"\u003e\u003ccode\u003earchivelocation\u003c/code\u003e\u003c/em\u003e is a directory readable and writable by the server-owning user.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.4.6\"\u003e\n\u003ch2\u003eOptions\u003c/h2\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e accepts the following command-line arguments:\u003c/p\u003e\n\u003cdiv class=\"variablelist\"\u003e\n\u003cdl class=\"variablelist\"\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-b\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--clean-backup-history\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eRemove backup history files as well. See \u003ca class=\"xref\" href=\"/docs/18/continuous-archiving.html#BACKUP-BASE-BACKUP\" title=\"25.3.2. Making a Base Backup\"\u003eSection 25.3.2\u003c/a\u003e for details about backup history files.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-d\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--debug\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ePrint lots of debug logging output on \u003ccode class=\"filename\"\u003estderr\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-n\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--dry-run\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ePrint the names of the files that would have been removed on \u003ccode class=\"filename\"\u003estdout\u003c/code\u003e (performs a dry run).\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-V\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--version\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003ePrint the \u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e version and exit.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-x \u003cem class=\"replaceable\"\u003e\u003ccode\u003eextension\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--strip-extension=\u003cem class=\"replaceable\"\u003e\u003ccode\u003eextension\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eProvide an extension that will be stripped from all file names before deciding if they should be deleted. This is typically useful for cleaning up archives that have been compressed during storage, and therefore have had an extension added by the compression program. For example: \u003ccode class=\"literal\"\u003e-x .gz\u003c/code\u003e.\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e-?\u003c/code\u003e\u003cbr\u003e\u003c/span\u003e\u003cspan class=\"term\"\u003e\u003ccode class=\"option\"\u003e--help\u003c/code\u003e\u003c/span\u003e\u003c/dt\u003e\n\u003cdd\u003e\n\u003cp\u003eShow help about \u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e command line arguments, and exit.\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.4.7\"\u003e\n\u003ch2\u003eEnvironment\u003c/h2\u003e\n\u003cp\u003eThe environment variable \u003ccode class=\"envar\"\u003ePG_COLOR\u003c/code\u003e specifies whether to use color in diagnostic messages. Possible values are \u003ccode class=\"literal\"\u003ealways\u003c/code\u003e, \u003ccode class=\"literal\"\u003eauto\u003c/code\u003e and \u003ccode class=\"literal\"\u003enever\u003c/code\u003e.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.4.8\"\u003e\n\u003ch2\u003eNotes\u003c/h2\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e is designed to work with \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 8.0 and later when used as a standalone utility, or with \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 9.0 and later when used as an archive cleanup command.\u003c/p\u003e\n\u003cp\u003e\u003cspan class=\"application\"\u003epg_archivecleanup\u003c/span\u003e is written in C and has an easy-to-modify source code, with specifically designated sections to modify for your own needs\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv class=\"refsect1\" id=\"id-1.9.5.4.9\"\u003e\n\u003ch2\u003eExamples\u003c/h2\u003e\n\u003cp\u003eOn Linux or Unix systems, you might use:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003earchive_cleanup_command = 'pg_archivecleanup -d /mnt/standby/archive %r 2\u0026gt;\u0026gt;cleanup.log'\n\u003c/pre\u003e\n\u003cp\u003ewhere the archive directory is physically located on the standby server, so that the \u003ccode class=\"varname\"\u003earchive_command\u003c/code\u003e is accessing it across NFS, but the files are local to the standby. This will:\u003c/p\u003e\n\u003cdiv class=\"itemizedlist\"\u003e\n\u003cul class=\"itemizedlist\"\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eproduce debugging output in \u003ccode class=\"filename\"\u003ecleanup.log\u003c/code\u003e\u003c/p\u003e\n\u003c/li\u003e\n\u003cli class=\"listitem\"\u003e\n\u003cp\u003eremove no-longer-needed files from the archive directory\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003c/div\u003e","related":[],"sections":[],"tables":[{"columns":[{"key":"signature","label":"Option and arguments"},{"key":"summary","label":"Description"}],"key":"options","rows":[{"signature":{"text":"-b --clean-backup-history","url":"/docs/18/pgarchivecleanup.html"},"summary":"Remove backup history files as well. See Section 25.3.2 for details about backup history files."},{"signature":{"text":"-d --debug","url":"/docs/18/pgarchivecleanup.html"},"summary":"Print lots of debug logging output on stderr ."},{"signature":{"text":"-n --dry-run","url":"/docs/18/pgarchivecleanup.html"},"summary":"Print the names of the files that would have been removed on stdout (performs a dry run)."},{"signature":{"text":"-V --version","url":"/docs/18/pgarchivecleanup.html"},"summary":"Print the pg_archivecleanup version and exit."},{"signature":{"text":"-x extension --strip-extension= extension","url":"/docs/18/pgarchivecleanup.html"},"summary":"Provide an extension that will be stripped from all file names before deciding if they should be deleted. This is typically useful for cleaning up archives that have been compressed during storage, and therefore have had an extension added by the compression program. For example: -x .gz ."},{"signature":{"text":"-? --help","url":"/docs/18/pgarchivecleanup.html"},"summary":"Show help about pg_archivecleanup command line arguments, and exit."}],"title":"Documented options"}]}},"RequestedLocale":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
