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 1sQ92R-0087TF-G8 for pgsql-general@arkaria.postgresql.org; Sat, 06 Jul 2024 17:17:31 +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 1sQ92O-004ksl-6L for pgsql-general@arkaria.postgresql.org; Sat, 06 Jul 2024 17:17:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sQ92N-004ksd-Ph for pgsql-general@lists.postgresql.org; Sat, 06 Jul 2024 17:17:27 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sQ92J-000jbW-FA for pgsql-general@lists.postgresql.org; Sat, 06 Jul 2024 17:17:26 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-52e9ab8b7cdso304819e87.1 for ; Sat, 06 Jul 2024 10:17:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seawardmoon.com; s=google; t=1720286240; x=1720891040; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=w0rFruSr2EVLh2w1H2e2YjLol+zpPSapuM6MnBs1d+c=; b=SJRdFTJkwTCKvAkcTu/+JQ1UUr5XaNgnhdQh2eiIzpOYHhiL7QAIu6yDbQbYywNZye 6SflkbnAPXXaTa1TCoesYTZew+gb+Nvl9LsdJK8x4GL1H/fUFppZnzSaF8LGTdff1zMr MOocGorVIcLR1IQRkAsYHRFZu9PtJi2WcZ4JHi9GXepH7kagXt+YgyQ0UkAegjJYqZlP ClHld0AXC5weCdS6GNmSAFfHNdXORRwUabfwD/EiMF09ASI8qwqC/7ewFrxCdjMq6GSj +PieHb7OxMDf+VopvWf2KqieCfd7VO62OLhVoSvS2+Xxu0j0bVJKap0P9suTt/XsSVpQ RQYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720286240; x=1720891040; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=w0rFruSr2EVLh2w1H2e2YjLol+zpPSapuM6MnBs1d+c=; b=aOJF0BCZ2hD9zJ6bZ0RhjP+fE+JVHFj2TAlYLdNwJxyGFSaloeFCX5JLwFV9fJX7Ql m49OnWwPJnyziMjcrP5BGru1gYcO7Q3WpbY0V3+o+G/vN+f7hsXQFcgARRBfOQiDBMZk ke5Y4SLvLRlx6VwIo9WaNuVHMhiXuFcp2HVqsVmk/d9RnF1w0r/W+3tRG1/TbKboZf64 8qNhapDEAbPHWjTRZ7e38WQtIWimysSC4CWYnmV1JlluaR9xBcWT9EMTgPVq0Zx4/Is/ EV/aPOm0S0sXRBZIRFrSELS3jlkgAlGa9rjz+/Ng2SAwivCoCt/BAj59dtJXGIekmiNJ F6pA== X-Forwarded-Encrypted: i=1; AJvYcCUhb0CWZXeIofk6g8jyA8gVTQYdP7VF3qYtw7sds2n5hH4Q2BynKmayiwCu0+RAvDDDF0OD8vq4dffDV5iacVVKtaAu56ad0cIj7kjpnd6lWmYx X-Gm-Message-State: AOJu0Yxfo81xDUHEyY3zLDSZT5Z4NrxBMspM8tH4EnGnaOjmxsm2aois ept6gJ5d7jT/CH/XgGxSaTXn3XME3x6vwSKxJOVY6gflI10pso+uIIzdM118JM9Vfo3aNNX0x01 GnXyDoUeGnHNaEPgO2RF9XHB40diDUWFRh4Q8+oh960T9+ubD X-Google-Smtp-Source: AGHT+IFRQZHJ+/VBYSHrcNXNGFvCJAaSi9+E43bEs90lDB3g4KCQZMZlPhIrQygSCAoB7bnn35qMep8zgzCB1v/Mmog= X-Received: by 2002:a2e:3309:0:b0:2ec:18c7:169d with SMTP id 38308e7fff4ca-2ee8ed66c33mr46341651fa.1.1720286239838; Sat, 06 Jul 2024 10:17:19 -0700 (PDT) MIME-Version: 1.0 References: <7e8b6d1951cf55c534966eb4a346add6fa420da7.camel@cybertec.at> <471035.1720273102@sss.pgh.pa.us> In-Reply-To: <471035.1720273102@sss.pgh.pa.us> From: Dennis White Date: Sat, 6 Jul 2024 13:17:08 -0400 Message-ID: Subject: Re: Can a long running procedure detect when smart shutdown is pending? To: Tom Lane Cc: Laurenz Albe , pgsql-general Content-Type: multipart/alternative; boundary="0000000000003ce714061c975a54" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000003ce714061c975a54 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks everyone. A more direct way to check via a sql function would be better but I suppose the dblink extension method will work. Thanks again, Dennis On Sat, Jul 6, 2024 at 9:38=E2=80=AFAM Tom Lane wrote: > 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 > 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 > --0000000000003ce714061c975a54 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks everyone. A more direct way to check via a sql= function would be better but I suppose the dblink extension method will wo= rk.

Thanks again,
Dennis
=
On Sat= , Jul 6, 2024 at 9:38=E2=80=AFAM Tom Lane <tgl@sss.pgh.pa.us> wrote:
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 Transa= ction Control that may take 30 minutes or more to complete.
>> I am curious if there is a way to make it more smart shutdown frie= ndly 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.=C2=A0 Ugly, but ...

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 regards, tom lane
--0000000000003ce714061c975a54--