>From 317d0f7bc73d904fdf58264ff5e39a43e57ea7df Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Wed, 5 Mar 2014 00:15:39 +0100 Subject: [PATCH 3/7] Documentation for logical decoding. Craig Ringer, Andres Freund, Christian Kruse --- doc/src/sgml/catalogs.sgml | 27 +- doc/src/sgml/filelist.sgml | 1 + doc/src/sgml/func.sgml | 102 +++++- doc/src/sgml/high-availability.sgml | 6 +- doc/src/sgml/logicaldecoding.sgml | 607 +++++++++++++++++++++++++++++++++++ doc/src/sgml/postgres.sgml | 1 + doc/src/sgml/protocol.sgml | 69 +++- doc/src/sgml/ref/allfiles.sgml | 1 + doc/src/sgml/ref/alter_table.sgml | 2 +- doc/src/sgml/ref/create_table.sgml | 15 +- doc/src/sgml/ref/pg_recvlogical.sgml | 305 ++++++++++++++++++ doc/src/sgml/reference.sgml | 1 + 12 files changed, 1120 insertions(+), 17 deletions(-) create mode 100644 doc/src/sgml/logicaldecoding.sgml create mode 100644 doc/src/sgml/ref/pg_recvlogical.sgml diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index 908f947..a12ee56 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -5177,7 +5177,7 @@ For more on replication slots, - see . + see and . @@ -5210,6 +5210,13 @@ + plugin + text + + The basename of the shared object containing the output plugin this logical slot is using, or null for physical slots. + + + datoid oid pg_database.oid @@ -5243,6 +5250,24 @@ + xmin + xid + + The oldest transaction that this slot needs the database to + retain. VACUUM cannot remove catalog tuples deleted + by any later transaction. + + + + + catalog_xmin + xid + + The xmin, or oldest transaction ID, that this + slot forces to be retained in the system catalogs. + + + restart_lsn pg_lsn diff --git a/doc/src/sgml/filelist.sgml b/doc/src/sgml/filelist.sgml index 0e863ee..6c8e254 100644 --- a/doc/src/sgml/filelist.sgml +++ b/doc/src/sgml/filelist.sgml @@ -91,6 +91,7 @@ + diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 080da43..0336de8 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -16377,8 +16377,9 @@ postgres=# SELECT * FROM pg_xlogfile_name_offset(pg_stop_backup()); PostgreSQL exposes a number of functions for controlling and interacting - with replication features. See - and . + with replication features. See , + + and . @@ -16437,9 +16438,106 @@ postgres=# SELECT * FROM pg_xlogfile_name_offset(pg_stop_backup()); command DROP_REPLICATION_SLOT. + + + + + pg_create_logical_replication_slot + + pg_create_logical_replication_slot(slotname name, plugin name) + + + (slotname name, xlog_position pg_lsn) + + + Creates a new logical (decoding) replication slot named + slotname using the output plugin + plugin. Output plugins are listed amongst the + extensions in pg_catalog.pg_available_extensions, + but there is no specific listing of only output plugins. Same as + walsender protocol command CREATE REPLICATION SLOT ... LOGICAL. + + + + + + + pg_logical_slot_get_changes + + pg_logical_slot_get_changes(slotname name, upto_lsn pg_lsn, upto_nchanges int, VARIADIC options text[]) + + + (location pg_lsn, xid xid, data text) + + + Returns changes in the slot slotname, starting + from the point at which since changes have been consumed last. Changes + are extracted upto the current end of the WAL, or if nonnull only if + their transactions have committed + before upto_lsn, or if nonnull + until upto_nchanges rows have been + collected. Note that the upto_nchanges limit is + only enforced everytime a transaction commits. Changes will not be + consumed. + + + + + + + pg_logical_slot_peek_changes + + pg_logical_slot_peek_changes(slotname name, upto_lsn pg_lsn, upto_nchanges int, VARIADIC options text[]) + + + (location text, xid xid, data text) + + + Behaves just like + the pg_logical_slot_get_changes() function, + except that changes are not consumed, i.e. will be returned again on + future calls. + + + + + + + pg_logical_slot_get_binary_changes + + pg_logical_slot_get_binary_changes(slotname name, upto_lsn pg_lsn, upto_nchanges int, VARIADIC options text[]) + + + (location pg_lsn, xid xid, data bytea) + + + Behaves just like + the pg_logical_slot_get_changes() function, + except that changes are returned as bytea. + + + + + + + pg_logical_slot_peek_binary_changes + + pg_logical_slot_peek_binary_changes(slotname name, upto_lsn pg_lsn, upto_nchanges int, VARIADIC options text[]) + + + (location pg_lsn, xid xid, data bytea) + + + Behaves just like + the pg_logical_slot_get_changes() function, + except that changes are returned as bytea and that + changes are not consumed, i.e. will be returned again on future calls. + +
+ diff --git a/doc/src/sgml/high-availability.sgml b/doc/src/sgml/high-availability.sgml index ecb51c4..deac2a7 100644 --- a/doc/src/sgml/high-availability.sgml +++ b/doc/src/sgml/high-availability.sgml @@ -888,12 +888,12 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass' In lieu of using replication slots, it is possible to prevent the removal - of old WAL segments using , or by + of old WAL segments using or by storing the segments in an archive using . However, these methods often result in retaining more WAL segments than - required, whereas replication slots retain only the number of segments - known to be needed. An advantage of these methods is that they bound + required whereas replication slots retain only the number of segments + known to be needed. An advantage of these methods is that they are bound the space requirement for pg_xlog; there is currently no way to do this using replication slots. diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml new file mode 100644 index 0000000..f4d5910 --- /dev/null +++ b/doc/src/sgml/logicaldecoding.sgml @@ -0,0 +1,607 @@ + + + Logical Decoding + + Logical Decoding + + + Logical Replication + + + Changeset Extraction + + + PostgreSQL provides infrastructure to stream the modifications performed + via SQL to external consumers which can be used to implement replication + solutions, perform auditing, and similar tasks. + + + + Changes are sent out in streams where each stream outputs each change + exactly once. On the sender's side, each changestream is identified by a so + called logical replication slot. + + + + The format in which those changes are streamed is determined by the output + plugin used. While an example plugin is provided, additional plugins can be + written to extend the choice of available formats without modifying any + core code. + Every output plugin has access to each individual new row produced + by INSERT, and the new row version created + by UPDATE. Which data is available for rows affected + by DELETE and for the old row version in + an UPDATE depends on the relation's + configured REPLICA + IDENTITY. + + + + Changes can be consumed either using the streaming replication protocol + (see and + ), or by calling functions + via SQL (see ). It is also possible + to write additional methods of consuming the output of a replication slot + without modifying core code + (see ). + + + + Logical Decoding Example + + The following example shows usage of the SQL interface. + + + Before you can use logical decoding + postgresql.conf must be changed to ensure the following + parameters are set to at least: + +wal_level = logical +max_replication_slots = 1 +max_wal_senders = 1 + + Then connect to the target database (in the example + below, postgres) as a superuser. + + +postgres=# -- max_replication_slots must be nonzero and wal_level must be logical +postgres=# SHOW max_replication_slots; + max_replication_slots +----------------------- + 1 +(1 row) + +postgres=# SHOW wal_level; + wal_level +----------- + logical +(1 row) + +postgres=# SELECT * FROM pg_replication_slots; + slot_name | plugin | slot_type | datoid | database | active | xmin | catalog_xmin | restart_lsn +-----------+--------+-----------+--------+----------+--------+------+--------------+------------- +(0 rows) + +postgres=# -- Create a slot named 'regression_slot' using the output plugin 'test_decoding' +postgres=# SELECT * FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); + slotname | xlog_position +-----------------+--------------- + regression_slot | 0/16B1970 +(1 row) + +postgres=# SELECT * FROM pg_replication_slots; + slot_name | plugin | slot_type | datoid | database | active | xmin | catalog_xmin | restart_lsn +-----------------+---------------+-----------+--------+----------+--------+--------+--------------+------------- + regression_slot | test_decoding | logical | 12052 | postgres | f | | 684 | 0/16A4408 +(1 row) + +postgres=# -- There are no changes to see yet +postgres=# SELECT * FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL); + location | xid | data +----------+-----+------ +(0 rows) + +postgres=# CREATE TABLE data(id serial primary key, data text); +CREATE TABLE + +postgres=# -- DDL isn't replicated, so all you'll see is the transaction +postgres=# SELECT * FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL); + location | xid | data +-----------+-----+------------ + 0/16D5D48 | 688 | BEGIN 688 + 0/16E0380 | 688 | COMMIT 688 +(2 rows) + +postgres=# -- Once changes are read, they're consumed and not emitted +postgres=# -- in a subsequent call: +postgres=# SELECT * FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL); + location | xid | data +----------+-----+------ +(0 rows) + +postgres=# BEGIN; +postgres=# INSERT INTO data(data) VALUES('1'); +postgres=# INSERT INTO data(data) VALUES('2'); +postgres=# COMMIT; + +postgres=# SELECT * FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL); + location | xid | data +-----------+-----+----------------------------------------------- + 0/16E0478 | 689 | BEGIN 689 + 0/16E0478 | 689 | table public.data: INSERT: id[int4]:1 data[text]:'1' + 0/16E0580 | 689 | table public.data: INSERT: id[int4]:2 data[text]:'2' + 0/16E0650 | 689 | COMMIT 689 +(4 rows) + +postgres=# INSERT INTO data(data) VALUES('3'); + +postgres=# -- You can also peek ahead in the change stream without consuming changes +postgres=# SELECT * FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL); + location | xid | data +-----------+-----+----------------------------------------------- + 0/16E09C0 | 690 | BEGIN 690 + 0/16E09C0 | 690 | table public.data: INSERT: id[int4]:3 data[text]:'3' + 0/16E0B90 | 690 | COMMIT 690 +(3 rows) + +postgres=# -- You can also peek ahead in the change stream without consuming changes +postgres=# SELECT * FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL); + location | xid | data +-----------+-----+----------------------------------------------- + 0/16E09C0 | 690 | BEGIN 690 + 0/16E09C0 | 690 | table public.data: INSERT: id[int4]:3 data[text]:'3' + 0/16E0B90 | 690 | COMMIT 690 +(3 rows) + +postgres=# -- options can be passed to output plugin, to influence the formatting +postgres=# SELECT * FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'include-timestamp', 'on'); + location | xid | data +-----------+-----+----------------------------------------------- + 0/16E09C0 | 690 | BEGIN 690 + 0/16E09C0 | 690 | table public.data: INSERT: id[int4]:3 data[text]:'3' + 0/16E0B90 | 690 | COMMIT 690 (at 2014-02-27 16:41:51.863092+01) +(3 rows) + +postgres=# -- Remember to destroy a slot you no longer need to stop it consuming +postgres=# -- server resources: +postgres=# SELECT pg_drop_replication_slot('regression_slot'); + pg_drop_replication_slot +----------------------- + +(1 row) + + + The following example shows usage of the walsender interface using + the pg_recvlogical + shell command. It requires the replication configurations to be allowed + (see ) + and max_wal_senders to be set sufficiently high for + another connection. + + +# pg_recvlogical -d testdb --slot test --create +# pg_recvlogical -d testdb --slot test --start -f - +CTRL-Z +# psql -c "INSERT INTO data(data) VALUES('4');" +# fg +BEGIN 693 +table public.data: INSERT: id[int4]:4 data[text]:'4' +COMMIT 693 +CTRL-C +# pg_recvlogical -d testdb --slot test --drop + + + + Logical Decoding Concepts + + + Logical Decoding + + Logical Decoding + + Logical decoding is the the process of extracting all persistent changes + to a database's tables into a coherent, easy to understand format which + can be interpreted without detailed knowledge of the database's internal + state. + + + In PostgreSQL logical decoding is implemented + by decoding the WAL's contents, which describe + changes on a storage level, into an application-specific form such as a + stream of tuples or SQL statements. + + + + + + Logical Replication Slot + + + Replication Slot + + Replication Slots + + In the context of logical replication a slot represents a stream of + changes which can be replayed to a client in the order they were made on + the origin server. Each slot streams a sequence of changes from a single + database, sending each change exactly once (unless peeking forward in the + stream). + + + PostgreSQL also has streaming replication slots + (see ), but they are used somewhat + differently there. + + + + Replication slots have an identifier which is unique across all databases + in a PostgreSQL cluster. Slots persist + independently of the connection using them and are crash-safe. They can + be allocated in primary servers and hot-standby servers (streaming + replicas or archive-replaying hot standbys), so it's possible to + replicate changes over physical replication and read a logical change + stream from that physical replica server. + + + Multiple independent slots may exist for a single database. Each slot has + its own state, allowing different consumers to receive changes from + different points in the database change stream. For most applications a + separate slot is required for each consumer. + + + A logical replication slot knows nothing about the state of the + receiver(s). It's even possible to have multiple different receivers using + the same slot at different times; they'll just get the changes following + on from when the last receiver stopped consuming them. Only one receiver + may consume changes from a slot at any given time. + + + + Replication slots persist across crashes and know nothing about the state of + their consumer(s). They will prevent removal of required resources even + when there is no connection using them. This consumes storage because + neither required WAL nor required rows from the system catalogs can be + removed by VACUUM as long as they are required by a replication slot, so + if a slot is no longer required it should be dropped. + + + Slots may be created manually, or using a client like a replication + tool. Keep this in mind when you retire a client that uses a replication + slot, like a logical replica - you may need to give it a specific + command to remove its replication slot, or drop the slot yourself, even + if you did not initially create the slot by hand. + + + + + Output Plugins + + Output plugins transform the data from postgres' internal representation + into the format the consumer of a replication slot desires. Additional + output plugins can be written without modifying core postgres code. + + + + Exported Snapshots + + When a new replication slot is created over the walsender interface a + snapshot is exported + (see ) which will show + exactly the state of the database after which all changes will be + included in the changestream. This can be used to create a new replica by + using SET TRANSACTION + SNAPSHOT to read the state of the database at the moment + the slot was created. This transaction can then be used to dump the + database's state at that point in time which afterwards can be updated + using the slot's contents without loosing any changes. + + + + + Streaming Replication Protocol Interface + + The CREATE_REPLICATION_SLOT SLOT slotname LOGICAL + options, DROP_REPLICATION_SLOT SLOT slotname + and START_REPLICATION SLOT slotname LOGICAL options + commands can be used to create, drop and stream changes from a replication + slot respectively. These commands are only available over a replication + connection; they won't work on the SQL + level. See . + + + The pg_recvlogical command + (see ) can be used to control logical + decoding over a walsender connection. + + + + Logical Decoding <acronym>SQL</acronym> Interface + + See for detailed documentation on + the SQL-level API for interacting with logical decoding. + + + Synchronous replication (see ) is + only supported on replication slots used over the walsender interface. The + function interface and additional, non-core interfaces do not support + synchronous replication. + + + + System catalogs related to logical decoding + + The pg_replication_slots + view and the + pg_stat_replication + view provide information about the current state of replication slots and + walsender connections respectively. These views apply to both physical and + logical replication. + + + + Logical Decoding Output Plugins + + An example output plugin can be found in the + + contrib/test_decoding + + subdirectory of the PostgreSQL source tree. + + + Initialization Function + + _PG_output_plugin_init + + + An output plugin is loaded by dynamically loading a shared library with + the output plugin's name as the library basename. The normal library + search path is used to locate the library. To provide the required output + plugin callbacks and to indicate that the library is actually an output + plugin it needs to provide a function named + _PG_output_plugin_init. This function is passed a + struct that needs to be filled with the callback function pointers for + individual actions. + +typedef struct OutputPluginCallbacks +{ + LogicalDecodeStartupCB startup_cb; + LogicalDecodeBeginCB begin_cb; + LogicalDecodeChangeCB change_cb; + LogicalDecodeCommitCB commit_cb; + LogicalDecodeShutdownCB shutdown_cb; +} OutputPluginCallbacks; +typedef void (*LogicalOutputPluginInit)(struct OutputPluginCallbacks *cb); + + The begin_cb, change_cb + and commit_cb callbacks are required, + while startup_cb + and shutdown_cb are optional. + + + + + Capabilities + + To decode, format and output changes, output plugins can use most of the + backend's normal infrastructure, including calling output functions. Read + only access to relations is permitted as long as only relations are + accessed that either have been created by initdb in + the pg_catalog schema, or have are marked as user + provided catalog tables using + +ALTER TABLE user_catalog_table SET (user_catalog_table = true); +CREATE TABLE another_catalog_table(data text) WITH (user_catalog_table = true); + + Any actions leading to xid assignment are prohibited. That, among others, + includes writing to tables, performing DDL changes and + calling txid_current(). + + + + + Output Plugin Callbacks + + An output plugin gets notified about changes that are happening via + various callbacks it needs to provide. + + + Concurrent transactions are decoded in commit order and only changes + belonging to a specific transaction are decoded inbetween + the begin and commit + callbacks. Transactions that were rolled back explicitly or implicitly + never get + decoded. Successfull SAVEPOINTs are + folded into the transaction containing them in the order they were + exectuded within that transaction. + + + + Only transactions that have already safely been flushed to disk will be + decoded. That can lead to a COMMIT not immediately being decoded in a + directly following pg_logical_slot_get_changes() + when synchronous_commit is set + to off. + + + + Startup Callback + + The optional startup_cb callback is called whenever + an replication slot is created or asked to stream changes, independent + of the number of changes that are ready to be put out. + +typedef void (*LogicalDecodeStartupCB) ( + struct LogicalDecodingContext *ctx, + OutputPluginOptions *options, + bool is_init +); + + The is_init paramter will be true when the + replication slot is being created and false + otherwise. options points to a struct of options + that output plugins can set: + +typedef struct OutputPluginOptions +{ + OutputPluginOutputType output_type; +} OutputPluginOptions; + + output_type has to either be set to + OUTPUT_PLUGIN_TEXTUAL_OUTPUT + or OUTPUT_PLUGIN_BINARY_OUTPUT. + + + The startup callback should validate the options present in + ctx->output_plugin_options. If the output plugin + needs to have a state, it can + use ctx->output_plugin_private to store it. + + + + Shutdown Callback + + The optional shutdown_cb callback is called + whenever a formerly active replication slot is not used anymore and can + be used to deallocate resources private to the output plugin. The slot + isn't necessarily being dropped, streaming is just being stopped. + +typedef void (*LogicalDecodeShutdownCB) ( + struct LogicalDecodingContext *ctx +); + + + + + Transaction Begin Callback + + The required begin_cb callback is called whenever a + start of a commited transaction has been decoded. Aborted transactions + and their contents never get decoded. + +typedef void (*LogicalDecodeBeginCB) ( + struct LogicalDecodingContext *, + ReorderBufferTXN *txn +); + + The txn parameter contains meta information about + the transaction, like the timestamp at which it has been committed and + its XID. + + + + Transaction End Callback + + The required commit_cb callback is called whenever + a transaction commit has been + decoded. The change_cb callbacks for all modified + rows will have been called before this, if there have been any modified + rows. + +typedef void (*LogicalDecodeCommitCB) ( + struct LogicalDecodingContext *, + ReorderBufferTXN *txn +); + + + + + Callback called for each individual change in a + transaction + + The required change_cb callback is called for every + individual row modification inside a transaction, may it be + an INSERT, UPDATE + or DELETE. Even if the original command modified + several rows at once the callback will be called indvidually for each + row. + +typedef void (*LogicalDecodeChangeCB) ( + struct LogicalDecodingContext *ctx, + ReorderBufferTXN *txn, + Relation relation, + ReorderBufferChange *change +); + + The ctx and txn parameters + have the same contents as for the begin_cb + and commit_cb callbacks, but additionally the + relation descriptor relation points to the + relation the row belongs to and a struct + change describing the row modification are passed + in. + + + + Only changes in user defined tables that are not unlogged + (see ) and not temporary + (see ) can be extracted using + logical decoding. + + + + + + Functions for producing output from an output plugin + + To actually produce output, output plugins can write data to + the StringInfo output buffer + in ctx->out when inside + the begin_cb, commit_cb + or change_cb callbacks. Before writing to the output + buffer OutputPluginPrepareWrite(ctx, last_write) has + to be called, and after finishing writing to the + buffer OutputPluginWrite(ctx, last_write) has to be + called to perform the write. The last_write + indicates whether a particular write was the callback's last write. + + + The following example shows how to output data to the consumer of an + output plugin: + +OutputPluginPrepareWrite(ctx, true); +appendStringInfo(ctx->out, "BEGIN %u", txn->xid); +OutputPluginWrite(ctx, true); + + + + + + Logical Decoding Output Writers + + It is possible to add more output methods in addition to the SQL and + replication protocol variants for consuming logical replication data. For + details look at the implementation of the SQL interface functions + in src/backend/replication/logical/logicalfuncs.c. + Essentially three functions need to be provided, one to read WAL, one to + prepare writing output, and one to write the output + (see ). + + + + Synchronous replication support for Logical Decoding + + The Logical Decoding support in PostgreSQL may + be used to to build synchronous + replication solutions with the same user interface as synchronous + replication for streaming + replication if the walsender interface + (see ) is used to stream out + data. Clients have to send Standby status update (F) + (see ) messages, just like streaming + replication clients do. + + + + A synchronous replica receiving changes via logical decoding will work in + the scope of a single database. Since, in contrast to + that, synchronous_standby_names currently is + server wide, this means that if more than one database in a cluster + require the use of synchronous replication it won't work properly if a + replica using logical replication is contained + in synchronous_standby_names. Essentially using a + logical replica as a synchronous replica requires that only one database + in a cluster is actively used. + + + + diff --git a/doc/src/sgml/postgres.sgml b/doc/src/sgml/postgres.sgml index b47bf52..9bde108 100644 --- a/doc/src/sgml/postgres.sgml +++ b/doc/src/sgml/postgres.sgml @@ -219,6 +219,7 @@ &spi; &bgworker; + &logicaldecoding; diff --git a/doc/src/sgml/protocol.sgml b/doc/src/sgml/protocol.sgml index cb2dfb2..b13304a 100644 --- a/doc/src/sgml/protocol.sgml +++ b/doc/src/sgml/protocol.sgml @@ -1309,16 +1309,30 @@ the simple query protocol can be used in walsender mode. Passing database as the value instructs walsender to connect to the database specified in the dbname parameter, which will allow the connection to be used for logical replication from that database. + + + For the purpose of testing replication commands, you can make a replication + connection via psql or any other libpq-using + tool with a connection string including the replication option, + e.g.: + + psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;" + + However it is often more useful to use + pg_receivexlog (for physical replication) or + pg_recvlogical (for logical replication). + + The commands accepted in walsender mode are: - IDENTIFY_SYSTEM - Requests the server to identify itself. Server replies with a result - set of a single row, containing four fields: + Requests the server to identify itself. Does not require a database name + to be specified for the connection. Server replies with a result set of a + single row, containing four fields: @@ -1381,7 +1395,8 @@ The commands accepted in walsender mode are: Requests the server to send over the timeline history file for timeline - tli. Server replies with a + tli. Does not require a database + name to be specified for the connection. Server replies with a result set of a single row, containing two fields: @@ -1764,17 +1779,55 @@ The commands accepted in walsender mode are: + + START_REPLICATION SLOT slotname LOGICAL XXX/XXX + + + Instructs server to start streaming WAL for logical replication, starting + at WAL position XXX/XXX. The server can + reply with an error, e.g. if the requested section of WAL has already + been recycled. On success, server responds with a CopyBothResponse + message, and then starts to stream WAL to the frontend. + + + The output plugin associated with the selected slot is used + to process the output for streaming. + + + + SLOT slotname + + + The name of the slot to stream changes from. This parameter is required, + and must correspond to an existing logical replication slot created + with CREATE_REPLICATION_SLOT in + LOGICAL mode. + + + + + XXX/XXX + + + The WAL position to begin streaming at. + + + + + + - DROP_REPLICATION_SLOT slotname + DROP_REPLICATION_SLOT SLOT slotname - Drops a replication slot, freeing any reserved server-side resources. If - the slot is currently in use by an active connection, this command fails. + Drops a physical or logical replication slot, freeing any reserved server-side + resources. If the slot is currently in use by an active connection this command + fails. - slotname + SLOT slotname The name of the slot to drop. diff --git a/doc/src/sgml/ref/allfiles.sgml b/doc/src/sgml/ref/allfiles.sgml index ce7a5e3..1b0962c 100644 --- a/doc/src/sgml/ref/allfiles.sgml +++ b/doc/src/sgml/ref/allfiles.sgml @@ -183,6 +183,7 @@ Complete list of usable sgml source files in this directory. + diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml index 2b02e66..4847d66 100644 --- a/doc/src/sgml/ref/alter_table.sgml +++ b/doc/src/sgml/ref/alter_table.sgml @@ -580,7 +580,7 @@ ALTER TABLE [ IF EXISTS ] name - + REPLICA IDENTITY diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml index fc7ad09..2a985b8 100644 --- a/doc/src/sgml/ref/create_table.sgml +++ b/doc/src/sgml/ref/create_table.sgml @@ -137,7 +137,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI - + TEMPORARY or TEMP @@ -171,7 +171,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI - + UNLOGGED @@ -1051,6 +1051,17 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI + + user_catalog_table (boolean) + + + Declare a table as an additional catalog table, e.g. for the purpose of + logical replication. See + for details. + + + + diff --git a/doc/src/sgml/ref/pg_recvlogical.sgml b/doc/src/sgml/ref/pg_recvlogical.sgml new file mode 100644 index 0000000..df22bba --- /dev/null +++ b/doc/src/sgml/ref/pg_recvlogical.sgml @@ -0,0 +1,305 @@ + + + + + pg_recvlogical + 1 + Application + + + + pg_recvlogical + Control logical decoding (see ) + streams over a walsender connection. + + + + pg_recvlogical + + + + + pg_recvlogical + + + + + + Description + + pg_recvlogical controls logical decoding replication + slots and streams data from such replication slots. + + + It creates a replication-mode connection, so it is subject to the same + constraints as pg_receivexlog, + plus those for logical replication (see ). + + + + + + Options + + + pg_recvlogical runs in one of three modes, which + control its primary action: + + + + + + + + Create a new logical replication slot with the name specified in + , using the output plugin + , then exit. The slot is created for the + database given in . + + + + + + + + + Begin streaming changes from the logical replication slot with the name + specified in , continuing until terminated with a + signal. If the server side change stream ends with a server + shutdown / disconnect, retry in a loop unless + is specified. The stream format is determined by the output plugin + specified when the slot was created. + + + You must connect to the same as the slot was + created with to stream changes from a logical replication slot. + + + + + + + + + Drop the replication slot with the name specified + in , then exit. + + + + + + + + + pg_recvlogical supports all the usual + libpq-based options. These are explained in detail in + the documentation for + psql and for + libpq. + + + + + + + + + Username to connect as. Must have a suitable pg_hba.conf + entry allowing replication connections. Defaults to + current operating system user name. + + + + + + + + + + The database to connect to in replication mode; see + mode descriptions for details. May be + a libpq connstring + instead. Defaults to user name. + + + + + + + + + + Host or socket to connect + to. See psql + and libpq + documentation. + + + + + + + + + + Port number to connect to. See + psql + for an explanation of default port choices when this is not + specified. + + + + + + + + + + Prevent prompting for a password. Will exit with an error code if a + password is required but not available. + + + + + + + + + + Provide a password for this connection. Please use the pgservice file + (see ) or an environment variable + instead of this option. + + + + + + + + + + The following command-line options control the location and format of the + output and other replication behaviour: + + + + + + + + + Write received and decoded transaction data into this + file. Use - for stdout. + + + + + + + + + + + When the connection to the server is lost, do not retry in a loop, just exit. + + + + + + + + + + When creating a slot, use the logical decoding output + plugin. See . This option has no + effect if the slot already exists. + + + + + + + + + + This option has the same effect as the option of the same name in pg_receivexlog. + See the description there. + + + + + + + + + + In mode, use the existing logical replication slot named + slot_name. In mode, create the + slot with this name. In mode, delete the slot with this name. + + + + + + + + + + In mode, start replication from the given + LSN. For details on the effect of this, see the documentation + in + and . Ignored in other modes. + + + + + + + + + + The following additional options are available: + + + + + + + + + Output verbose (detailed) error messages suitable for debugging and fault diagnosis. + + + + + + + + + + Print the pg_recvlogical version and exit. + + + + + + + + + + Show help about pg_recvlogical command line + arguments, and exit. + + + + + + + + diff --git a/doc/src/sgml/reference.sgml b/doc/src/sgml/reference.sgml index 87e8e9e..a6575f5 100644 --- a/doc/src/sgml/reference.sgml +++ b/doc/src/sgml/reference.sgml @@ -231,6 +231,7 @@ &pgDumpall; &pgIsready; &pgReceivexlog; + &pgRecvlogical; &pgRestore; &psqlRef; &reindexdb; -- 1.8.5.rc2.dirty