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

Commit 66abc26

Browse files
committed
Add a new reloption, user_catalog_table.
When this reloption is set and wal_level=logical is configured, we'll record the CIDs stamped by inserts, updates, and deletes to the table just as we would for an actual catalog table. This will allow logical decoding to use historical MVCC snapshots to access such tables just as they access ordinary catalog tables. Replication solutions built around the logical decoding machinery will likely need to set this operation for their configuration tables; it might also be needed by extensions which perform table access in their output functions. Andres Freund, reviewed by myself and others.
1 parent e55704d commit 66abc26

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/backend/access/common/reloptions.c

+10
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ static relopt_bool boolRelOpts[] =
6161
},
6262
true
6363
},
64+
{
65+
{
66+
"user_catalog_table",
67+
"Declare a table as an additional catalog table, e.g. for the purpose of logical replication",
68+
RELOPT_KIND_HEAP
69+
},
70+
false
71+
},
6472
{
6573
{
6674
"fastupdate",
@@ -1166,6 +1174,8 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
11661174
offsetof(StdRdOptions, security_barrier)},
11671175
{"check_option", RELOPT_TYPE_STRING,
11681176
offsetof(StdRdOptions, check_option_offset)},
1177+
{"user_catalog_table", RELOPT_TYPE_BOOL,
1178+
offsetof(StdRdOptions, user_catalog_table)}
11691179
};
11701180

11711181
options = parseRelOptions(reloptions, validate, kind, &numoptions);

src/backend/commands/tablecmds.c

+6
Original file line numberDiff line numberDiff line change
@@ -3532,6 +3532,12 @@ ATRewriteTables(List **wqueue, LOCKMODE lockmode)
35323532
errmsg("cannot rewrite system relation \"%s\"",
35333533
RelationGetRelationName(OldHeap))));
35343534

3535+
if (RelationIsUsedAsCatalogTable(OldHeap))
3536+
ereport(ERROR,
3537+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3538+
errmsg("cannot rewrite table \"%s\" used as a catalog table",
3539+
RelationGetRelationName(OldHeap))));
3540+
35353541
/*
35363542
* Don't allow rewrite on temp tables of other backends ... their
35373543
* local buffer manager is not going to cope.

src/include/utils/rel.h

+14-2
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ typedef struct StdRdOptions
217217
AutoVacOpts autovacuum; /* autovacuum-related options */
218218
bool security_barrier; /* for views */
219219
int check_option_offset; /* for views */
220+
bool user_catalog_table; /* use as an additional catalog relation */
220221
} StdRdOptions;
221222

222223
#define HEAP_MIN_FILLFACTOR 10
@@ -285,6 +286,15 @@ typedef struct StdRdOptions
285286
((StdRdOptions *) (relation)->rd_options)->check_option_offset, \
286287
"cascaded") == 0 : false)
287288

289+
/*
290+
* RelationIsUsedAsCatalogTable
291+
* Returns whether the relation should be treated as a catalog table
292+
* from the pov of logical decoding.
293+
*/
294+
#define RelationIsUsedAsCatalogTable(relation) \
295+
((relation)->rd_options ? \
296+
((StdRdOptions *) (relation)->rd_options)->user_catalog_table : false)
297+
288298
/*
289299
* RelationIsValid
290300
* True iff relation descriptor is valid.
@@ -462,7 +472,7 @@ typedef struct StdRdOptions
462472
#define RelationIsAccessibleInLogicalDecoding(relation) \
463473
(XLogLogicalInfoActive() && \
464474
RelationNeedsWAL(relation) && \
465-
IsCatalogRelation(relation))
475+
(IsCatalogRelation(relation) || RelationIsUsedAsCatalogTable(relation)))
466476

467477
/*
468478
* RelationIsLogicallyLogged
@@ -471,7 +481,9 @@ typedef struct StdRdOptions
471481
*
472482
* We don't log information for unlogged tables (since they don't WAL log
473483
* anyway) and for system tables (their content is hard to make sense of, and
474-
* it would complicate decoding slightly for little gain).
484+
* it would complicate decoding slightly for little gain). Note that we *do*
485+
* log information for user defined catalog tables since they presumably are
486+
* interesting to the user...
475487
*/
476488
#define RelationIsLogicallyLogged(relation) \
477489
(XLogLogicalInfoActive() && \

0 commit comments

Comments
 (0)