Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3f811c2

Browse files
committed
Add confirmed_flush column to pg_replication_slots.
There's no reason not to expose both restart_lsn and confirmed_flush since they have rather distinct meanings. The former is the oldest WAL still required and valid for both physical and logical slots, whereas the latter is the location up to which a logical slot's consumer has confirmed receiving data. Most of the time a slot will require older WAL (i.e. restart_lsn) than the confirmed position (i.e. confirmed_flush_lsn). Author: Marko Tiikkaja, editorialized by me Discussion: 559D110B.1020109@joh.to
1 parent 5c4b25a commit 3f811c2

File tree

9 files changed

+35
-15
lines changed

9 files changed

+35
-15
lines changed

contrib/test_decoding/expected/ddl.out

+2-2
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ SELECT pg_drop_replication_slot('regression_slot');
673673

674674
/* check that the slot is gone */
675675
SELECT * FROM pg_replication_slots;
676-
slot_name | plugin | slot_type | datoid | database | active | active_pid | xmin | catalog_xmin | restart_lsn
677-
-----------+--------+-----------+--------+----------+--------+------------+------+--------------+-------------
676+
slot_name | plugin | slot_type | datoid | database | active | active_pid | xmin | catalog_xmin | restart_lsn | confirmed_flush_lsn
677+
-----------+--------+-----------+--------+----------+--------+------------+------+--------------+-------------+---------------------
678678
(0 rows)
679679

doc/src/sgml/catalogs.sgml

+11
Original file line numberDiff line numberDiff line change
@@ -5577,6 +5577,17 @@
55775577
automatically removed during checkpoints.
55785578
</entry>
55795579
</row>
5580+
5581+
<row>
5582+
<entry><structfield>confirmed_flush</structfield></entry>
5583+
<entry><type>pg_lsn</type></entry>
5584+
<entry></entry>
5585+
<entry>The address (<literal>LSN</literal>) up to which the logical
5586+
slot's consumer has confirmed receiving data. Data older than this is
5587+
not available anymore. <literal>NULL</> for physical slots.
5588+
</entry>
5589+
</row>
5590+
55805591
</tbody>
55815592
</tgroup>
55825593
</table>

doc/src/sgml/high-availability.sgml

+3-3
Original file line numberDiff line numberDiff line change
@@ -934,9 +934,9 @@ postgres=# SELECT * FROM pg_create_physical_replication_slot('node_a_slot');
934934
node_a_slot |
935935

936936
postgres=# SELECT * FROM pg_replication_slots;
937-
slot_name | slot_type | datoid | database | active | xmin | restart_lsn
938-
-------------+-----------+--------+----------+--------+------+-------------
939-
node_a_slot | physical | | | f | |
937+
slot_name | slot_type | datoid | database | active | xmin | restart_lsn | confirmed_flush_lsn
938+
-------------+-----------+--------+----------+--------+------+-------------+---------------------
939+
node_a_slot | physical | | | f | | |
940940
(1 row)
941941
</programlisting>
942942
To configure the standby to use this slot, <varname>primary_slot_name</>

doc/src/sgml/logicaldecoding.sgml

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ postgres=# SELECT * FROM pg_create_logical_replication_slot('regression_slot', '
6262
regression_slot | 0/16B1970
6363
(1 row)
6464

65-
postgres=# SELECT slot_name, plugin, slot_type, database, active, restart_lsn FROM pg_replication_slots;
66-
slot_name | plugin | slot_type | database | active | restart_lsn
67-
-----------------+---------------+-----------+----------+--------+-------------
68-
regression_slot | test_decoding | logical | postgres | f | 0/16A4408
65+
postgres=# SELECT slot_name, plugin, slot_type, database, active, restart_lsn, confirmed_flush_lsn FROM pg_replication_slots;
66+
slot_name | plugin | slot_type | database | active | restart_lsn | confirmed_flush_lsn
67+
-----------------+---------------+-----------+----------+--------+-------------+-----------------
68+
regression_slot | test_decoding | logical | postgres | f | 0/16A4408 | 0/16A4440
6969
(1 row)
7070

7171
postgres=# -- There are no changes to see yet

src/backend/catalog/system_views.sql

+2-1
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,8 @@ CREATE VIEW pg_replication_slots AS
676676
L.active_pid,
677677
L.xmin,
678678
L.catalog_xmin,
679-
L.restart_lsn
679+
L.restart_lsn,
680+
L.confirmed_flush_lsn
680681
FROM pg_get_replication_slots() AS L
681682
LEFT JOIN pg_database D ON (L.datoid = D.oid);
682683

src/backend/replication/slotfuncs.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pg_drop_replication_slot(PG_FUNCTION_ARGS)
158158
Datum
159159
pg_get_replication_slots(PG_FUNCTION_ARGS)
160160
{
161-
#define PG_GET_REPLICATION_SLOTS_COLS 9
161+
#define PG_GET_REPLICATION_SLOTS_COLS 10
162162
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
163163
TupleDesc tupdesc;
164164
Tuplestorestate *tupstore;
@@ -206,6 +206,7 @@ pg_get_replication_slots(PG_FUNCTION_ARGS)
206206
TransactionId xmin;
207207
TransactionId catalog_xmin;
208208
XLogRecPtr restart_lsn;
209+
XLogRecPtr confirmed_flush_lsn;
209210
pid_t active_pid;
210211
Oid database;
211212
NameData slot_name;
@@ -224,6 +225,7 @@ pg_get_replication_slots(PG_FUNCTION_ARGS)
224225
catalog_xmin = slot->data.catalog_xmin;
225226
database = slot->data.database;
226227
restart_lsn = slot->data.restart_lsn;
228+
confirmed_flush_lsn = slot->data.confirmed_flush;
227229
namecpy(&slot_name, &slot->data.name);
228230
namecpy(&plugin, &slot->data.plugin);
229231

@@ -273,6 +275,11 @@ pg_get_replication_slots(PG_FUNCTION_ARGS)
273275
else
274276
nulls[i++] = true;
275277

278+
if (confirmed_flush_lsn != InvalidXLogRecPtr)
279+
values[i++] = LSNGetDatum(confirmed_flush_lsn);
280+
else
281+
nulls[i++] = true;
282+
276283
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
277284
}
278285

src/include/catalog/catversion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 201508062
56+
#define CATALOG_VERSION_NO 201508101
5757

5858
#endif

src/include/catalog/pg_proc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5197,7 +5197,7 @@ DATA(insert OID = 3779 ( pg_create_physical_replication_slot PGNSP PGUID 12 1 0
51975197
DESCR("create a physical replication slot");
51985198
DATA(insert OID = 3780 ( pg_drop_replication_slot PGNSP PGUID 12 1 0 0 0 f f f f f f v 1 0 2278 "19" _null_ _null_ _null_ _null_ _null_ pg_drop_replication_slot _null_ _null_ _null_ ));
51995199
DESCR("drop a replication slot");
5200-
DATA(insert OID = 3781 ( pg_get_replication_slots PGNSP PGUID 12 1 10 0 0 f f f f f t s 0 0 2249 "" "{19,19,25,26,16,23,28,28,3220}" "{o,o,o,o,o,o,o,o,o}" "{slot_name,plugin,slot_type,datoid,active,active_pid,xmin,catalog_xmin,restart_lsn}" _null_ _null_ pg_get_replication_slots _null_ _null_ _null_ ));
5200+
DATA(insert OID = 3781 ( pg_get_replication_slots PGNSP PGUID 12 1 10 0 0 f f f f f t s 0 0 2249 "" "{19,19,25,26,16,23,28,28,3220,3220}" "{o,o,o,o,o,o,o,o,o,o}" "{slot_name,plugin,slot_type,datoid,active,active_pid,xmin,catalog_xmin,restart_lsn,confirmed_flush_lsn}" _null_ _null_ pg_get_replication_slots _null_ _null_ _null_ ));
52015201
DESCR("information about replication slots currently in use");
52025202
DATA(insert OID = 3786 ( pg_create_logical_replication_slot PGNSP PGUID 12 1 0 0 0 f f f f f f v 2 0 2249 "19 19" "{19,19,25,3220}" "{i,i,o,o}" "{slot_name,plugin,slot_name,xlog_position}" _null_ _null_ pg_create_logical_replication_slot _null_ _null_ _null_ ));
52035203
DESCR("set up a logical replication slot");

src/test/regress/expected/rules.out

+3-2
Original file line numberDiff line numberDiff line change
@@ -1416,8 +1416,9 @@ pg_replication_slots| SELECT l.slot_name,
14161416
l.active_pid,
14171417
l.xmin,
14181418
l.catalog_xmin,
1419-
l.restart_lsn
1420-
FROM (pg_get_replication_slots() l(slot_name, plugin, slot_type, datoid, active, active_pid, xmin, catalog_xmin, restart_lsn)
1419+
l.restart_lsn,
1420+
l.confirmed_flush_lsn
1421+
FROM (pg_get_replication_slots() l(slot_name, plugin, slot_type, datoid, active, active_pid, xmin, catalog_xmin, restart_lsn, confirmed_flush_lsn)
14211422
LEFT JOIN pg_database d ON ((l.datoid = d.oid)));
14221423
pg_roles| SELECT pg_authid.rolname,
14231424
pg_authid.rolsuper,

0 commit comments

Comments
 (0)