| From: | Srinath Reddy Sadipiralla <srinath2133(at)gmail(dot)com> |
|---|---|
| To: | Jeremy Schneider <schneider(at)ardentperf(dot)com> |
| Cc: | PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: hang during shutdown |
| Date: | 2026-07-06 05:29:01 |
| Message-ID: | CAFC+b6pQXYMks5f4XJ-QX4QpxnYnrNz9Zrkg8EiJ5-O+PxKxBQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Jeremy,
On Mon, Jul 6, 2026 at 3:25 AM Jeremy Schneider <schneider(at)ardentperf(dot)com>
wrote:
> i recently 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
> 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 past
> month. :)
>
sorry for ruining your weekend ;)
>
> so far, it all started with this postgres hang during a shutdown. 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 anyone else has seen
> 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 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 shows single open xact 2121426339 - this must belong to the
> autovac doing freeze & visibility.
>
> 04:25:09.403 immediate checkpoint (explicit from automation), same running
> 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=300s 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-state
> hang then it would 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'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.
--
Thanks :)
Srinath Reddy Sadipiralla
EDB: https://www.enterprisedb.com/
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Xuneng Zhou | 2026-07-06 05:41:35 | Re: wait_event_type for WAIT FOR LSN |
| Previous Message | shveta malik | 2026-07-06 05:12:24 | Re: [PATCH] Preserve replication origin OIDs in pg_upgrade |