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 1sPy9k-007Br8-Rx for pgsql-general@arkaria.postgresql.org; Sat, 06 Jul 2024 05:40:21 +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 1sPy9i-000LTx-U6 for pgsql-general@arkaria.postgresql.org; Sat, 06 Jul 2024 05:40:19 +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 1sPy9i-000LTo-FN for pgsql-general@lists.postgresql.org; Sat, 06 Jul 2024 05:40:19 +0000 Received: from mail-yw1-x112c.google.com ([2607:f8b0:4864:20::112c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sPy9g-000eGD-EV for pgsql-general@lists.postgresql.org; Sat, 06 Jul 2024 05:40:17 +0000 Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-650469f59d7so20598477b3.2 for ; Fri, 05 Jul 2024 22:40:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720244416; x=1720849216; 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=fbtzmnZ3ABYfADyErCNoECO+vIvDTPxxfaHZ1wzn4IQ=; b=FyP7fXFNpOhLg8OXH/d2n9ar78TpOefqDfYFnwdEYlvUhPL7cj679H5baA0EWEEads SQidCYiiiRYH8i73HMTg9oXaqDo+W23Z/dE5dxwldrnCz0EmRHKymc4O/kvXYaVhX+fA 1HTboEe5aQT9a11u+xO37XWbyMV4qrFmevSgx/EsbqAZ3wcexpCyJ4laTFaO2qaBvAdu fdvjpAtnf9OcMmwOlYc+Cc+RumCE2hi+AgziWbzLD4NVSKsgGVDGj0xARWtuQqbG2UuD hCFNxj78iFWFrUEgd9p66Mcoot8knicEFk/S8oZkFQ9ecs4chMvJ5lizkbw3Vd+ZoAm9 SUyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720244416; x=1720849216; 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=fbtzmnZ3ABYfADyErCNoECO+vIvDTPxxfaHZ1wzn4IQ=; b=s0tSV3hBvRXGreuLSX7ptK4lAUPlfYqsVgS0IDTlnFv0TDhPMYzmoXKTqFQJ5oTbTd tupkj5Q/o0m5GZQ7IWfJ7jjLyxJ8IuygZ+Se4NpdiMwXpEainBrRwGFPAiIrxPe6TxJv KHMgW27S4tFEpANgTQ5fg7naDtdU7nxyUY4XakkYNO3eC6INMo0i+jENqxxe1jhCCahb o/ZvruYr4XBxN4yblWmZCjvOHmvKAqv23RoeE93omJGXsggrq/70w+Ui0YqEY3vKap6H 6f6yNify7ThgCzTHsXTbNolZmndQjWFupNOzASW4mMhicEFxas3rTaYyY7/eHDfjdYiY Kp8g== X-Forwarded-Encrypted: i=1; AJvYcCXhXBNGk9ANtMS5sxvYLv6DwtD4iJJq23SWSEn5kaQr3kJRdYqa+wMyH3Z1kmyl/c/h57gbU83E2PdZTzUvfnN/1jYF7n+q30imzhRpLBL9KSEf X-Gm-Message-State: AOJu0YwjaGwSVlh57zjyth3YfZiEwdlsJOb8O0HRdUK9cggqGOa6T8vN 8kezpXQVK4hsHR5UXMbxhULoulDLcS3c+S0RT4TWoiDfzmpgTiqgDgs25xX3rZLeKVr+11Ye2FS XyLX+se+MUQizBI5IocoCgsf842g= X-Google-Smtp-Source: AGHT+IGPZv25oJznjZFGWM3deIA3FAKjE72gj6GJQP0cPqKOFGYTVPJBPvvvecZuEHH/f/7vE/FWMlIv3zOCrW9KRYg= X-Received: by 2002:a81:9215:0:b0:64b:8b8f:7770 with SMTP id 00721157ae682-652d60ecec4mr67570297b3.23.1720244415635; Fri, 05 Jul 2024 22:40:15 -0700 (PDT) MIME-Version: 1.0 References: <7b98efa8-9a3e-4012-8dd9-d980b5e40609@cloud.gatewaynet.com> In-Reply-To: From: Pavel Stehule Date: Sat, 6 Jul 2024 07:39:38 +0200 Message-ID: Subject: Re: Can a long running procedure detect when smart shutdown is pending? To: dwhite@seawardmoon.com Cc: Achilleas Mantzios , pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000005229bb061c8d9df5" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000005229bb061c8d9df5 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable so 6. 7. 2024 v 1:36 odes=C3=ADlatel Dennis White napsal: > Thanks for responding. > This will be a stored procedure written in plpgsql that's kicked off by > pg_cron. > I wasn't sure a normal smart shutdown would stop it. > shutdown try to cancel any query. The plpgsql routine should be canceled without problems. > > Thanks > > On Fri, Jul 5, 2024 at 4:57=E2=80=AFPM Achilleas Mantzios < > a.mantzios@cloud.gatewaynet.com> wrote: > >> =CE=A3=CF=84=CE=B9=CF=82 5/7/24 21:12, =CE=BF/=CE=B7 Dennis White =CE=AD= =CE=B3=CF=81=CE=B1=CF=88=CE=B5: >> >> 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 s= o >> it can stop between steps? >> >> We are using both PG 14 and PG 16 on Rhel 8. >> Pardon me if it's obvious but is there a function to call or a table tha= t >> could be checked after a commit within the procedure to determine a >> shutdown is pending? >> >> Maybe somehow checking the log for a message like : >> >> received smart shutdown request >> >> Or use tail_n_mail against the log and then implement some logic using >> NOTIFY , ideally you want your procedure to be interrupted rather than d= o >> polling. >> >> >> Thanks, >> Dennis >> >> -- >> Achilleas Mantzios >> IT DEV - HEAD >> IT DEPT >> Dynacom Tankers Mgmt (as agents only) >> >> --0000000000005229bb061c8d9df5 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
so 6. 7. 2024 v=C2=A01:36 odes=C3=ADl= atel Dennis White <dwhite@seaw= ardmoon.com> napsal:
Thanks for responding.
This wil= l be a stored procedure written in plpgsql that's kicked off by pg_cron= .
I wasn't sure a normal smart shutdown would stop it.
<= /div>

shutdown try to cancel any query. The= plpgsql routine should be canceled without problems.

=C2=A0
<= div dir=3D"ltr">

Thanks

On Fri, Jul 5, 2024 at = 4:57=E2=80=AFPM Achilleas Mantzios <a.mantzios@cloud.gatewaynet.com> wr= ote:
=20 =20 =20
=CE=A3=CF=84=CE=B9=CF=82 5/7/24 21:12, =CE=BF/=CE=B7 Dennis White =CE=AD=CE=B3=CF=81=CE=B1=CF=88=CE=B5:
=20
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?

We are using both PG 14 and PG 16 on Rhel 8.
Pardon me if it's obvious but is there a function to call or a table that could be checked after a commit within the procedure to determine a shutdown is pending?

Maybe somehow checking the log for a message like :

received smart shutdown request

Or use tail_n_mail against the log and then implement some logic using NOTIFY , ideally you want your procedure to be interrupted rather than do polling.


Thanks,
Dennis
--=20
Achilleas Mantzios
 IT DEV - HEAD
 IT DEPT
 Dynacom Tankers Mgmt (as agents only)
--0000000000005229bb061c8d9df5--