| From: | Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
| Cc: | Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi> |
| Subject: | RegisterShmemCallbacks() does nothing in single-user mode |
| Date: | 2026-08-21 05:36:11 |
| Message-ID: | CAJTYsWU7epjUL1-xrpYeOrmkmq20M2Q22Y_SRb8PWQG8KNQyDw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Looking at the after-startup path from 283e823f9dc, I noticed that
RegisterShmemCallbacks() does not do anything useful in single-user mode.
The branch that does the work immediately is guarded by:
if (shmem_request_state == SRS_DONE && IsUnderPostmaster)
IsUnderPostmaster is false in a standalone backend as well as in the
postmaster, so a standalone backend always falls through to the "remember
the callbacks for later" branch, and startup has already consumed that
list. An extension loaded at runtime there, e.g. with LOAD or CREATE
EXTENSION, therefore never has its callbacks called, and
RegisterShmemCallbacks() reports nothing:
LOG: test_shmem module's _PG_init called
ERROR: shmem area not attached or initialized in this process
The LOG line is the only trace of the registration. The ERROR is
test_shmem's own guard when the area is later used, not the shmem code;
an extension without such a guard would dereference a NULL pointer?
I am unsure whether this was left out intentionally or simply missed, but
it seems worth having: a standalone backend has shared memory and the
same after-startup reserve, and a silent no-op is easy to mistake for
success.
The attached patch also checks !IsPostmasterEnvironment and adds a
single-user case to the test_shmem TAP test.
Thoughts?
Regards,
Ayush
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Fix-after-startup-shmem-allocation-in-single-user.patch | application/octet-stream | 2.7 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Ian Lawrence Barwick | 2026-08-21 05:47:46 | Re: [PATCH] doc: clarify AS requirement when VALUES used in a FROM clause |
| Previous Message | Bharath Rupireddy | 2026-08-21 05:19:01 | Re: postgres_fdw: Fix flaky push down FUNCTION RTE test |