"out of relcache_callback_list slots" after multiple calls to pg_logical_slot_get_binary_changes

From: "shiy(dot)fnst(at)fujitsu(dot)com" <shiy(dot)fnst(at)fujitsu(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: "out of relcache_callback_list slots" after multiple calls to pg_logical_slot_get_binary_changes
Date: 2023-02-19 02:40:31
Message-ID: OSZPR01MB631004A78D743D68921FFAD3FDA79@OSZPR01MB6310.jpnprd01.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

After multiple calls to the function pg_logical_slot_get_binary_changes() in
single client backend (the output plugin of the slot is pgoutput), I got the
following error:

client backend FATAL: out of relcache_callback_list slots
client backend CONTEXT: slot "testslot", output plugin "pgoutput", in the startup callback
client backend STATEMENT: SELECT data FROM pg_logical_slot_get_binary_changes('testslot', NULL, NULL, 'proto_version', '3', 'streaming', 'off', 'publication_names', 'pub');

I tried to look into it and found that it's because every time the function
(pg_logical_slot_get_binary_changes) is called, relcache callback and syscache
callbacks are registered when initializing pgoutput (see pgoutput_startup() and
init_rel_sync_cache()), but they are not unregistered when it shutdowns. So,
after multiple calls to the function, MAX_RELCACHE_CALLBACKS is exceeded. This
is mentioned in the following comment.

/*
* We can get here if the plugin was used in SQL interface as the
* RelSchemaSyncCache is destroyed when the decoding finishes, but there
* is no way to unregister the relcache invalidation callback.
*/
if (RelationSyncCache == NULL)
return;

Could we fix it by adding two new function to unregister relcache callback and
syscache callback? I tried to do so in the attached patch.

Regards,
Shi Yu

Attachment Content-Type Size
v1-0001-Unregister-syscache-callback-and-relcache-callbac.patch application/octet-stream 6.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2023-02-19 05:40:39 Re: shoud be get_extension_schema visible?
Previous Message Jonathan S. Katz 2023-02-19 02:20:31 Re: Support logical replication of DDLs