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.98.2) (envelope-from ) id 1xHNUJ-00000002yGG-1i8q for pgsql-bugs@arkaria.postgresql.org; Thu, 15 Oct 2026 15:35:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xHNUH-00000009n5l-3gSH for pgsql-bugs@arkaria.postgresql.org; Thu, 15 Oct 2026 15:35:21 +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.98.2) (envelope-from ) id 1xHN21-00000009V0f-0wtg for pgsql-bugs@lists.postgresql.org; Thu, 15 Oct 2026 15:06:09 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xHN1z-00000002GNB-0rLZ for pgsql-bugs@lists.postgresql.org; Thu, 15 Oct 2026 15:06:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=DDk5M4uiU8sd+zFv2S+COpR/2qio4WN1JIiUTt7Dpgg=; b=uNB+1JVYl+Y6MKFrGk/jW/vcCv dEavhLyGYwDizuUQiAfMD6RdGmmNXYFu3OHyHQJvn0bw2KfK9ANLSYqSx5F4fS9nVomhJMGuO1NfW SXhHXC/aUR27xf+J6Sm7gWCCp6LChjosODcGGAQt4IeNPdy4FUhnDm165gjhtzH3fA0MAiqW1zZ3i T5jPXWFbAfQY2xbHIERGU7ML/KxCcCI28PlYwh+db0QRa0ob58cOe6H15Srr4KkiJb9E+JarQrc6O RnnBZ8QHTcg5wwCPTc+vF/gc3RDCDfhT4pOo6FwStz/WvXPLJjv2T1W5jISHqBvZUs2UwWthLgAaN kXUMWa9g==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xHN1w-00000006IyF-3wlP for pgsql-bugs@lists.postgresql.org; Thu, 15 Oct 2026 15:06:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xHN1v-00000001iJJ-25AE for pgsql-bugs@lists.postgresql.org; Thu, 15 Oct 2026 15:06:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19764: ManualBug3 Assert failure in pgstat_setup_shared_refs crashes initdb post-bootstrap subprocess To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 1217816127@qq.com Reply-To: 1217816127@qq.com, pgsql-bugs@lists.postgresql.org Date: Thu, 15 Oct 2026 15:05:32 +0000 Message-ID: <19764-dbbe7e43001dede5@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19764 Logged by: Yuelin Wang Email address: 1217816127@qq.com PostgreSQL version: 19rc1 Operating system: Linux (Ubuntu 24.04, x86_64) Description: =20 ### What happens? During `initdb`, the "performing post-bootstrap initialization" subprocess calls `pgstat_initialize()` (which sets `pgStatLocal.shmem->gc_request_count =3D 1` via `StatsShmemInit`), then calls `StartupXLOG()`. Inside `StartupXLOG()`, `pgstat_restore_stats()` is invoked. After `pgstat_restore_stats()` completes, `gc_request_count` has been zeroed out to 0 (verified via debug instrumentation in the working-tree build). Later, during catalog initialization (`InitPostgres` calls `table_beginscan_catalog`, which calls `heap_beginscan`, which calls `pgstat_assoc_relation`), `pgstat_get_entry_ref` is invoked for the first time in this subprocess. This triggers `pgstat_setup_shared_refs()` (src/backend/utils/activity/pgstat_shmem.c), which reads `pgStatSharedRefAge =3D pg_atomic_read_u64(&pgStatLocal.shmem->gc_request_count)` and gets 0. Immediately after, the function asserts `Assert(pgStatSharedRefAge !=3D 0)`= at pgstat_shmem.c:939, which fires and aborts the subprocess, causing initdb to fail and clean up the data directory. The violated invariant is: `gc_request_count` must remain at its initialized value (1) and never fall to 0, since `pgstat_setup_shared_refs` relies on a non-zero value to guarantee `pgStatSharedRefAge !=3D 0`. The `own_hash` feature introduced in commit 44539786b8 added `entry_counts`, `kind_hash_handles`, and `raw_kind_dsa_area` arrays to `PgStat_ShmemControl`, altering the struct layout and the initialization sequence in `pgstat_restore_stats`/`pgstat_read_statsfile`. The debug trace confirms that `gc_request_count` transitions from 1 to 0 precisely during `pgstat_restore_stats()`. This matches the Entry91 root-cause pattern: a field that must be initialized to a sentinel non-zero value before use is inadvertently reset to the uninitialized zero value by a code path that was modified by the same recent commit. ### To Reproduce Start a fresh PostgreSQL ASAN instance with initdb: ```sh TMPDIR=3D$(mktemp -d /tmp/pg_scan_XXXX) DATADIR=3D$TMPDIR/pgdata PGUSER=3D$(whoami) ASAN_OPTIONS=3Ddetect_leaks=3D0:abort_on_error=3D0:log_path=3D$TMPDIR/asan \ /data/ylwang/Projects/DirectedDB/latesttarget/postgre/build_asan/install/bi= n/initdb \ -D $DATADIR -U $PGUSER --no-locale --encoding=3DUTF8 2>&1 ``` Trigger output: ``` The files belonging to this database system will be owned by user "yuelinwang". This user must also own the server process. The database cluster will be initialized with locale "C". The default text search configuration will be set to "english". Data page checksums are enabled. creating directory .../pgdata ... ok creating subdirectories ... ok selecting dynamic shared memory implementation ... posix selecting default "max_connections" ... 100 selecting default "shared_buffers" ... 128MB selecting default time zone ... Asia/Singapore creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... TRAP: failed Assert("pgStatSharedRefAge !=3D 0"), File: "pgstat_shmem.c", Line: 939, PID: 3146498 /lib/x86_64-linux-gnu/libasan.so.8(+0x831e0)[...] .../postgres(ExceptionalCondition+0x165)[...] .../postgres(+0x14c282a)[...] .../postgres(pgstat_get_entry_ref+0x33b)[...] .../postgres(pgstat_prep_pending_entry+0x37)[...] .../postgres(+0x14b9ee9)[...] .../postgres(pgstat_assoc_relation+0x1f7)[...] .../postgres(+0x5a3a24)[...] .../postgres(heap_beginscan+0x8c0)[...] .../postgres(+0x6e832b)[...] .../postgres(table_beginscan_catalog+0x9a)[...] .../postgres(+0x1963b82)[...] .../postgres(InitPostgres+0x63a)[...] .../postgres(PostgresMain+0x553)[...] .../postgres(main+0x5d5)[...] Aborted (core dumped) child process exited with exit code 134 initdb: removing data directory ".../pgdata" ``` The assertion failure prevents initdb from completing and the data directory is cleaned up automatically. ### Environment - OS: Ubuntu 24.04.2 LTS, x86_64 (Linux 6.8.0-55-generic) - PostgreSQL Version: PostgreSQL 20devel (from build_asan/install/bin/postgres --version) - Client: initdb, ASAN instrumented build (built from source with -fsanitize=3Daddress) - Hardware: N/A ### Identity Disclosure - Full Name: Yuelin - Affiliation: Individual