Reject access to unlogged tables in contrib modules

Started by Jim Jones5 days ago1 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliessuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t254260
psql -h localhost -U postgres

Built from patchset v1 (message #1), October 22, 2026 at 03:21 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t254260_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t254260_1 && git checkout t254260_1

Patchset v1 (message #1) is on t254260_1

Jump to latest
#1Jim Jones
jim.jones@uni-muenster.de

Hi

A few contrib modules fail to handle unlogged relations during recovery,
which leads to rather unhelpful error messages:

== primary ==

create extension pgrowlocks;
create extension pgstattuple;
create extension pg_visibility;
create extension pageinspect;
create unlogged table ut as select 1;

== standby ==

psql (20devel)
Type "help" for help.

postgres=# select * from pgrowlocks('ut');
ERROR: could not open file "base/5/16458": No such file or directory
postgres=# select * from pgstattuple('ut');
ERROR: could not open file "base/5/16458": No such file or directory
postgres=# select * from pg_visibility('ut');
ERROR: could not open file "base/5/16458": No such file or directory
postgres=# select get_raw_page('ut',0);
ERROR: could not open file "base/5/16458": No such file or directory

Attached 4 patches adding checks to report a proper error message -- one
per module for easier reviewing:

psql (20devel)
Type "help" for help.

postgres=# select * from pgrowlocks('ut');
ERROR: cannot access temporary or unlogged relations during recovery
postgres=# select * from pgstattuple('ut');
ERROR: cannot access temporary or unlogged relations during recovery
postgres=# select * from pg_visibility('ut');
ERROR: cannot access temporary or unlogged relations during recovery
postgres=# select get_raw_page('ut',0);
ERROR: cannot access temporary or unlogged relations during recovery
postgres=#

I was unable to find any TAP test I could use to add these cases, and I
believe it could be an overkill to create one just to test these error
messages, so I decided to not include any tests for now. Let me know if
I am missing something here.

These bugs were reported by Zsolt (in CC) in another related thread[1]

Thanks!

Best, Jim

1 -
/messages/by-id/CAN4CZFMCuiya7d5sRQ-xm=hKnADiT_jrppSTo+a_WxktuPk2LQ@mail.gmail.com

Attachments:

t254260_1
v1-0001-pageinspect-Reject-unlogged-relations-during-reco.patchtext/x-patch; charset=UTF-8; name=v1-0001-pageinspect-Reject-unlogged-relations-during-reco.patchDownload+31-1
v1-0002-pgrowlocks-Reject-unlogged-tables-during-recovery.patchtext/x-patch; charset=UTF-8; name=v1-0002-pgrowlocks-Reject-unlogged-tables-during-recovery.patchDownload+7-1
v1-0003-pgstattuple-Reject-unlogged-relations-during-reco.patchtext/x-patch; charset=UTF-8; name=v1-0003-pgstattuple-Reject-unlogged-relations-during-reco.patchDownload+39-1
v1-0004-pg_visibility-Reject-unlogged-tables-during-recov.patchtext/x-patch; charset=UTF-8; name=v1-0004-pg_visibility-Reject-unlogged-tables-during-recov.patchDownload+19-1