PG_RECVLOGICAL(1)
π PG_RECVLOGICAL π
okay bestie, so you know how PostgreSQL can literally stream the changes happening in your database like it's a live feed? yeah. this is the little command-line icon that drives that. it's called pg_recvlogical and it lives in the PostgreSQL 18.6 Documentation, and no cap, it's lowkey the main character of logical decoding. π
β¨ NAME β¨
pg_recvlogical β control PostgreSQL logical decoding streams. that's it. that's the job. slay. π
πΈ SYNOPSIS πΈ
pg_recvlogical [option...]
like, you just hand it options. it does the rest. periodt. π¦
π DESCRIPTION π
so here's the tea. pg_recvlogical does two big things: it controls logical decoding replication slots, and it streams data out of those replication slots. both. at once. versatile queen. π
it makes a replication-mode connection, which means it's bound by the same rules as pg_receivewal(1), plus all the extra rules that come with logical replication (peep Chapter 47 if you wanna go deep, iykyk).
here's a thing you should know fr fr: pg_recvlogical has no equivalent to the logical decoding SQL interface's peek and get modes. instead, it sends replay confirmations for data lazily as it receives it, and also on clean exit. so if you just wanna look at what's pending on a slot without eating it? use pg_logical_slot_peek_changes. don't come for pg_recvlogical's plate. π
as long as no fatal errors show up, pg_recvlogical will literally just run until something kills it β specifically the SIGINT signal (that's Control+C for you and me π) or the SIGTERM signal.
and when pg_recvlogical catches a SIGHUP signal? it closes the current output file and opens a brand new one using the filename you gave it with the --file option. the way that works is iconic actually β you rename the current file first, then send the SIGHUP, and boom π₯: log rotation. chef's kiss. π
β¨ OPTIONS β¨
heads up bestie: you gotta give at least one of the action options below, or we're not going anywhere.
π the actions (pick at least one, okay?)
--create-slotβ makes a brand new logical replication slot. the name comes from--slot, the output plugin comes from--plugin, and the database comes from--dbname. for this action,--slotand--dbnameare required. you can also throw in--enable-two-phaseand--enable-failoverhere if you're feeling fancy. β¨--drop-slotβ yeets the replication slot named by--slot, then exits.--slotis required for this one. bye boo π--startβ begins streaming changes from the logical replication slot named by--slot, and keeps going until a signal ends it. if the server-side change stream ends because of a server shutdown or a disconnect, it'll retry in a loop β unless you passed--no-loop.--slot,--dbnameand--fileare all required for this action. the stream format? determined by whatever output plugin was used when the slot was created. and the connection must be to the same database that was used to create the slot. no switching up. π«
you can combine --create-slot and --start. but --drop-slot? that one cannot be combined with another action. it's a solo act. π€
π output location, format & other replication behavior
-E lsn,--endpos=lsnβ in--startmode, automatically stop replication and exit with normal exit status0once receiving reaches the specified LSN. if you specify this while not in--startmode, an error gets raised, sorry babe. if there's a record with an LSN exactly equal to lsn, that record will be output. β οΈ warning though:--endposis not aware of transaction boundaries and may truncate output partway through a transaction. any partially output transaction won't be consumed and will be replayed again the next time the slot is read from. individual messages, however, are never truncated.--enable-failoverβ enables the slot to be synchronized to the standbys. this option may only be specified with--create-slot.-f filename,--file=filenameβ writes received and decoded transaction data into this file. use-for stdout. this parameter is required for--start.-F interval_seconds,--fsync-interval=interval_secondsβ 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 you flush more often. setting an interval of0disables issuingfsync()calls altogether β while still reporting progress to the server. in that case, data could be lost in the event of a crash. π-I lsn,--startpos=lsnβ in--startmode, start replication from the given LSN. for details on what that actually does, check Chapter 47 and Section 54.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. be chill about it. π-n,--no-loopβ when the connection to the server is lost, don't retry in a loop, just exit. no dramatic comebacks.-o name[=value],--option=name[=value]β passes the option name to the output plugin, along with the option value if one is specified. which options exist and what they do depends entirely on the output plugin you're using. your plugin, your rules.-P plugin,--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. sorry, it's already got a personality.-s interval_seconds,--status-interval=interval_secondsβ same effect as the option of the same name inpg_receivewal(1). go read the description over there, bestie.-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. this parameter is required for any of actions.-t,--enable-two-phase,--two-phase(deprecated) β enables decoding of prepared transactions. this option may only be specified with--create-slot.-v,--verboseβ enables verbose mode. give us the details, we love details. π£οΈ
π database connection parameters
-d dbname,--dbname=dbnameβ the database to connect to. check the descriptions of the actions to see what this means in detail. dbname can be a connection string. if it is, connection string parameters will override any conflicting command line options. this parameter is required for--create-slotand--start.-h hostname-or-ip,--host=hostname-or-ipβ 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 comes from thePGHOSTenvironment variable if it's set β otherwise a Unix domain socket connection is attempted.-p port,--port=portβ the TCP port, or the local Unix domain socket file extension, that the server is listening on for connections. defaults to thePGPORTenvironment variable if set, or a compiled-in default.-U user,--username=userβ the 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 no password is available by other means β like a.pgpassfile β the connection attempt will fail. super useful in batch jobs and scripts where there's nobody around to type a password. π€-W,--passwordβ forcepg_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 auth. but here's the thing: without it,pg_recvlogicalwastes a whole connection attempt just finding out the server wants a password. sometimes it's worth typing-Wto skip that extra attempt. π
β the extra lil options
-V,--versionβ print thepg_recvlogicalversion and exit.-?,--helpβ show help aboutpg_recvlogicalcommand line arguments, and exit.
π¦ EXIT STATUS π¦
pg_recvlogical exits with status 0 when it's terminated by the SIGINT or SIGTERM signal. and bestie, that's the normal way to end it β so it is not an error, okay? don't feel bad. π
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. it's respectful like that. π«Ά
π EXAMPLES π
see Section 47.1 for an example.
π SEE ALSO π
and that's the whole vibe, bestie π go forth and decode logically. this was the pg_recvlogical page from PostgreSQL 18.6, dated 2026 β mwah, take care of her, she's iconic. πβ¨π¦
π¦ where this page comes from
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms