[PATCH] Add permit_unlogged_tables GUC to control unlogged table creation.

Started by harinath kanchu11 months ago3 messageshackers

Thread notes

1 note#feature#moderate#enhancement
hackorum-bot#feature#moderate#enhancement
hackorum-bot
1 day ago

@global #feature #moderate #enhancement

#feature#moderate#enhancement
Jump to latest
#1harinath kanchu
kanchuharinath@gmail.com

Hello,
This patch implements a new GUC parameter "permit_unlogged_tables" which
allows admins to disable creation of unlogged tables or altering the
existing tables to be unlogged.

This is useful in environments with strict compliance requirements as well
as multi-tenant environments where the provider needs to guarantee
durability of customer data.

The default is "true", which is to say that behavior would remain unchanged.

Implementation
- Boolean GUC with PGC_SIGHUP context (reloadable without restart)
- Check in "DefineRelation()" to block "CREATE UNLOGGED TABLE" commands.
- Check in "ATPrepCmd()" to block "ALTER TABLE SET UNLOGGED" commands.
- "ALTER TABLE SET LOGGED" commands remain unaffected and should always
work.

Attached the patch for review. Happy to make adjustments based on feedback.

Thanks !

Best,
Harinath

Attachments:

t53082_1
v1-0001-Add-permit_unlogged_tables-GUC-to-control-unlogge.patchapplication/octet-stream; name=v1-0001-Add-permit_unlogged_tables-GUC-to-control-unlogge.patchDownload+370-1
#2David G. Johnston
david.g.johnston@gmail.com
In reply to: harinath kanchu (#1)
Re: [PATCH] Add permit_unlogged_tables GUC to control unlogged table creation.

On Tue, Jan 13, 2026 at 1:48 PM harinath kanchu <kanchuharinath@gmail.com>
wrote:

This patch implements a new GUC parameter "permit_unlogged_tables" which
allows admins to disable creation of unlogged tables or altering the
existing tables to be unlogged.

I dislike the premise of this option. It doesn't seem like something that
should be evaluated on a cluster/database scope.

David J.

#3Greg Sabino Mullane
htamfids@gmail.com
In reply to: David G. Johnston (#2)
Re: [PATCH] Add permit_unlogged_tables GUC to control unlogged table creation.

On Tue, Jan 13, 2026 at 4:14 PM David G. Johnston <
david.g.johnston@gmail.com> wrote:

I dislike the premise of this option. It doesn't seem like something that
should be evaluated on a cluster/database scope.

Indeed. OP, we already have a mechanism to support this: event triggers.
Quick example:

create or replace function unlogged_be_gone() returns event_trigger
language plpgsql as $$
declare myrec record;
begin
for myrec in select * from pg_event_trigger_ddl_commands() loop
if myrec.command_tag = 'CREATE TABLE' OR myrec.command_tag = 'ALTER
TABLE' then
perform 1 from pg_class where oid = myrec.objid and relpersistence =
'u';
if found then
raise 'Tables may not be created or changed to unlogged!';
end if;
end if;
end loop;
end
$$;

create event trigger etest on ddl_command_end execute function
unlogged_be_gone();

Cheers,
Greg

--
Crunchy Data - https://www.crunchydata.com
Enterprise Postgres Software Products & Tech Support