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.96) (envelope-from ) id 1wgbuP-006Hyd-0G for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jul 2026 05:30:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wgbtN-00F1mH-34 for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jul 2026 05:29:17 +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.96) (envelope-from ) id 1wgbtN-00F1m8-1l for pgsql-hackers@lists.postgresql.org; Mon, 06 Jul 2026 05:29:17 +0000 Received: from mail-vs1-xe2e.google.com ([2607:f8b0:4864:20::e2e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wgbtL-00000001l1e-0dXb for pgsql-hackers@postgresql.org; Mon, 06 Jul 2026 05:29:16 +0000 Received: by mail-vs1-xe2e.google.com with SMTP id ada2fe7eead31-736eea06c3eso707864137.0 for ; Sun, 05 Jul 2026 22:29:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783315754; cv=none; d=google.com; s=arc-20260327; b=F+8g1tKZ848eROA+96Chv24gjy8RgtJwGUY0dxLloeohuRWno49+UgObQR/Ud7Epxv QkE3i7kOSwotf6o57To2eQ4U2I8Y5MpU7tG58um6uYlWOBtYAirOVBNBi3C8nD89dZGt u9UaROwsBpeZrJPr7pULA+cD31wnAP95hhaTJr8ovKnJd9uZET+DJTF0BLeYumd4LVhH M85iZF4t4YNqPN5uhsrkGJELbLYcCD3iXWdJf7xIOyKXQq6bO/RKJFATgjX4fmzpM17u aCzIXUbVvo1EOKObbZksLnQyTaJ32S2X7ROT8je0nFbzMJpoa79yAIZ+Usp8ovIgn5Fn qXTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=UxnsSQH7TRkDrGEUFWfcYeNu7qnbluz1Sfsx75G0tjc=; fh=k6ueqkgnDuBwgLQgFXAlKr+SiUEnFy5yLHMj2spqOeg=; b=hly9Tcc8azacHhpoGvZ/ubV9i4Xk9unUNyKtewoJdlI/0PwOufxFhHN/3J2K5J3jqL AODl66qm4HObu3JumvXLbrFuyz9SGmWPqvfJwwlleMyBct5iSHcvju1j91YZFqpGfACt Fxark+83ZFfpZVPoH/GZEBd1wNb6PS20cyyPlWloS0Zc7wCvOCSSbxPLjg9wMEFoFOTQ 8xWR0IgQGQx/S5qAb5cd8hOtx7+oaRMLLTgwgxzYBmDChPPJ546F0316rCtoECtvsWVY dNpQt3eCemPtJhYNBbAc2OaSdE9M24swrnCF7f/kJYovKlzx4+UgqT+NsVujuPJ4b6mJ Bbxg==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783315754; x=1783920554; darn=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=UxnsSQH7TRkDrGEUFWfcYeNu7qnbluz1Sfsx75G0tjc=; b=Q7pyW5yW1uyqLr1GWPMMq3RWY8IM3wjSpaxgdh6lFKUsR5BzXlEFm02//J+ttah3SH SrD7W1QrCsqlt/Kk1uMRJS5V5Wnu0LVZJ3H9Cv9Yr1c3vwCUhV5GPXJ8/pYCEuDY46tE g4I+4xze43LOpBdsY0k/wrsmQYpcHTponmKZRhB9d8pxym1uYJFUYzSkXCFbzdG/OTnW LFOIt7vCFy3g19cAYdCdPvq4IEwJ0FZYaE9CAbho1LdamTBbZB21l4OYNxnVAkbSAP+7 9mnmFWG9Cr3zpT5F7PLwNTkIMJQ6sxykE8NDfO0D0CHirClihoxoRUgvZrbUAoW1cwHn 5u+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783315754; x=1783920554; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=UxnsSQH7TRkDrGEUFWfcYeNu7qnbluz1Sfsx75G0tjc=; b=mfST547oKX+5NZhbvQz0NoCKeWmIKRQlP35DFK8otqlRYawT69b2bYVCsUuN6x6yUE KPACWQW1/9a886bmEeIbMENeuORLLGx5GhN/SoisDJRMaSHHfSAd7UAcF08ZWSBY5j3X TZMJkQQ7QXysqyfUlOL7LN/wA5GO4uyVU9UAPCGuanVX0Y6JXKps8JZ3a++r/vFsmBxy ZvxKgWgU5YvqtIHRQ8mFD6t91ce6rILpoAT2pa5Gx09EFgzl7oy72poZ3na3ohWNicfl shQidkOvUn/26kCYC3NHSZQ5INDy1V0rK/yLGCG9czbduE3OpKAV9SwBUje3K3IlX+8T OOmQ== X-Gm-Message-State: AOJu0YwxsQMLXret35l40tXvKvipC4ZBhOHHWzNOa4XltqnN4JC0LsZU KNNVY63vWyr6hAYuz1T3ICymREVyY9Ccakub8vZKwYaS8jjfEsxXpjd0aZq2CvFRQySyF0lsj2x 9uaiASxJm7w3ICPhPpt8VaH4ou8io3CGH2uRE X-Gm-Gg: AfdE7cljsafCYamC2X+zTaoqUSJ517pRCSBQ/fcQhax8G+XGReB0jSUwGZ9jGmYL3i9 E40Jv9hxWQOOnqyP5H5pdDGkHLphg2+LVepQ666XRCtE542JR3u+6zJowJh9xOhlRN/1A+bJtWB F/1SGyr3v3ow6rVlG0hYy5RHUVGaPEDe21XIgSaJlC1Oap37DqF5uTzKsZeV1d5SeJlXxlgNaza Ng3ykHIxTqFphCyOUOb99wuNAwkd29j2i0OBlOWlyOMI5lFHiAQewrjzte6w9GNfOghWv8C/wgm 1R0TKQRAopJyRcVEYB2getLR1PYIczAYG5hJVtLFJBcJQgxgEr+WW8Cr78p8K4PyVlU/aARXY5h hR5IPNrSfkPAni3ZR X-Received: by 2002:a05:6102:510c:b0:738:ff1b:942 with SMTP id ada2fe7eead31-7427f051094mr2877209137.22.1783315753980; Sun, 05 Jul 2026 22:29:13 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Srinath Reddy Sadipiralla Date: Mon, 6 Jul 2026 10:59:01 +0530 X-Gm-Features: AVVi8CfwRJeAkcn-wwFN_9NKkJtjNMH_J7IRND7XYriamKK6eqHXwgzDtdrVkb4 Message-ID: Subject: Re: hang during shutdown To: Jeremy Schneider Cc: PostgreSQL mailing lists Content-Type: multipart/alternative; boundary="00000000000009d6a80655ea8eae" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000009d6a80655ea8eae Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Jeremy, On Mon, Jul 6, 2026 at 3:25=E2=80=AFAM Jeremy Schneider wrote: > i recently saw a hung shutdown on a busy multi-TB production database. th= e > hung shutdown had some unexpected downstream impacts unrelated to core > postgres which turned a routine maintenance operation into a long dramati= c > overnight incident... blowing way past our planned maint window and > spoiling my weekend... but that's another story and mainly just explains = my > stubborn persistence slowly following the dominoes backwards over this pa= st > month. :) > sorry for ruining your weekend ;) > > so far, it all started with this postgres hang during a shutdown. we didn= t > capture enough diagnostics to root-cause the domino before the hang, but > the data i do have about this postgres hang is very peculiar. i'm working > on some automation to gather more diagnostics if there is a recurrence. i= n > the meantime i wanted to share what i do know, in case anyone else has se= en > something similar. > > postgres version 16.13 > Ubuntu 22.04.5 LTS > kernel 5.15.0-1110-azure > > between log messages and wal contents, it appears PostmasterStateMachine > transitioned into PM_WAIT_BACKENDS but never progressed beyond this for a > full 30 minutes until external automation finally killed the processes. i > think the evidence most strongly supports the idea that an autovacuum > worker was somehow wedged, but no idea where it possibly could have been > stuck. app was shut down before maint started, at hang time there were on= ly > three open "postgres" user connections from platform automation. > > here's what i have: > > 04:24:07 wal checkpoint. two in-progress autovacs, one is writing > FREEZE_PAGE and VISIBLE records, AI tells me this requires an xid. > RUNNING_XACTS shows single open xact 2121426339 - this must belong to the > autovac doing freeze & visibility. > > 04:25:09.403 immediate checkpoint (explicit from automation), same runnin= g > xid > > 04:25:09.808 pg logs the fast shutdown req (pg_ctl stop -m fast from > automation) > > 04:25:09.815 both autovac workers log "terminating autovacuum process": > die() -> ProcessInterrupts() -> ereport() > > 04:30:09 XLOG_SWITCH and archiver uploads segment 0x30 > > 04:30:10 checkpooint_timeout=3D300s fires, 72 dirty buffers written. > RUNNING_XACTS at this time shows xid 2121426339 is still open. > > 04:35:10 XLOG_SWITCH and archiver uploads segment 0x31 > > 04:55:08 external automation SIGKILL > > > based on the fact that we saw checkpoints and archivals a full 10 minutes > later, that's why i think it never left PM_WAIT_BACKENDS. also, there was > never any XLOG_CHECKPOINT_SHUTDOWN record or any XLOG_XACT_ABORT record > written in the whole 30 minutes. > > AI tells me autovac process needs to call AbortTransaction() which calls > ProcArrayEndTransaction() to remove xid from PGPROC and also calls > RecordTransactionAbort() which should write the abort WAL record. neither > of these happen, which suggests autovac was stuck after it logs its > termination message and before it performs either of these actions. this = is > not a lot of code, and my AI couldnt find any obvious places where theres > disk or network calls or anything else that could hang. > > successful checkpoints suggest that both the data and the wal disks were > accepting writes, and IO was not hung on the whole. if there was a D-stat= e > hang then it would have been just one process, while others on same devic= e > did not hang. > > your autovac analysis makes sense, i think that after worker's fatal -> proc_exit(1)-> proc_exit_prepare->calls a shmem_exit and stuck there, maybe because of any extension's shmem callback, idk, it would be awesome if you get the backtrace using gdb by connecting to the PID of autovacuum which got stuck , if it was not stuck then it goes to the ShutdownPostgres = , a InitPostgres before_shmem_exit callback and would have called AbortTransaction and write the WAL record, which is not the case as you mentioned. --=20 Thanks :) Srinath Reddy Sadipiralla EDB: https://www.enterprisedb.com/ --00000000000009d6a80655ea8eae Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi=C2=A0Jeremy,

On M= on, Jul 6, 2026 at 3:25=E2=80=AFAM Jeremy Schneider <schneider@ardentperf.com> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">
i re= cently saw a hung shutdown on a busy multi-TB production database. the hung= shutdown had some unexpected downstream impacts unrelated to core postgres= which turned a routine maintenance operation into a long dramatic overnigh= t incident... blowing way past our planned maint window and spoiling my wee= kend... but that's another story and mainly just explains my stubborn p= ersistence slowly following the dominoes backwards over this past month. = =C2=A0:)

sorry for ruining your weeken= d ;)
=C2=A0

so far, it all started with this postgres hang during a shu= tdown. we didnt capture enough diagnostics to root-cause the domino before = the hang, but the data i do have about this postgres hang is very peculiar.= i'm working on some automation to gather more diagnostics if there is = a recurrence. in the meantime i wanted to share what i do know, in case any= one else has seen something similar.

postgres version 16.13
Ubunt= u 22.04.5 LTS
kernel 5.15.0-1110-azure

between log messages and w= al contents, it appears PostmasterStateMachine transitioned into PM_WAIT_BA= CKENDS but never progressed beyond this for a full 30 minutes until externa= l automation finally killed the processes. i think the evidence most strong= ly supports the idea that an autovacuum worker was somehow wedged, but no i= dea where it possibly could have been stuck. app was shut down before maint= started, at hang time there were only three open "postgres" user= connections from platform automation.

here's what i have:
04:24:07 wal checkpoint. two in-progress autovacs, one is writing FREEZE_= PAGE and VISIBLE records, AI tells me this requires an xid. RUNNING_XACTS s= hows single open xact 2121426339 - this must belong to the autovac doing fr= eeze & visibility.

04:25:09.403 immediate checkpoint (explicit f= rom automation), same running xid

04:25:09.808 pg logs the fast shut= down req (pg_ctl stop -m fast from automation)

04:25:09.815 both aut= ovac workers log "terminating autovacuum process": die() -> Pr= ocessInterrupts() -> ereport()

04:30:09 XLOG_SWITCH and archiver = uploads segment 0x30

04:30:10 checkpooint_timeout=3D300s fires, 72 d= irty buffers written. RUNNING_XACTS at this time shows xid 2121426339 is st= ill open.

04:35:10 XLOG_SWITCH and archiver uploads segment 0x31
=
04:55:08 external automation SIGKILL


based on the fact that = we saw checkpoints and archivals a full 10 minutes later, that's why i = think it never left PM_WAIT_BACKENDS. also, there was never any XLOG_CHECKP= OINT_SHUTDOWN record or any XLOG_XACT_ABORT record written in the whole 30 = minutes.

AI tells me autovac process needs to call AbortTransaction(= ) which calls ProcArrayEndTransaction() to remove xid from PGPROC and also = calls RecordTransactionAbort() which should write the abort WAL record. nei= ther of these happen, which suggests autovac was stuck after it logs its te= rmination message and before it performs either of these actions. this is n= ot a lot of code, and my AI couldnt find any obvious places where theres di= sk or network calls or anything else that could hang.

successful che= ckpoints suggest that both the data and the wal disks were accepting writes= , and IO was not hung on the whole. if there was a D-state hang then it wou= ld have been just one process, while others on same device did not hang.

your autovac analysis makes sense, i think= that after worker's fatal -> proc_exit(1)->
proc_exit_prepare= ->calls a shmem_exit and stuck there, maybe because
of any extension&= #39;s shmem callback, idk, it would be awesome if you
get the backtrace = using gdb by connecting to the PID of autovacuum
which got stuck , if it= was not stuck then it goes to the ShutdownPostgres ,
a InitPostgres bef= ore_shmem_exit callback and would have called
AbortTransaction and write= the WAL record, which is not the case as
you mentioned.

--
Thanks :)
Srinath Reddy Sadipiralla
EDB:=C2=A0https://www.enterprisedb.com/
--00000000000009d6a80655ea8eae--