PG_RECVLOGICAL(1)
π NAME π
pg_recvlogical β the whole vibe is controlling PostgreSQL logical decoding streams β¨
π¦ SYNOPSIS π¦
pg_recvlogical [option...]
πΈ DESCRIPTION πΈ
okay so bestie, pg_recvlogical is literally the main character for controlling logical decoding replication slots and streaming the data out of those slots. iconic behavior only.
It opens a replication-mode connection, which means it's subject to the exact same constraints as pg_receivewal(1), plus the extra ones that come with logical replication (peep Chapter 47 for that lore).
ngl there's one thing pg_recvlogical does not have: it has zero equivalent to the logical decoding SQL interface's peek and get modes. It sends replay confirmations for data lazily as it receives it, and also on clean exit. So if you wanna examine pending data on a slot without consuming it, use pg_logical_slot_peek_changes instead β that's the girl for the job π
Assuming no fatal errors happen (fingers crossed π«Ά), pg_recvlogical will keep running until it gets terminated by the SIGINT (that's Control+C for you) or SIGTERM signal.
and the cutest part?? when pg_recvlogical catches a SIGHUP signal, it closes the current output file and opens a brand new one using the filename you specified with the --file option β¨ That's how we rotate the output file, babes: rename the current file first, then send SIGHUP to pg_recvlogical. rotation slay π
β¨ OPTIONS β¨
At least one of these has to be specified to pick an action β you literally cannot skip this part:
--create-slotβ makes a new logical replication slot with the name from--slot, using the output plugin from--plugin, for the database from--dbname. and ooh,--two-phasecan be specified together with--create-slotto enable decoding of prepared transactions π«Ά--drop-slotβ drops the replication slot named by--slot, then exits. bye bestie π--startβ begins streaming changes from the logical replication slot specified by--slot, and just keeps going until a signal terminates it. If the server side change stream ends because of a server shutdown or disconnect, it retries in a loop unless you passed--no-loop. The stream format is decided by the output plugin that was specified when the slot was created. and heads up: the connection must be to the same database that was used to create the slot π
--create-slot and --start can be specified together, cute. But --drop-slot β¨cannotβ¨ be combined with another action. periodt.
π options that control location, format & replication behavior π
-Elsn,--endpos=lsnβ in--startmode, this automatically stops replication and exits with normal exit status0when receiving reaches the specified LSN. If you specify it when you're not in--startmode, an error is raised. If there's a record with an LSN exactly equal to lsn, that record will be output. β οΈ important:--endposis 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 the next time the slot is read from. Individual messages are never truncated tho π-ffilename,--file=filenameβ writes received and decoded transaction data into this file. use-for stdout π-Finterval_seconds,--fsync-interval=interval_secondsβ says how oftenpg_recvlogicalshould issuefsync()calls to make sure the output file is safely flushed to disk. The server will occasionally ask the client to perform a flush and report the flush position back to the server β this setting is in addition to that, so flushes happen more frequently. Specifying an interval of0disables issuingfsync()calls altogether while still reporting progress to the server. β οΈ but in that case, data could be lost in the event of a crash. no cap.-Ilsn,--startpos=lsnβ in--startmode, start replication from the given LSN. for the deets on what that actually does, see the documentation in Chapter 47 and Section 53.4. ignored in other modes π--if-not-existsβ do not error out when--create-slotis specified and a slot with the specified name already exists. we love a low-stakes option β¨-n,--no-loopβ when the connection to the server is lost, do not retry in a loop, just exit. short and sweet π¦-oname[=value],--option=name[=value]β passes the option name to the output plugin, with the option value value if specified. which options exist and what they do depends on the output plugin you're using β iykyk π-Pplugin,--plugin=pluginβ when creating a slot, use the specified logical decoding output plugin. see Chapter 47. this option has no effect if the slot already exists π-sinterval_seconds,--status-interval=interval_secondsβ same effect as the option of the same name inpg_receivewal(1). see the description there π-Sslot_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 modes, main character energy π-t,--two-phaseβ enables decoding of prepared transactions. this option may only be specified with--create-slotπ«Ά-v,--verboseβ enables verbose mode. more words, more fun β¨
π options that control database connection parameters π
-ddbname,--dbname=dbnameβ the database to connect to. see the description of the actions for what this means in detail. dbname can be a connection string β if it is, connection string parameters will override any conflicting command line options. defaults to the user name πΈ-hhostname-or-ip,--host=hostname-or-ipβ specifies the host name of the machine the server is running on. if the value begins with a slash, it's used as the directory for the Unix domain socket. the default is taken from thePGHOSTenvironment variable if it's set, else a Unix domain socket connection is attempted π¦-pport,--port=portβ specifies the TCP port or local Unix domain socket file extension the server is listening on for connections. defaults to thePGPORTenvironment variable if set, or a compiled-in default π-Uuser,--username=userβ user name to connect as. defaults to the current operating system user name π-w,--no-passwordβ never issue a password prompt. if the server requires password authentication and a password isn't 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 π-W,--passwordβ forcespg_recvlogicalto prompt for a password before connecting to a database. this option is never essential, sincepg_recvlogicalwill automatically prompt for a password if the server demands password authentication. however,pg_recvlogicalwill waste a connection attempt finding out that the server wants a password. in some cases it's worth typing-Wto avoid the extra connection attempt π
β extra options, because why not β
-V,--versionβ print thepg_recvlogicalversion and exit π-?,--helpβ show help aboutpg_recvlogicalcommand line arguments, and exit π«Ά
π EXIT STATUS π
pg_recvlogical will exit with status 0 when terminated by the SIGINT or SIGTERM signal. (That's literally the normal way to end it, so it is not an error β don't panic bestie π) For fatal errors or other signals, the exit status will be nonzero π
π§ ENVIRONMENT π§
This utility, like most other PostgreSQL utilities, uses the environment variables supported by libpq (see Section 32.15) β¨
The environment variable PG_COLOR specifies whether to use color in diagnostic messages. possible values are always, auto and never π
π NOTES π
pg_recvlogical will preserve group permissions on the output files if group permissions are enabled on the source cluster π
π₯ EXAMPLES π₯
See Section 47.1 for an example π
π SEE ALSO π
and that's the whole page, bestie π«Ά this was PostgreSQL 17.11, dated 2026 β go stream some logical decoding and slay π
β¨π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-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