PG_RECVLOGICAL(1)
Okay bestie, gather round π«Ά β this is the manual page for pg_recvlogical, aka the PG_RECVLOGICAL(1) page from the PostgreSQL 13.23 documentation. It's lowkey iconic for anyone doing logical decoding, so let's get into it. β¨
πΈ NAME πΈ
pg_recvlogical β control PostgreSQL logical decoding streams. That's the whole vibe. π
π¦ SYNOPSIS π¦
pg_recvlogical [option...]
β¨ DESCRIPTION β¨
Okay so pg_recvlogical is your main character for controlling logical decoding replication slots and streaming data from those slots. It's giving backend bestie energy. π
It creates a replication-mode connection, which means it's subject to the same constraints as pg_receivewal(1), plus the constraints for logical replication (see Chapter 48). No cap.
Here's a thing to know: pg_recvlogical has no equivalent to the logical decoding SQL interface's peek and get modes. It sends replay confirmations for data lazily as it receives it and on clean exit. So if you wanna examine pending data on a slot without consuming it, use pg_logical_slot_peek_changes. Periodt. π
When pg_recvlogical receives a SIGHUP signal, it closes the current output file and opens a new one using the filename specified by the --file option. The way that works is: you rename the current file first, then send a SIGHUP signal to pg_recvlogical, and boom π₯ β output file rotation. Iconic.
π OPTIONS π
At least one of the following options must be specified to select an action. Don't skip this part, bestie. π
π Action Options π
--create-slotβ Create a new logical replication slot with the name specified by--slot, using the output plugin specified by--plugin, for the database specified by--dbname. Slay.--drop-slotβ Drop the replication slot with the name specified by--slot, then exit. Bye bestie π.--startβ Begin streaming changes from the logical replication slot specified by--slot, continuing until terminated by a signal. If the server side change stream ends with a server shutdown or disconnect, retry in a loop unless--no-loopis specified.
The stream format is determined by the output plugin specified when the slot was created. (So like, the plugin chose the vibe at slot-creation time, and now you're living in it. π«)
The connection must be to the same database used to create the slot. No switching up on me. π
--create-slot and --start can be specified together. --drop-slot cannot be combined with another action. That's the rule, fr fr.
The following command-line options control the location and format of the output and other replication behavior:
πΎ Output and Replication Behavior πΎ
-E lsn,--endpos=lsnβ In--startmode, automatically stop replication and exit with normal exit status0when receiving reaches the specified LSN. If specified when not in--startmode, an error is raised. π¨
If there's a record with LSN exactly equal to lsn, the record will be output. (So yes, exactly equal counts. Inclusive vibes. π )
Heads up bestie: the --endpos option is not aware of transaction boundaries and may truncate output partway through a transaction. Any partially output transaction will not be consumed and will be replayed again when the slot is next read from. Individual messages are never truncated. So like, messages are safe, transactions can get cut mid-sentence. π
-f filename,--file=filenameβ Write received and decoded transaction data into this file. Use-for stdout. Simple as that. π-F interval_seconds,--fsync-interval=interval_secondsβ Specifies how oftenpg_recvlogicalshould issuefsync()calls to ensure the output file is safely flushed to disk.
The server will occasionally request the client to perform a flush and report the flush position to the server. This setting is in addition to that, to perform flushes more frequently. So it's like extra credit flushing. β¨
Specifying an interval of 0 disables issuing fsync() calls altogether, while still reporting progress to the server. In this case, data could be lost in the event of a crash. Not me telling you to be careful β but be careful. π
-I lsn,--startpos=lsnβ In--startmode, start replication from the given LSN. For details on the effect of this, see the documentation in Chapter 48 and Section 52.4. Ignored in other modes. So if you're not in--start, it's literally ignored. π--if-not-existsβ Do not error out when--create-slotis specified and a slot with the specified name already exists. Chill mode activated. π-n,--no-loopβ When the connection to the server is lost, do not retry in a loop, just exit. No dramatic comeback tour. π-o name[=value],--option=name[=value]β Pass the option name to the output plugin with, if specified, the option value value. Which options exist and their effects depends on the used output plugin. So like, plugin-dependent, iykyk. π§-P plugin,--plugin=pluginβ When creating a slot, use the specified logical decoding output plugin. See Chapter 48. This option has no effect if the slot already exists. So it's a create-time thing only, bestie. π-s interval_seconds,--status-interval=interval_secondsβ This option has the same effect as the option of the same name inpg_receivewal(1). See the description there. Go read that one, it's a whole thing. π-S slot_name,--slot=slot_nameβ In--startmode, use the existing logical replication slot named slot_name. In--create-slotmode, create the slot with this name. In--drop-slotmode, delete the slot with this name. One option, three moods. π-v,--verboseβ Enables verbose mode. Tell me everything. π£οΈ
The following command-line options control the database connection parameters.
π Database Connection Options π
-d dbname,--dbname=dbnameβ The database to connect to. See the description of the actions for what this means in detail. The dbname can be a connection string. If so, connection string parameters will override any conflicting command line options. Defaults to the user name. So like, connection string wins if there's a fight. π₯-h hostname-or-ip,--host=hostname-or-ipβ 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 thePGHOSTenvironment variable, if set, else a Unix domain socket connection is attempted. Very demure, very mindful. π-p port,--port=portβ Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to thePGPORTenvironment variable, if set, or a compiled-in default. πͺ-U user,--username=userβ User name to connect as. Defaults to current operating system user name. Hi, it's me, your OS user. π-w,--no-passwordβ Never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a.pgpassfile, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password. So like, no human, no prompt, no drama. π€-W,--passwordβ Forcepg_recvlogicalto prompt for a password before connecting to a database.
This option is never essential, since pg_recvlogical will automatically prompt for a password if the server demands password authentication. However, pg_recvlogical 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. So it's like skipping the awkward "do you want a password?" round trip. π
The following additional options are available:
π Additional Options π
-V,--versionβ Print thepg_recvlogicalversion and exit. Flex the version. β-?,--helpβ Show help aboutpg_recvlogicalcommand line arguments, and exit. Help is here, bestie. π«Ά
π± ENVIRONMENT π±
This utility, like most other PostgreSQL utilities, uses the environment variables supported by libpq (see Section 33.14). So like, the usual libpq env var squad. π
The environment variable PG_COLOR specifies whether to use color in diagnostic messages. Possible values are always, auto and never. Pick your vibe: always colorful, auto colorful, or never colorful. π
π NOTES π
pg_recvlogical will preserve group permissions on the received WAL files if group permissions are enabled on the source cluster. So like, group perms are respected, no cap. π«‘
π EXAMPLES π
See Section 48.1 for an example. That's where the example lives, bestie. Go look. π
π SEE ALSO π
pg_receivewal(1) β your other replication bestie. π
And that's the tea β β this page is from the PostgreSQL 13.23 documentation, dated 2025. Mwah π, go stream some logical decoding responsibly. π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms