{
    "mode": "man",
    "parameter": "pg_receivewal",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/pg_receivewal/1/json",
    "generated": "2026-06-15T16:42:37Z",
    "synopsis": "pgreceivewal [option...]",
    "sections": {
        "NAME": {
            "content": "pgreceivewal - stream write-ahead logs from a PostgreSQL server\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "pgreceivewal [option...]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "pgreceivewal is used to stream the write-ahead log from a running PostgreSQL cluster. The\nwrite-ahead log is streamed using the streaming replication protocol, and is written to a\nlocal directory of files. This directory can be used as the archive location for doing a\nrestore using point-in-time recovery (see Section 26.3).\n\npgreceivewal streams the write-ahead log in real time as it's being generated on the server,\nand does not wait for segments to complete like archivecommand does. For this reason, it is\nnot necessary to set archivetimeout when using pgreceivewal.\n\nUnlike the WAL receiver of a PostgreSQL standby server, pgreceivewal by default flushes WAL\ndata only when a WAL file is closed. The option --synchronous must be specified to flush WAL\ndata in real time. Since pgreceivewal does not apply WAL, you should not allow it to become\na synchronous standby when synchronouscommit equals remoteapply. If it does, it will appear\nto be a standby that never catches up, and will cause transaction commits to block. To avoid\nthis, you should either configure an appropriate value for synchronousstandbynames, or\nspecify applicationname for pgreceivewal that does not match it, or change the value of\nsynchronouscommit to something other than remoteapply.\n\nThe write-ahead log is streamed over a regular PostgreSQL connection and uses the replication\nprotocol. The connection must be made with a user having REPLICATION permissions (see\nSection 22.2) or a superuser, and pghba.conf must permit the replication connection. The\nserver must also be configured with maxwalsenders set high enough to leave at least one\nsession available for the stream.\n\nThe starting point of the write-ahead log streaming is calculated when pgreceivewal starts:\n\n1. First, scan the directory where the WAL segment files are written and find the newest\ncompleted segment file, using as the starting point the beginning of the next WAL segment\nfile.\n\n2. If a starting point cannot be calculated with the previous method, the latest WAL flush\nlocation is used as reported by the server from an IDENTIFYSYSTEM command.\n\nIf the connection is lost, or if it cannot be initially established, with a non-fatal error,\npgreceivewal will retry the connection indefinitely, and reestablish streaming as soon as\npossible. To avoid this behavior, use the -n parameter.\n\nIn the absence of fatal errors, pgreceivewal will run until terminated by the SIGINT signal\n(Control+C).\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "-D",
                    "content": "--directory=directory\nDirectory to write the output to.\n\nThis parameter is required.\n",
                    "flag": "-D"
                },
                {
                    "name": "-E",
                    "content": "--endpos=lsn\nAutomatically stop replication and exit with normal exit status 0 when receiving reaches\nthe specified LSN.\n\nIf there is a record with LSN exactly equal to lsn, the record will be processed.\n",
                    "flag": "-E"
                },
                {
                    "name": "--if-not-exists",
                    "content": "Do not error out when --create-slot is specified and a slot with the specified name\nalready exists.\n",
                    "long": "--if-not-exists"
                },
                {
                    "name": "-n",
                    "content": "",
                    "flag": "-n"
                },
                {
                    "name": "--no-loop",
                    "content": "Don't loop on connection errors. Instead, exit right away with an error.\n",
                    "long": "--no-loop"
                },
                {
                    "name": "--no-sync",
                    "content": "This option causes pgreceivewal to not force WAL data to be flushed to disk. This is\nfaster, but means that a subsequent operating system crash can leave the WAL segments\ncorrupt. Generally, this option is useful for testing but should not be used when doing\nWAL archiving on a production deployment.\n\nThis option is incompatible with --synchronous.\n",
                    "long": "--no-sync"
                },
                {
                    "name": "-s",
                    "content": "--status-interval=interval\nSpecifies the number of seconds between status packets sent back to the server. This\nallows for easier monitoring of the progress from server. A value of zero disables the\nperiodic status updates completely, although an update will still be sent when requested\nby the server, to avoid timeout disconnect. The default value is 10 seconds.\n",
                    "flag": "-s"
                },
                {
                    "name": "-S",
                    "content": "--slot=slotname\nRequire pgreceivewal to use an existing replication slot (see Section 27.2.6). When this\noption is used, pgreceivewal will report a flush position to the server, indicating when\neach segment has been synchronized to disk so that the server can remove that segment if\nit is not otherwise needed.\n\nWhen the replication client of pgreceivewal is configured on the server as a synchronous\nstandby, then using a replication slot will report the flush position to the server, but\nonly when a WAL file is closed. Therefore, that configuration will cause transactions on\nthe primary to wait for a long time and effectively not work satisfactorily. The option\n--synchronous (see below) must be specified in addition to make this work correctly.\n",
                    "flag": "-S"
                },
                {
                    "name": "--synchronous",
                    "content": "Flush the WAL data to disk immediately after it has been received. Also send a status\npacket back to the server immediately after flushing, regardless of --status-interval.\n\nThis option should be specified if the replication client of pgreceivewal is configured\non the server as a synchronous standby, to ensure that timely feedback is sent to the\nserver.\n",
                    "long": "--synchronous"
                },
                {
                    "name": "-v",
                    "content": "",
                    "flag": "-v"
                },
                {
                    "name": "--verbose",
                    "content": "Enables verbose mode.\n",
                    "long": "--verbose"
                },
                {
                    "name": "-Z",
                    "content": "--compress=level\nEnables gzip compression of write-ahead logs, and specifies the compression level (0\nthrough 9, 0 being no compression and 9 being best compression). The suffix .gz will\nautomatically be added to all filenames.\n\nThe following command-line options control the database connection parameters.\n",
                    "flag": "-Z"
                },
                {
                    "name": "-d",
                    "content": "--dbname=connstr\nSpecifies parameters used to connect to the server, as a connection string; these will\noverride any conflicting command line options.\n\nThe option is called --dbname for consistency with other client applications, but because\npgreceivewal doesn't connect to any particular database in the cluster, database name in\nthe connection string will be ignored.\n",
                    "flag": "-d"
                },
                {
                    "name": "-h",
                    "content": "--host=host\nSpecifies the host name of the machine on which the server is running. If the value\nbegins with a slash, it is used as the directory for the Unix domain socket. The default\nis taken from the PGHOST environment variable, if set, else a Unix domain socket\nconnection is attempted.\n",
                    "flag": "-h"
                },
                {
                    "name": "-p",
                    "content": "--port=port\nSpecifies the TCP port or local Unix domain socket file extension on which the server is\nlistening for connections. Defaults to the PGPORT environment variable, if set, or a\ncompiled-in default.\n",
                    "flag": "-p"
                },
                {
                    "name": "-U",
                    "content": "--username=username\nUser name to connect as.\n",
                    "flag": "-U"
                },
                {
                    "name": "-w",
                    "content": "",
                    "flag": "-w"
                },
                {
                    "name": "--no-password",
                    "content": "Never issue a password prompt. If the server requires password authentication and a\npassword is not available by other means such as a .pgpass file, the connection attempt\nwill fail. This option can be useful in batch jobs and scripts where no user is present\nto enter a password.\n",
                    "long": "--no-password"
                },
                {
                    "name": "-W",
                    "content": "",
                    "flag": "-W"
                },
                {
                    "name": "--password",
                    "content": "Force pgreceivewal to prompt for a password before connecting to a database.\n\nThis option is never essential, since pgreceivewal will automatically prompt for a\npassword if the server demands password authentication. However, pgreceivewal will waste\na connection attempt finding out that the server wants a password. In some cases it is\nworth typing -W to avoid the extra connection attempt.\n\npgreceivewal can perform one of the two following actions in order to control physical\nreplication slots:\n",
                    "long": "--password"
                },
                {
                    "name": "--create-slot",
                    "content": "Create a new physical replication slot with the name specified in --slot, then exit.\n",
                    "long": "--create-slot"
                },
                {
                    "name": "--drop-slot",
                    "content": "Drop the replication slot with the name specified in --slot, then exit.\n\nOther options are also available:\n",
                    "long": "--drop-slot"
                },
                {
                    "name": "-V",
                    "content": "",
                    "flag": "-V"
                },
                {
                    "name": "--version",
                    "content": "Print the pgreceivewal version and exit.\n\n-?",
                    "long": "--version"
                },
                {
                    "name": "--help",
                    "content": "Show help about pgreceivewal command line arguments, and exit.\n",
                    "long": "--help"
                }
            ]
        },
        "EXIT STATUS": {
            "content": "pgreceivewal will exit with status 0 when terminated by the SIGINT signal. (That is the\nnormal way to end it. Hence it is not an error.) For fatal errors or other signals, the exit\nstatus will be nonzero.\n",
            "subsections": []
        },
        "ENVIRONMENT": {
            "content": "This utility, like most other PostgreSQL utilities, uses the environment variables supported\nby libpq (see Section 34.15).\n\nThe environment variable PGCOLOR specifies whether to use color in diagnostic messages.\nPossible values are always, auto and never.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "When using pgreceivewal instead of archivecommand as the main WAL backup method, it is\nstrongly recommended to use replication slots. Otherwise, the server is free to recycle or\nremove write-ahead log files before they are backed up, because it does not have any\ninformation, either from archivecommand or the replication slots, about how far the WAL\nstream has been archived. Note, however, that a replication slot will fill up the server's\ndisk space if the receiver does not keep up with fetching the WAL data.\n\npgreceivewal will preserve group permissions on the received WAL files if group permissions\nare enabled on the source cluster.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "To stream the write-ahead log from the server at mydbserver and store it in the local\ndirectory /usr/local/pgsql/archive:\n\n$ pgreceivewal -h mydbserver -D /usr/local/pgsql/archive\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "pgbasebackup(1)\n\n\n\nPostgreSQL 14.23                                2026                                PGRECEIVEWAL(1)",
            "subsections": []
        }
    },
    "summary": "pgreceivewal - stream write-ahead logs from a PostgreSQL server",
    "flags": [
        {
            "flag": "-D",
            "long": null,
            "arg": null,
            "description": "--directory=directory Directory to write the output to. This parameter is required."
        },
        {
            "flag": "-E",
            "long": null,
            "arg": null,
            "description": "--endpos=lsn Automatically stop replication and exit with normal exit status 0 when receiving reaches the specified LSN. If there is a record with LSN exactly equal to lsn, the record will be processed."
        },
        {
            "flag": "",
            "long": "--if-not-exists",
            "arg": null,
            "description": "Do not error out when --create-slot is specified and a slot with the specified name already exists."
        },
        {
            "flag": "-n",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--no-loop",
            "arg": null,
            "description": "Don't loop on connection errors. Instead, exit right away with an error."
        },
        {
            "flag": "",
            "long": "--no-sync",
            "arg": null,
            "description": "This option causes pgreceivewal to not force WAL data to be flushed to disk. This is faster, but means that a subsequent operating system crash can leave the WAL segments corrupt. Generally, this option is useful for testing but should not be used when doing WAL archiving on a production deployment. This option is incompatible with --synchronous."
        },
        {
            "flag": "-s",
            "long": null,
            "arg": null,
            "description": "--status-interval=interval Specifies the number of seconds between status packets sent back to the server. This allows for easier monitoring of the progress from server. A value of zero disables the periodic status updates completely, although an update will still be sent when requested by the server, to avoid timeout disconnect. The default value is 10 seconds."
        },
        {
            "flag": "-S",
            "long": null,
            "arg": null,
            "description": "--slot=slotname Require pgreceivewal to use an existing replication slot (see Section 27.2.6). When this option is used, pgreceivewal will report a flush position to the server, indicating when each segment has been synchronized to disk so that the server can remove that segment if it is not otherwise needed. When the replication client of pgreceivewal is configured on the server as a synchronous standby, then using a replication slot will report the flush position to the server, but only when a WAL file is closed. Therefore, that configuration will cause transactions on the primary to wait for a long time and effectively not work satisfactorily. The option --synchronous (see below) must be specified in addition to make this work correctly."
        },
        {
            "flag": "",
            "long": "--synchronous",
            "arg": null,
            "description": "Flush the WAL data to disk immediately after it has been received. Also send a status packet back to the server immediately after flushing, regardless of --status-interval. This option should be specified if the replication client of pgreceivewal is configured on the server as a synchronous standby, to ensure that timely feedback is sent to the server."
        },
        {
            "flag": "-v",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--verbose",
            "arg": null,
            "description": "Enables verbose mode."
        },
        {
            "flag": "-Z",
            "long": null,
            "arg": null,
            "description": "--compress=level Enables gzip compression of write-ahead logs, and specifies the compression level (0 through 9, 0 being no compression and 9 being best compression). The suffix .gz will automatically be added to all filenames. The following command-line options control the database connection parameters."
        },
        {
            "flag": "-d",
            "long": null,
            "arg": null,
            "description": "--dbname=connstr Specifies parameters used to connect to the server, as a connection string; these will override any conflicting command line options. The option is called --dbname for consistency with other client applications, but because pgreceivewal doesn't connect to any particular database in the cluster, database name in the connection string will be ignored."
        },
        {
            "flag": "-h",
            "long": null,
            "arg": null,
            "description": "--host=host Specifies the host name of the machine on which the server is running. If the value begins with a slash, it is used as the directory for the Unix domain socket. The default is taken from the PGHOST environment variable, if set, else a Unix domain socket connection is attempted."
        },
        {
            "flag": "-p",
            "long": null,
            "arg": null,
            "description": "--port=port Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the PGPORT environment variable, if set, or a compiled-in default."
        },
        {
            "flag": "-U",
            "long": null,
            "arg": null,
            "description": "--username=username User name to connect as."
        },
        {
            "flag": "-w",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--no-password",
            "arg": null,
            "description": "Never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a .pgpass file, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password."
        },
        {
            "flag": "-W",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--password",
            "arg": null,
            "description": "Force pgreceivewal to prompt for a password before connecting to a database. This option is never essential, since pgreceivewal will automatically prompt for a password if the server demands password authentication. However, pgreceivewal will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing -W to avoid the extra connection attempt. pgreceivewal can perform one of the two following actions in order to control physical replication slots:"
        },
        {
            "flag": "",
            "long": "--create-slot",
            "arg": null,
            "description": "Create a new physical replication slot with the name specified in --slot, then exit."
        },
        {
            "flag": "",
            "long": "--drop-slot",
            "arg": null,
            "description": "Drop the replication slot with the name specified in --slot, then exit. Other options are also available:"
        },
        {
            "flag": "-V",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--version",
            "arg": null,
            "description": "Print the pgreceivewal version and exit. -?"
        },
        {
            "flag": "",
            "long": "--help",
            "arg": null,
            "description": "Show help about pgreceivewal command line arguments, and exit."
        }
    ],
    "examples": [
        "To stream the write-ahead log from the server at mydbserver and store it in the local",
        "directory /usr/local/pgsql/archive:",
        "$ pgreceivewal -h mydbserver -D /usr/local/pgsql/archive"
    ],
    "see_also": [
        {
            "name": "pgbasebackup",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/pgbasebackup/1/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Stream the write-ahead log from a running PostgreSQL cluster.",
        "examples": [
            {
                "description": "Stream WAL to a local directory (minimum required)",
                "command": "pg_receivewal {{-D|--directory}} {{directory}}"
            },
            {
                "description": "Same as above, specify host, port, username including verbose output",
                "command": "pg_receivewal {{-v|--verbose}} {{-h|--host}} {{host}} {{-p|--port}} {{port}} {{-U|--username}} {{username}} {{-D|--directory}} {{directory}}"
            },
            {
                "description": "Use replication slot (create-if-needed)",
                "command": "pg_receivewal {{-S|--slot}} {{slot_name}} --create-slot {{-h|--host}} {{host}} {{-p|--port}} {{port}} {{-U|--username}} {{username}} {{-D|--directory}} {{directory}}"
            },
            {
                "description": "Stop at a given WAL position (LSN)",
                "command": "pg_receivewal {{-E|--endpos}} {{lsn}} {{-D|--directory}} {{directory}} {{-h|--host}} {{host}} {{-p|--port}} {{port}} {{-U|--username}} {{username}}"
            },
            {
                "description": "Control looping on failure",
                "command": "pg_receivewal {{-n|--no-loop}} {{-D|--directory}} {{directory}} {{-h|--host}} {{host}} {{-p|--port}} {{port}} {{-U|--username}} {{username}}"
            },
            {
                "description": "Flush data synchronously (force WAL writes immediately)",
                "command": "pg_receivewal --synchronous {{-D|--directory}} {{directory}} {{-h|--host}} {{host}} {{-p|--port}} {{port}} {{-U|--username}} {{username}}"
            },
            {
                "description": "Compress WAL output (`gzip`, level 0-9)",
                "command": "pg_receivewal {{-Z|--compress}} {{level|method}} {{-D|--directory}} {{directory}} {{-h|--host}} {{host}} {{-p|--port}} {{port}} {{-U|--username}} {{username}}"
            },
            {
                "description": "Set status reporting interval",
                "command": "pg_receivewal {{-s|--status-interval}} {{seconds}} {{-D|--directory}} {{directory}} {{-h|--host}} {{host}} {{-p|--port}} {{port}} {{-U|--username}} {{username}}"
            }
        ]
    }
}