0001-wal_decoding-mergme-Support-declaring-normal-tables-.patch
text/x-patch
Filename: 0001-wal_decoding-mergme-Support-declaring-normal-tables-.patch
Type: text/x-patch
Part: 0
Message:
Re: logical changeset generation v4
Patch
Format: unified
Series: patch 0001
| File | + | − |
|---|---|---|
| src/backend/access/common/reloptions.c | 10 | 0 |
| src/backend/utils/cache/relcache.c | 8 | 1 |
| src/include/utils/rel.h | 9 | 0 |
>From b535ba12fad667725247281c43be2ef81f7e40d7 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Wed, 23 Jan 2013 13:02:34 +0100
Subject: [PATCH] wal_decoding: mergme: Support declaring normal tables as
timetraveleable
This is useful to be able to access tables used for replication metadata inside
an output plugin.
The storage option 'treat_as_catalog_table' is used for that purpose, so it can
be enabled for a table with
ALTER TABLE replication_metadata SET (treat_as_catalog_table = true);
It is currently possible to change that option mid-transaction although
timetravel access will only be possible in the next transaction.
---
src/backend/access/common/reloptions.c | 10 ++++++++++
src/backend/utils/cache/relcache.c | 9 ++++++++-
src/include/utils/rel.h | 9 +++++++++
3 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c
index 456d746..f2d3c8b 100644
--- a/src/backend/access/common/reloptions.c
+++ b/src/backend/access/common/reloptions.c
@@ -62,6 +62,14 @@ static relopt_bool boolRelOpts[] =
},
{
{
+ "treat_as_catalog_table",
+ "Treat table as a catalog table for the purpose of logical replication",
+ RELOPT_KIND_HEAP
+ },
+ false
+ },
+ {
+ {
"fastupdate",
"Enables \"fast update\" feature for this GIN index",
RELOPT_KIND_GIN
@@ -1151,6 +1159,8 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
offsetof(StdRdOptions, autovacuum) +offsetof(AutoVacOpts, analyze_scale_factor)},
{"security_barrier", RELOPT_TYPE_BOOL,
offsetof(StdRdOptions, security_barrier)},
+ {"treat_as_catalog_table", RELOPT_TYPE_BOOL,
+ offsetof(StdRdOptions, treat_as_catalog_table)},
};
options = parseRelOptions(reloptions, validate, kind, &numoptions);
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 369a4d1..cc42ff4 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -4718,12 +4718,19 @@ RelationIsDoingTimetravelInternal(Relation relation)
Assert(wal_level >= WAL_LEVEL_LOGICAL);
/*
- * XXX: Doing this test instead of using IsSystemNamespace has the
+ * XXX: Doing this test instead of using IsSystemNamespace has the frak
* advantage of classifying toast tables correctly.
*/
if (RelationGetRelid(relation) < FirstNormalObjectId)
return true;
+ /*
+ * also log relevant data if we want the table to behave as a catalog
+ * table, although its not a system provided one.
+ */
+ if (RelationIsTreatedAsCatalogTable(relation))
+ return true;
+
return false;
}
diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h
index e07ef3f..a026612 100644
--- a/src/include/utils/rel.h
+++ b/src/include/utils/rel.h
@@ -219,6 +219,7 @@ typedef struct StdRdOptions
int fillfactor; /* page fill factor in percent (0..100) */
AutoVacOpts autovacuum; /* autovacuum-related options */
bool security_barrier; /* for views */
+ bool treat_as_catalog_table; /* treat as timetraveleable table */
} StdRdOptions;
#define HEAP_MIN_FILLFACTOR 10
@@ -255,6 +256,14 @@ typedef struct StdRdOptions
((StdRdOptions *) (relation)->rd_options)->security_barrier : false)
/*
+ * RelationIsTreatedAsCatalogTable
+ * Returns whether the relation is security view, or not
+ */
+#define RelationIsTreatedAsCatalogTable(relation) \
+ ((relation)->rd_options ? \
+ ((StdRdOptions *) (relation)->rd_options)->treat_as_catalog_table : false)
+
+/*
* RelationIsValid
* True iff relation descriptor is valid.
*/
--
1.7.10.4