{"Entry":{"collection":"guc","key":"archive_command","name":"archive_command","aliases":[],"metadata":{"baseline":false,"boot_human":"Not specified","boot_val":null,"category":"Write-Ahead Log / Archiving","category_zh":"","changed_in":["15","18"],"changes":[{"documentation_changed":false,"fields":{},"from":"7.4","status":"added","to":"8.0"},{"documentation_changed":true,"fields":{},"from":"8.0","status":"changed","to":"8.1"},{"documentation_changed":true,"fields":{},"from":"8.1","status":"changed","to":"8.2"},{"documentation_changed":true,"fields":{},"from":"8.2","status":"changed","to":"8.3"},{"documentation_changed":true,"fields":{},"from":"8.4","status":"changed","to":"9.0"},{"documentation_changed":true,"fields":{},"from":"9.3","status":"changed","to":"9.4"},{"documentation_changed":true,"fields":{},"from":"9.4","status":"changed","to":"9.5"},{"documentation_changed":true,"fields":{},"from":"9.5","status":"changed","to":"9.6"},{"documentation_changed":true,"fields":{},"from":"13","status":"changed","to":"14"},{"documentation_changed":true,"fields":{"extra_desc":{"from":null,"to":"This is used only if \"archive_library\" is not set."}},"from":"14","status":"changed","to":"15"},{"documentation_changed":true,"fields":{},"from":"15","status":"changed","to":"16"},{"documentation_changed":true,"fields":{},"from":"16","status":"changed","to":"17"},{"documentation_changed":false,"fields":{"extra_desc":{"from":"This is used only if \"archive_library\" is not set.","to":"An empty string means use \"archive_library\"."}},"from":"17","status":"changed","to":"18"}],"content_hash":"d66be3669eb87684b6ec6712ef2b5ff8b4a3ae162f5772b963843093e5a04c0a","context":"","default_changed_in":[],"default_history":[{"from":"9.0","to":"19","value":"Empty string"}],"derived_content_hash":"45a138dd42dcf027868834942e10e5618d2265ebf7c73c7ecdcfe0c0db3f1115","editorial":{"advice":{"olap":"Provision archive throughput and capacity for bulk-load WAL peaks. If archiving falls behind, throttle the job and alert; never hide backlog with false success or aggressive cleanup.","oltp":"Manage archive_command as part of the backup/restore protocol: the command or module must be idempotent, fail visibly, and be verified by restoring from the real archive—not merely by exit status.","small":"Enable it only for a defined PITR requirement and use a mature backup tool. Keep rebuildable instances simple, but never install a no-op command that creates the illusion of a backup."},"mechanism":["Sets the shell command that will be called to archive a WAL file. A configuration reload applies a new value; existing work already in flight is not retroactively changed.","The archiver expands %p to the source path and %f to the WAL file name, and considers exit status zero a durable success. A nonzero result is retried; a false success allows PostgreSQL to recycle the only local copy and silently breaks the archive chain.","Monitor and change archive_command together with archive_mode, archive_library, archive_timeout. Validate on the relevant server role and real workload, then use its sighup context to choose session change, reload, or restart; a historical boot default is not the current effective value."],"pitfalls":["Returning success before the archive copy is durable or verified.","Failing to quote %p/%f safely in a shell command.","Letting repeated failures fill pg_wal and stop the server.","Confusing pg_settings base units with human-readable configuration units.","Benchmarking throughput without a crash-recovery and archive-restore test."],"references":[{"title":"PostgreSQL 19 Beta 4: archive_command","url":"https://www.postgresql.org/docs/19/runtime-config-wal.html#GUC-ARCHIVE-COMMAND"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["archive_mode","archive_library","archive_timeout","archive_cleanup_command","restore_command","recovery_end_command"],"summary":"archive_command — Sets the shell command that will be called to archive a WAL file. Observed in PG9.0–19 Beta 4; its last measured boot default is empty string in PG19 Beta 4, with sighup context. This is a beta-snapshot fact and can change before PostgreSQL 19 GA."},"enumvals":[],"first_version":"8.0","group":"Write-Ahead Log","group_slug":"wal","imported_at":"2026-09-27T17:57:30.75336+08:00","intro_commit":{},"key":"archive_command","last_version":"20","max_val":"","min_val":"","name":"archive_command","position":9,"present_in":["8.0","8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6","10","11","12","13","14","15","16","17","18","19","20"],"repair_provenance":{"original_source_revision":"english-manuals:6f8041df52107b90e28760d91a04b9b98ab12bab5d2b6dbd6c2e35b6e70d919a","receipt_sha256":"8667038964af4281140ba049d486a0cf4d51f11b65b44374e578143cc29f4ce6","repair":"wiki-repair-20261023"},"short_desc":"The local shell command to execute to archive a completed WAL file segment.","short_desc_zh":"","source_rev":"wiki-repair-20261023:04a4d0698bd21626cb98772b261f488bff4fed920a0faa988e6f1c98cfa430e0","unit":"","vartype":"string"}},"Definition":{"Collection":"guc","Key":"archive_command","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"archive_command","SourceRevision":"wiki-repair-20261023:04a4d0698bd21626cb98772b261f488bff4fed920a0faa988e6f1c98cfa430e0","Facts":{"boot_val":"","category":"Write-Ahead Log / Archiving","context":"sighup","description":"The local shell command to execute to archive a completed WAL file segment. Any %p in the string is replaced by the path name of the file to archive, and any %f is replaced by only the file name. (The path name is relative to the working directory of the server, i.e., the cluster's data directory.) Use %% to embed an actual % character in the command. It is important for the command to return a zero exit status only if it succeeds. For more information see Section 25.3.1. This parameter can only be set in the postgresql.conf file or on the server command line. It is only used if archive_mode was enabled at server start and archive_library is set to an empty string. If both archive_command and archive_library are set, an error will be raised. If archive_command is an empty string (the default) while archive_mode is enabled (and archive_library is set to an empty string), WAL archiving is temporarily disabled, but the server continues to accumulate WAL segment files in the expectation that a command will soon be provided. Setting archive_command to a command that does nothing but return true, e.g., /bin/true (REM on Windows), effectively disables archiving, but also breaks the chain of WAL files needed for archive recovery, so it should only be used in unusual circumstances.","description_zh":"本地 shell 命令被执行来归档一个完成的 WAL 段文件。字符串中的任何 %p 被替换成要被归档的文件的路径名，而 %f 只被文件名替换（路径名是相对于服务器的工作目录，即集簇的数据目录）。如果要在命令里嵌入一个真正的% 字符，可以使用%%。有一点很重要，该命令只在成功时返回一个零作为退出状态。更多信息请见第 25.3.1 节。 这个参数只能在 postgresql.conf 文件或服务器命令行中设置。除非在服务器启动时启用了 archive_mode 并且 archive_library 设置为空字符串，否则将被忽略。如果 archive_command 和 archive_library 都被设置，则会报错。如果 archive_command 是空字符串（默认值），而 archive_mode 已启用（并且 archive_library 设置为空字符串），WAL 归档将暂时被禁用，但服务器将继续积累 WAL 段文件，期望很快会提供命令。将 archive_command 设置为一个什么都不做但返回 true 的命令，例如 /bin/true（Windows 上为 REM），实际上禁用了归档，但也破坏了用于归档恢复所需的 WAL 文件链，因此只应在不寻常的情况下使用。","description_zh_html":"\u003cp\u003e\n        本地 shell 命令被执行来归档一个完成的 WAL 段文件。字符串中的任何 \u003ccode class=\"literal\"\u003e%p\u003c/code\u003e 被替换成要被归档的文件的路径名，而 \u003ccode class=\"literal\"\u003e%f\u003c/code\u003e 只被文件名替换（路径名是相对于服务器的工作目录，即集簇的数据目录）。如果要在命令里嵌入一个真正的\u003ccode class=\"literal\"\u003e%\u003c/code\u003e 字符，可以使用\u003ccode class=\"literal\"\u003e%%\u003c/code\u003e。有一点很重要，该命令只在成功时返回一个零作为退出状态。更多信息请见\u003ca class=\"xref\" href=\"/zh/docs/18/continuous-archiving.html#BACKUP-ARCHIVING-WAL\" title=\"25.3.1. 设置 WAL 归档\"\u003e第 25.3.1 节\u003c/a\u003e。\n       \u003c/p\u003e\u003cp\u003e\n        这个参数只能在 \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e 文件或服务器命令行中设置。除非在服务器启动时启用了 \u003ccode class=\"varname\"\u003earchive_mode\u003c/code\u003e 并且 \u003ccode class=\"varname\"\u003earchive_library\u003c/code\u003e 设置为空字符串，否则将被忽略。如果 \u003ccode class=\"varname\"\u003earchive_command\u003c/code\u003e 和 \u003ccode class=\"varname\"\u003earchive_library\u003c/code\u003e 都被设置，则会报错。如果 \u003ccode class=\"varname\"\u003earchive_command\u003c/code\u003e 是空字符串（默认值），而 \u003ccode class=\"varname\"\u003earchive_mode\u003c/code\u003e 已启用（并且 \u003ccode class=\"varname\"\u003earchive_library\u003c/code\u003e 设置为空字符串），WAL 归档将暂时被禁用，但服务器将继续积累 WAL 段文件，期望很快会提供命令。将 \u003ccode class=\"varname\"\u003earchive_command\u003c/code\u003e 设置为一个什么都不做但返回 true 的命令，例如 \u003ccode class=\"literal\"\u003e/bin/true\u003c/code\u003e（Windows 上为 \u003ccode class=\"literal\"\u003eREM\u003c/code\u003e），实际上禁用了归档，但也破坏了用于归档恢复所需的 WAL 文件链，因此只应在不寻常的情况下使用。\n       \u003c/p\u003e","doc":{"anchor":"GUC-ARCHIVE-COMMAND","file":"runtime-config-wal.html","lang":"en","sha256":"d2646404a06e8f7ac655204b4f28c049ae8f3fd4f2272db080fcefa2c4af0763","slug":"18"},"documented":true,"enumvals":null,"extra_desc":"An empty string means use \"archive_library\".","lang":"en","max_val":null,"metadata_version":"18","min_val":null,"name":"archive_command","short_desc":"Sets the shell command that will be called to archive a WAL file.","source":"pg-settings-source-snapshot","translation_provenance":{"inputs":[{"kind":"current-pgdoc-translation","path":"/Users/vonng/pgsty/pgdoc/zh/18/html/runtime-config-wal.html","sha256":"94cdacb1171b4c528492ca0aec6aafa48a2c758276225fe0dbfe5b12452d4930"}],"kind":"same-version-pgdoc","locale":"zh-Hans","source_revision":"b1b500221dbe5437cfca004d6b04d3f6e422765d","version":"18"},"unit":null,"vartype":"string","zh_from":"same-version-pgdoc"},"ManualEvidence":{"doc":{"anchor":"GUC-ARCHIVE-COMMAND","file":"runtime-config-wal.html","lang":"en","sha256":"d2646404a06e8f7ac655204b4f28c049ae8f3fd4f2272db080fcefa2c4af0763","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"archive_command","SourceDatabase":"center","Version":"18","Locale":"en","Title":"archive_command","Summary":"The local shell command to execute to archive a completed WAL file segment. Any %p in the string is replaced by the path name of the file to archive, and any %f is replaced by only the file name. (The path name is relative to the working directory of the server, i.e., the cluster's data directory.) Use %% to embed an actual % character in the command. It is important for the command to return a zero exit status only if it succeeds. For more information see Section 25.3.1. This parameter can only be set in the postgresql.conf file or on the server command line. It is only used if archive_mode was enabled at server start and archive_library is set to an empty string. If both archive_command and archive_library are set, an error will be raised. If archive_command is an empty string (the default) while archive_mode is enabled (and archive_library is set to an empty string), WAL archiving is temporarily disabled, but the server continues to accumulate WAL segment files in the expectation that a command will soon be provided. Setting archive_command to a command that does nothing but return true, e.g., /bin/true (REM on Windows), effectively disables archiving, but also breaks the chain of WAL files needed for archive recovery, so it should only be used in unusual circumstances.","BodyHTML":"\u003cp\u003eThe local shell command to execute to archive a completed WAL file segment. Any %p in the string is replaced by the path name of the file to archive, and any %f is replaced by only the file name. (The path name is relative to the working directory of the server, i.e., the cluster\u0026#39;s data directory.) Use %% to embed an actual % character in the command. It is important for the command to return a zero exit status only if it succeeds. For more information see Section 25.3.1. This parameter can only be set in the postgresql.conf file or on the server command line. It is only used if archive_mode was enabled at server start and archive_library is set to an empty string. If both archive_command and archive_library are set, an error will be raised. If archive_command is an empty string (the default) while archive_mode is enabled (and archive_library is set to an empty string), WAL archiving is temporarily disabled, but the server continues to accumulate WAL segment files in the expectation that a command will soon be provided. Setting archive_command to a command that does nothing but return true, e.g., /bin/true (REM on Windows), effectively disables archiving, but also breaks the chain of WAL files needed for archive recovery, so it should only be used in unusual circumstances.\u003c/p\u003e","SourceRevision":"wiki-repair-20261023:04a4d0698bd21626cb98772b261f488bff4fed920a0faa988e6f1c98cfa430e0","ContentHash":"29aa33ba36f42b2aea69b3799552c9598bbb13d7b0da292db7d609f46c66335f","Payload":{"description":"The local shell command to execute to archive a completed WAL file segment. Any %p in the string is replaced by the path name of the file to archive, and any %f is replaced by only the file name. (The path name is relative to the working directory of the server, i.e., the cluster's data directory.) Use %% to embed an actual % character in the command. It is important for the command to return a zero exit status only if it succeeds. For more information see Section 25.3.1. This parameter can only be set in the postgresql.conf file or on the server command line. It is only used if archive_mode was enabled at server start and archive_library is set to an empty string. If both archive_command and archive_library are set, an error will be raised. If archive_command is an empty string (the default) while archive_mode is enabled (and archive_library is set to an empty string), WAL archiving is temporarily disabled, but the server continues to accumulate WAL segment files in the expectation that a command will soon be provided. Setting archive_command to a command that does nothing but return true, e.g., /bin/true (REM on Windows), effectively disables archiving, but also breaks the chain of WAL files needed for archive recovery, so it should only be used in unusual circumstances."}},"RequestedLocale":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","8.0","8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
