Re: Can a long running procedure detect when smart shutdown is pending? - Mailing list pgsql-general

From Tom Lane
Subject Re: Can a long running procedure detect when smart shutdown is pending?
Date
Msg-id 471035.1720273102@sss.pgh.pa.us
Whole thread Raw
In response to Re: Can a long running procedure detect when smart shutdown is pending?  (Laurenz Albe <laurenz.albe@cybertec.at>)
Responses Re: Can a long running procedure detect when smart shutdown is pending?
List pgsql-general
Laurenz Albe <laurenz.albe@cybertec.at> writes:
> On Fri, 2024-07-05 at 14:12 -0400, Dennis White wrote:
>> My project's DB has a mutli-step stored procedure using Transaction Control that may take 30 minutes or more to
complete.
>> I am curious if there is a way to make it more smart shutdown friendly so it can stop between steps?

> I don't think there is a direct way to do that in SQL; that would require a new
> system function that exposes canAcceptConnections() in SQL.

It's worse than that: the state variables involved are local to the
postmaster, so you wouldn't get the right answer in a backend even
if the function were reachable.

> What you could do is use the dblink extension to connect to the local database.
> If you get an error "the database system is shutting down", there is a smart
> shutdown in progress.

This'd probably work.  Ugly, but ...

            regards, tom lane



pgsql-general by date:

Previous
From: "Peter J. Holzer"
Date:
Subject: Re: confused about material view locks please explain
Next
From: Michael Nolan
Date:
Subject: Re: Alignment check