File: hook-after-create.sql

package info (click to toggle)
postgis 3.5.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 69,528 kB
  • sloc: ansic: 162,229; sql: 93,970; xml: 53,139; cpp: 12,646; perl: 5,658; sh: 5,369; makefile: 3,435; python: 1,205; yacc: 447; lex: 151; pascal: 58
file content (29 lines) | stat: -rw-r--r-- 977 bytes parent folder | download | duplicates (6)
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();