File: hook-after-create.sql

package info (click to toggle)
postgis 3.6.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 74,680 kB
  • sloc: ansic: 163,427; sql: 95,196; xml: 54,290; cpp: 12,646; perl: 5,875; sh: 5,415; makefile: 3,492; python: 1,207; yacc: 447; lex: 151; pascal: 58
file content (29 lines) | stat: -rw-r--r-- 977 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
--
-- Disable autovacuum on the tables created as part of the test suite
-- to make sure autovacuum does not run VACUUM or ANALYZE on the tables
-- created by the test suite.
--
-- Some of the tests are designed with the assumption that ANALYZE will
-- only be run explicitly, and not from an external source like autovacuum.
--

CREATE OR REPLACE FUNCTION trg_test_disable_table_autovacuum()
RETURNS event_trigger
LANGUAGE plpgsql
AS $$
DECLARE
    obj record;
BEGIN
    FOR obj IN SELECT * FROM pg_event_trigger_ddl_commands() WHERE command_tag in ('CREATE TABLE','CREATE TABLE AS')
    LOOP
        IF obj.object_identity = 'public.spatial_ref_sys' THEN
            CONTINUE;
        END IF;
        EXECUTE format('ALTER TABLE %s SET (autovacuum_enabled = false);',obj.object_identity);
    END LOOP;
END;
$$;

CREATE EVENT TRIGGER trg_autovac_disable ON ddl_command_end
WHEN TAG IN ('CREATE TABLE','CREATE TABLE AS')
EXECUTE PROCEDURE trg_test_disable_table_autovacuum();