Re: How to deinitialize a connection for background worker

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "ISHAN CHHANGANI (dot)" <f20200230h(at)alumni(dot)bits-pilani(dot)ac(dot)in>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: How to deinitialize a connection for background worker
Date: 2025-01-21 17:18:11
Message-ID: 3357370.1737479891@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"ISHAN CHHANGANI ." <f20200230h(at)alumni(dot)bits-pilani(dot)ac(dot)in> writes:
> I am working on a project which requires me to create a background worker. This worker checks some array(shared memory) every second and then connects to the database mentioned within the array. That is I want to connect to different databases using the same background worker without killing it.

You can't really. There is no part of our catalog-access
infrastructure that is designed to support this, and there are bits of
cached state all over the system that will misbehave if you try.
You found some of it, but there is plenty more.

I'd suggest letting the worker process die and spawning a new one
if you need to redirect its efforts to a new database. If that
seems too expensive, rethink the design that requires you to do it.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Anthonin Bonnefoy 2025-01-21 17:20:22 Re: Accept recovery conflict interrupt on blocked writing
Previous Message Robert Haas 2025-01-21 16:51:51 Re: Orphaned users in PG16 and above can only be managed by Superusers