Subject: Re: "out of relcache_callback_list slots" after multiple callsto pg_logical_slot_get_binary_changes

From: Kyotaro Horiguchi <[email-masked]>
Date: Mon, 20 Feb 2023 17:08:19 +0900 (JST)

Good catch!

At Sun, 19 Feb 2023 02:40:31 +0000, "[email-masked]" <[email-masked]> wrote in 
> 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.

I'm pretty sure that everytime an output plugin is initialized on a
process, it installs the same set of syscache/relcache callbacks each
time.  Do you think we could simply stop duplicate registration of
those callbacks by using a static boolean?  It would be far simpler.

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center

---

From: Tom Lane <[email-masked]>
Date: Mon, 20 Feb 2023 10:30:43 -0500

> those callbacks by using a static boolean?  It would be far simpler.

Yeah, I think that's the way it's done elsewhere.  Removing and
re-registering your callback seems expensive, and it also destroys
any reasoning that anyone might have made about the order in which
different callbacks will get called.  (Admittedly, that's probably not
important for invalidation callbacks, but it does matter for e.g.
process exit callbacks.)

			regards, tom lane