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 1sPsTe-006krX-EA for pgsql-general@arkaria.postgresql.org; Fri, 05 Jul 2024 23:36:30 +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 1sPsTb-00FIE1-F3 for pgsql-general@arkaria.postgresql.org; Fri, 05 Jul 2024 23:36:28 +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 1sPsTb-00FICh-1k for pgsql-general@lists.postgresql.org; Fri, 05 Jul 2024 23:36:27 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sPsTV-000dBP-FM for pgsql-general@lists.postgresql.org; Fri, 05 Jul 2024 23:36:26 +0000 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-52e994be1abso135630e87.2 for ; Fri, 05 Jul 2024 16:36:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seawardmoon.com; s=google; t=1720222579; x=1720827379; 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=6wBvgJx/EspoPgf/w/BQlO6x6y3nwocRwX92V8y3Img=; b=LMbSq0Obkcp+hqZObfu8ciF9dQSFFewQc5o1aGZG4rVzh1/dS4bOyaNWwa0an3s5na WhcNjsnHdMZnVWhiPhZJ3Pam+8JhF0MW4CtytlZnSG1akvhPnvxSUgfFrYHsyHb4O3eP /Nq07bTYnmxeOOm4ADery5lxZ2leOVzCMtfQh1glnqa+CnlIcsZTBKT/jnpNVwuim9fe rDASE/Zk2GjJKaRUh/zi7MnKXyjjsSToSTND3Wt8XPgekEHEJBlyEqC9WbiShYNXErVZ uGCyZUeCla2kQX8N6k9ksyfiOZ69vKdy5HJaV1TaiiPmh4ItCyOZw2WxIkOgLZKbeZQ4 2M7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720222579; x=1720827379; 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=6wBvgJx/EspoPgf/w/BQlO6x6y3nwocRwX92V8y3Img=; b=Gu4H9t1OY15CqbPe70v5VptEijXKpgdxWLZ/PDx1Al+7MIeeMe19ljLZShpWYBlFT5 ltWo7gP1Ad4cUn+NclVAAfakEios3m60zhaCx2tAVRtDfNuB+H88J4wmFuuMoJ4vHl0k VEFmtr0mGlDIY2+HOMpO00jlmXCNT9nq+KL6gM35Qbd5bS5vLbaefjmvu8HRiJKmCygp AZlYLzykm7uXElQZQzbXVhVMPGJAijrnu4EQvjg4Ihik9+l0IjslhOR0GPyWJmbckxOU 4q3mIcZUvMIS+PxwaVKAmjU+Chdz75mgTBMwieMbxW5cU8xjbkk4T6I8dq//Quqe5wsH Tsrw== X-Gm-Message-State: AOJu0YxEepolyyG/INnHpLaKxf2qxs6oX9nFJBrlMNUoVhtxet1l6mw6 d+EWy/3JGsCoMlC53hyR8G66Vhbxbl2aULbh72TrO72k8WWwPfPANn2WupC1IVjiKriv5WnFR/3 2HdfjdZtJImqYcrdfMeJIO0LaN+i4y+ABQdQcKwTO2dSLH6JM X-Google-Smtp-Source: AGHT+IGtRq6ib1tSYQHhheA3HyApAvqUxc/itGEUprIY8YDZKxSlDc7gmqn+4+jW7G83oHChcfQnNWFE3jGqei84Pv0= X-Received: by 2002:a2e:b00b:0:b0:2ee:8d03:9127 with SMTP id 38308e7fff4ca-2ee8eeba39amr35487361fa.5.1720222578421; Fri, 05 Jul 2024 16:36:18 -0700 (PDT) MIME-Version: 1.0 References: <7b98efa8-9a3e-4012-8dd9-d980b5e40609@cloud.gatewaynet.com> In-Reply-To: <7b98efa8-9a3e-4012-8dd9-d980b5e40609@cloud.gatewaynet.com> From: Dennis White Date: Fri, 5 Jul 2024 19:36:07 -0400 Message-ID: Subject: Re: Can a long running procedure detect when smart shutdown is pending? To: Achilleas Mantzios Cc: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000b8d303061c888704" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b8d303061c888704 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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. 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 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 > > -- > Achilleas Mantzios > IT DEV - HEAD > IT DEPT > Dynacom Tankers Mgmt (as agents only) > > --000000000000b8d303061c888704 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks for responding.
This will be a store= d procedure written in plpgsql that's kicked off by pg_cron.
= I wasn't sure a normal smart shutdown would stop it.

Thanks

On Fri, Jul 5, 2024 at 4:57=E2=80=AFPM Achilleas Man= tzios <a.mantzios@clo= ud.gatewaynet.com> wrote:
=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)
--000000000000b8d303061c888704--