Re: [PATCH] Add permit_unlogged_tables GUC to control unlogged table creation.
| От | Greg Sabino Mullane |
|---|---|
| Тема | Re: [PATCH] Add permit_unlogged_tables GUC to control unlogged table creation. |
| Дата | |
| Msg-id | CAKAnmmK4DXes01TX9q+9rTOvLsOFCNXSdOKcB=__nBM=Gv_Wjw@mail.gmail.com обсуждение исходный текст |
| Ответ на | Re: [PATCH] Add permit_unlogged_tables GUC to control unlogged table creation. ("David G. Johnston" <david.g.johnston@gmail.com>) |
| Список | pgsql-hackers |
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();
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
В списке pgsql-hackers по дате отправления: