-
Notifications
You must be signed in to change notification settings - Fork 163
Add more fine grained event trigger for automatic schema cache reloading #445
Comments
For future reference:
|
A problem with the current event trigger is that a Just reproduced it with a function like: create or replace function what() returns text as $$
create temp table if not exists wut();
select 'what'::text
$$ language sql; Each call with POST will print:
A GET does fail: {"hint":null,"details":null,"code":"25006","message":"cannot execute CREATE TABLE in a read-only transaction"} This of course affects the performance of functions that use temp tables for internal logic. |
@wolfgangwalther Can you remind me why we need collations? I've settled on the following function for now(also took event trigger matrix as reference), since there's no event for CREATE OR REPLACE FUNCTION pgrst_watch() RETURNS event_trigger AS $$
DECLARE
obj record;
BEGIN
IF tg_tag IN (
-- schemas
'CREATE SCHEMA', 'ALTER SCHEMA', 'DROP SCHEMA'
-- tables
, 'CREATE TABLE', 'CREATE TABLE AS', 'SELECT INTO', 'ALTER TABLE', 'DROP TABLE'
-- foreign tables
, 'CREATE FOREIGN TABLE', 'ALTER FOREIGN TABLE', 'DROP FOREIGN TABLE'
-- views
, 'CREATE VIEW', 'ALTER VIEW', 'DROP VIEW'
-- materialized views
, 'CREATE MATERIALIZED VIEW', 'ALTER MATERIALIZED VIEW', 'DROP MATERIALIZED VIEW'
-- functions
, 'CREATE FUNCTION', 'ALTER FUNCTION', 'DROP FUNCTION'
-- procedures
, 'CREATE PROCEDURE', 'ALTER PROCEDURE', 'DROP PROCEDURE'
-- triggers
, 'CREATE TRIGGER', 'DROP TRIGGER'
-- types
, 'CREATE TYPE', 'DROP TYPE'
-- rules
, 'CREATE RULE', 'DROP RULE'
-- drops many types of objects
, 'DROP OWNED'
) AND
-- don't notify in case of CREATE TEMP table or other objects created on pg_temp
'pg_temp' NOT IN (SELECT schema_name FROM pg_event_trigger_ddl_commands())
THEN
RAISE NOTICE '%', tg_tag;
NOTIFY pgrst, 'reload schema';
END IF;
END;
$$ LANGUAGE plpgsql; |
Only triggering on the schemas in For solving that I think we need a new |
I assumed we'd need it because of the following two lines in the But it seems like this is a
I would have to try to reproduce this, but I think this might lead to problems. Maybe something more like this? EXISTS (SELECT 1 FROM pg_event_trigger_ddl_commands WHERE schema_name <> 'pg_temp')
Even if in-db configuration is used, we still wouldn't know the username of the authenticator - so it's not clear to me how we would even query for those settings? But restricting this to the schemas in |
Yeah, the docs say:
https://www.postgresql.org/docs/13/functions-event-triggers.html Asked on IRC:
So I guess another schema that needs to be excluded is Tried changing the logic of the above to instead iterate over |
The above behavior is documented here: https://www.postgresql.org/docs/current/event-trigger-definition.html So unfortunately it seems we'll need two event triggers, one with |
Right now https://postgrest.org/en/v8.0/schema_cache.html#automatic-schema-cache-reloading reloads on every DDL change but we don't need to reload on changes on triggers, grants, policies, etc.
See PostgREST/postgrest#1512 (comment) for a basic idea on how to do a more fine grained even trigger.
The text was updated successfully, but these errors were encountered: