aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-02-23 15:40:28 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2023-02-23 15:40:28 -0500
commit95558bc8ff89c5887f1bffc9d152ca603637e2c0 (patch)
treec671cbc2ea68f1cc13b6c7d6e0b886f5b09ba6fa
parent98b83b7349821b05134e6f50f516ecac878cb91d (diff)
downloadpostgresql-95558bc8ff89c5887f1bffc9d152ca603637e2c0.tar.gz
postgresql-95558bc8ff89c5887f1bffc9d152ca603637e2c0.zip
Don't repeatedly register cache callbacks in pgoutput plugin.
Multiple cycles of starting up and shutting down the plugin within a single session would eventually lead to "out of relcache_callback_list slots", because pgoutput_startup blindly re-registered its cache callbacks each time. Fix it to register them only once, as all other users of cache callbacks already take care to do. This has been broken all along, so back-patch to all supported branches. Shi Yu Discussion: https://postgr.es/m/OSZPR01MB631004A78D743D68921FFAD3FDA79@OSZPR01MB6310.jpnprd01.prod.outlook.com
-rw-r--r--src/backend/replication/pgoutput/pgoutput.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index 6710f983ea4..1b7a16d889b 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -152,6 +152,7 @@ pgoutput_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
bool is_init)
{
PGOutputData *data = palloc0(sizeof(PGOutputData));
+ static bool publication_callback_registered = false;
/* Create our memory context for private allocations. */
data->context = AllocSetContextCreate(ctx->context,
@@ -196,9 +197,18 @@ pgoutput_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
/* Init publication state. */
data->publications = NIL;
publications_valid = false;
- CacheRegisterSyscacheCallback(PUBLICATIONOID,
- publication_invalidation_cb,
- (Datum) 0);
+
+ /*
+ * Register callback for pg_publication if we didn't already do that
+ * during some previous call in this process.
+ */
+ if (!publication_callback_registered)
+ {
+ CacheRegisterSyscacheCallback(PUBLICATIONOID,
+ publication_invalidation_cb,
+ (Datum) 0);
+ publication_callback_registered = true;
+ }
/* Initialize relation schema cache. */
init_rel_sync_cache(CacheMemoryContext);
@@ -503,8 +513,10 @@ static void
init_rel_sync_cache(MemoryContext cachectx)
{
HASHCTL ctl;
+ static bool relation_callbacks_registered = false;
MemoryContext old_ctxt;
+ /* Nothing to do if hash table already exists */
if (RelationSyncCache != NULL)
return;
@@ -522,10 +534,16 @@ init_rel_sync_cache(MemoryContext cachectx)
Assert(RelationSyncCache != NULL);
+ /* No more to do if we already registered callbacks */
+ if (relation_callbacks_registered)
+ return;
+
CacheRegisterRelcacheCallback(rel_sync_cache_relation_cb, (Datum) 0);
CacheRegisterSyscacheCallback(PUBLICATIONRELMAP,
rel_sync_cache_publication_cb,
(Datum) 0);
+
+ relation_callbacks_registered = true;
}
/*