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 1wgUqq-006Dpg-28 for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Jul 2026 21:58:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wgUqp-00Dukx-0k for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Jul 2026 21:58:11 +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.96) (envelope-from ) id 1wgUnh-00Dr3u-0r for pgsql-hackers@lists.postgresql.org; Sun, 05 Jul 2026 21:54:57 +0000 Received: from mail-lj1-x229.google.com ([2a00:1450:4864:20::229]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wgUne-00000001wN7-3avo for pgsql-hackers@postgresql.org; Sun, 05 Jul 2026 21:54:56 +0000 Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-39b217f54daso23893631fa.0 for ; Sun, 05 Jul 2026 14:54:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783288494; cv=none; d=google.com; s=arc-20260327; b=OWtrwByADzcI3dgZnNAmBAuukR6hIven9J7aylmtFtVa36nkMXSAR5U4Ycc1XvZNjN 8j18gtVvM5vEhRZBCTI4s9C54pCsVagS0k8gc3eAJ/AtfWrOl9Qlp5MAWSCmgmRqfSEE VA8btdKHZCFLTnT+loFuT6kr8WB9fZkm1DXa9IF7JPPEJ+9kVclkG8oE2J/+kdh9cbSN GE+K+WvpBqIuBsCgp+D8EuPA46IfYjRjbHzzsDRy1rbhDkScg9DE27t5KQSS8iiPvUbP HUhp0qtjkRUkmhJJKE/1RiDDIk+EUugrzqrKFN4yEEqV1g0Gih1rGk3ilH/Dq7u78K2b 9PkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=to:subject:message-id:date:from:mime-version:dkim-signature; bh=RJ1Ya5PxAfOD2z0w2+54NdGoqW4Ku1NaPEjt9azgiZ0=; fh=BzvuiUoYZmDQVdingmDswqztNCftM0Ive1oQwE7t0iM=; b=k0HXPZbllSQKsfPo/Vz3VOH/ICTJvF3sRc61g4jAiXs/IJFIFapfOdQOaDnKp5r8ku WO0i4zfC27XNgPqMUrAp0ygrAMj8023OKOLSUD/qk1gPxGbVY/OHbUkIQr1c+qPuFHhf iuf3frkGtnVsoMrpK2MxMkkVts9AN5O1da0dz0lGHImVYYYbUgFDJEkP/PTRqttKf28k 53W7GEYqmZIFf7AXT94NRfkeV67qlHvTmrjHswIsNtVcboXFUbQN4w/49KRxKwtSngHR D6D4slxcXfjNNSCkH2WsOAaiiZjQQiIjZU4PvxfeYc13ocAGrIWHHN9OzEsY3saIsggT Gyrw==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ardentperf-com.20251104.gappssmtp.com; s=20251104; t=1783288494; x=1783893294; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=RJ1Ya5PxAfOD2z0w2+54NdGoqW4Ku1NaPEjt9azgiZ0=; b=HbdCVKc46W7mg3a5h3+LckuI9G8pTF0z5Lp0VETfghm3DV4VYyH0S0AW/uVgv0ovAZ +pjVa5vZaMFbTUTNVA4LpEhfqlf1yTgyyLFrETQtBf5JqFaVFr07StV0x5gONC/CrCiW ng7u2XJ+GdcOow9vrRmFLXKK+5RYYTVT0ypx0fLZKgSyPDxC+Hlq707mkvZdiKozUGb2 y7m83Io2inP7DI5JPMO+8m9hKfLGhBT892OSGIXENaiTM9DcPfkFTdDSOXFL6wkNpoAf gDYVheb05AtvkYHFJXzdyN3ky7NNn2AQtLM/hNCgG609iY0PMP4k579OYp6mbNdSEsSv 9b8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783288494; x=1783893294; h=to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RJ1Ya5PxAfOD2z0w2+54NdGoqW4Ku1NaPEjt9azgiZ0=; b=i1dvgpbUuFDynz4EATaPRZ0IjLdg0Acpi85fsHQJW/UobI350FPQ4HfQyEh1p7Onrx DIyT5vql7XQWhovY8dlqv6ryAC8nst0eQJOTOcQkYZtsrVwtTKK579WL0fTp4PgvTsjp titLYtXP9c7r8sHLytFCYh1zuxlLL578T1uOqQrIJX9rpbl7iY8dMx7cQMKpLKx7oyqw p3lNWGIMo6vRrZN1iqqhTwDxnZEtRLhSXfzZ+tLfq//6EjbEdx49bLKuEosrltxBeC75 5e9eVzayIlmMno8MC852UD2F991pC2mgA8GqLalEBihm01NId6yBqO2OQfgJVp3zfIXi rJsQ== X-Gm-Message-State: AOJu0YxFjXBbF0MXVr6ylVueTv7+ijJ+6tbU7QtobXjv0+PD24L/kN1l jMhSp518G6Euo4CdW7Vbf4ZpQtLUyNlLApPr63lK5vl82bHFUcTqg8JeETFrKS3LLMi2ZQZ6e5Y 78SqhzvGKG70j4JKR5yuBgFjPI1gHp+TyxORPvT/xT6B7Tar5aC5PmZTA X-Gm-Gg: AfdE7cmce686za3IOSXE8OcLeJbKhebVvbdawh+b4PhUfvV8zsuYYgmVSFp2p5mseco 0ENQ0jIbqvdMGzcz/7FlBn5Ft++cfws955vECMsBtStiQHfCxPZdJw33hJdTb8WBZbbOoqgpSuf hGhsmCq7gMcKNbOfNPfYHdJb74OKvpCdSIQ0GDbBK7ksS8NPHZr/JMpHxkSM6HfZ61S+/XzrEPH dKARa2GRxHWPMMbFXGIF387a53bbD7kCLMz6yhwQ3bRzfE5YxQr4NKhALXctYVZN/szVnEN4UHA PTAMCgNSnW1+LhTqwc2QIp4JWbNV X-Received: by 2002:a2e:bd12:0:b0:39a:e32c:1b1 with SMTP id 38308e7fff4ca-39b54051bd0mr13290991fa.19.1783288493394; Sun, 05 Jul 2026 14:54:53 -0700 (PDT) MIME-Version: 1.0 From: Jeremy Schneider Date: Sun, 5 Jul 2026 14:54:42 -0700 X-Gm-Features: AVVi8CfnnOyNe5b6xtT3RgEME5J54Fx3WZWgVYMqp1ulkrvN2YGpNsVVVLTw6_g Message-ID: Subject: hang during shutdown To: PostgreSQL mailing lists Content-Type: multipart/alternative; boundary="0000000000002e57b90655e43504" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000002e57b90655e43504 Content-Type: text/plain; charset="UTF-8" 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. :) 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. i'm pretty stumped! my plan right now is to work on the automation that fires the SIGKILL and just have it collect and log everything it can from /proc/pid/* before the kill. if this happens again we should get a little more info to go on. if anyone else has thoughts or ideas to add, lmk -Jeremy -- http://about.me/jeremy_schneider --0000000000002e57b90655e43504 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
i recently saw a hung shutdown on a busy multi-TB pro= duction database. the hung shutdown had some unexpected downstream impacts = unrelated to core postgres which turned a routine maintenance operation int= o a long dramatic overnight incident... blowing way past our planned maint = window and spoiling my weekend... but that's another story and mainly j= ust explains my stubborn persistence slowly following the dominoes backward= s over this past month. =C2=A0:)

so far, it all started with this po= stgres 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 postgre= s 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 wha= t i do know, in case anyone else has seen something similar.

postgre= s version 16.13
Ubuntu 22.04.5 LTS
kernel 5.15.0-1110-azure

be= tween log messages and wal contents, it appears PostmasterStateMachine tran= sitioned 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 wa= s shut down before maint started, at hang time there were only three open &= quot;postgres" user connections from platform automation.

here&= #39;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 immediat= e checkpoint (explicit from automation), same running xid

04:25:09.8= 08 pg logs the fast shutdown req (pg_ctl stop -m fast from automation)
<= br>04:25:09.815 both autovac workers log "terminating autovacuum proce= ss": die() -> ProcessInterrupts() -> ereport()

04:30:09 X= LOG_SWITCH and archiver uploads segment 0x30

04:30:10 checkpooint_ti= meout=3D300s fires, 72 dirty buffers written. RUNNING_XACTS at this time sh= ows 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 w= as never any XLOG_CHECKPOINT_SHUTDOWN record or any XLOG_XACT_ABORT record = written in the whole 30 minutes.

AI tells me autovac process needs t= o call AbortTransaction() which calls ProcArrayEndTransaction() to remove x= id from PGPROC and also calls RecordTransactionAbort() which should write t= he abort WAL record. neither of these happen, which suggests autovac was st= uck 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 obviou= s places where theres disk or network calls or anything else that could han= g.

successful checkpoints suggest that both the data and the wal dis= ks 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.

i'm pretty stumped!

my plan right n= ow is to work on the automation that fires the SIGKILL and just have it col= lect and log everything it can from /proc/pid/* before the kill. if this ha= ppens again we should get a little more info to go on.

if anyone els= e has thoughts or ideas to add, lmk

-Jeremy

= --
--0000000000002e57b90655e43504--