Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sQ5cb-007qi4-42 for pgsql-general@arkaria.postgresql.org; Sat, 06 Jul 2024 13:38:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sQ5cX-003Z8M-V9 for pgsql-general@arkaria.postgresql.org; Sat, 06 Jul 2024 13:38:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sQ5cX-003Z8D-Kq for pgsql-general@lists.postgresql.org; Sat, 06 Jul 2024 13:38:33 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sQ5cQ-000jd3-BU for pgsql-general@lists.postgresql.org; Sat, 06 Jul 2024 13:38:32 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 466DcMaN471036; Sat, 6 Jul 2024 09:38:23 -0400 From: Tom Lane To: Laurenz Albe cc: Dennis White , pgsql-general Subject: Re: Can a long running procedure detect when smart shutdown is pending? In-reply-to: <7e8b6d1951cf55c534966eb4a346add6fa420da7.camel@cybertec.at> References: <7e8b6d1951cf55c534966eb4a346add6fa420da7.camel@cybertec.at> Comments: In-reply-to Laurenz Albe message dated "Sat, 06 Jul 2024 07:59:26 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <471034.1720273102.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 06 Jul 2024 09:38:22 -0400 Message-ID: <471035.1720273102@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Laurenz Albe 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 Con= trol 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 requir= e 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 da= tabase. > If you get an error "the database system is shutting down", there is a s= mart > shutdown in progress. This'd probably work. Ugly, but ... regards, tom lane