PG_RECVLOGICAL(1)

πŸ“¦ version 13.23, in opensuse-leap 16.0

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-loop is 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 --start mode, automatically stop replication and exit with normal exit status 0 when receiving reaches the specified LSN. If specified when not in --start mode, 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 often pg_recvlogical should issue fsync() 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 --start mode, 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-slot is 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 in pg_receivewal(1). See the description there. Go read that one, it's a whole thing. πŸ“–
  • -S slot_name, --slot=slot_name β€” In --start mode, use the existing logical replication slot named slot_name. In --create-slot mode, create the slot with this name. In --drop-slot mode, 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 the PGHOST environment 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 the PGPORT environment 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 .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. So like, no human, no prompt, no drama. πŸ€–
  • -W, --password β€” Force pg_recvlogical to 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 the pg_recvlogical version and exit. Flex the version. ⭐
  • -?, --help β€” Show help about pg_recvlogical command 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