diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml index ec8ea8fd985..6b03cbdc733 100644 --- a/doc/src/sgml/ref/pg_dump.sgml +++ b/doc/src/sgml/ref/pg_dump.sgml @@ -974,6 +974,15 @@ PostgreSQL documentation + + + + + Do not dump event triggers. + + + + diff --git a/doc/src/sgml/ref/pg_dumpall.sgml b/doc/src/sgml/ref/pg_dumpall.sgml index ba005ff19e2..53f6d29a161 100644 --- a/doc/src/sgml/ref/pg_dumpall.sgml +++ b/doc/src/sgml/ref/pg_dumpall.sgml @@ -391,6 +391,15 @@ PostgreSQL documentation + + + + + Do not dump event triggers. + + + + diff --git a/doc/src/sgml/ref/pg_restore.sgml b/doc/src/sgml/ref/pg_restore.sgml index a81583191c1..aaf7d1ca734 100644 --- a/doc/src/sgml/ref/pg_restore.sgml +++ b/doc/src/sgml/ref/pg_restore.sgml @@ -623,6 +623,16 @@ PostgreSQL documentation + + + + + Do not output commands to restore event triggers, even if the archive + contains them. + + + + diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h index aba780ef4b1..5ed7fe9a8c9 100644 --- a/src/bin/pg_dump/pg_backup.h +++ b/src/bin/pg_dump/pg_backup.h @@ -96,6 +96,7 @@ typedef struct _restoreOptions int noOwner; /* Don't try to match original object owner */ int noTableAm; /* Don't issue table-AM-related commands */ int noTablespace; /* Don't issue tablespace-related commands */ + int no_event_triggers; /* Don't dump event triggers */ int disable_triggers; /* disable triggers during data-only * restore */ int use_setsessauth; /* Use SET SESSION AUTHORIZATION commands @@ -184,6 +185,7 @@ typedef struct _dumpOptions int disable_triggers; int outputNoTableAm; int outputNoTablespaces; + int no_event_triggers; int use_setsessauth; int enable_row_security; int load_via_partition_root; diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 3448aba12f4..7eef30ddb96 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -201,6 +201,7 @@ dumpOptionsFromRestoreOptions(RestoreOptions *ropt) dopt->no_publications = ropt->no_publications; dopt->no_security_labels = ropt->no_security_labels; dopt->no_subscriptions = ropt->no_subscriptions; + dopt->no_event_triggers = ropt->no_event_triggers; dopt->lockWaitTimeout = ropt->lockWaitTimeout; dopt->include_everything = ropt->include_everything; dopt->enable_row_security = ropt->enable_row_security; @@ -2854,6 +2855,10 @@ _tocEntryRequired(TocEntry *te, teSection curSection, ArchiveHandle *AH) if (ropt->no_subscriptions && strcmp(te->desc, "SUBSCRIPTION") == 0) return 0; + /* If it's an event trigger, maybe ignore it */ + if (ropt->no_event_triggers && strcmp(te->desc, "EVENT TRIGGER") == 0) + return 0; + /* Ignore it if section is not to be dumped/restored */ switch (curSection) { diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index ba71c0b0f32..a3a30d0febf 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -411,6 +411,7 @@ main(int argc, char **argv) {"lock-wait-timeout", required_argument, NULL, 2}, {"no-table-access-method", no_argument, &dopt.outputNoTableAm, 1}, {"no-tablespaces", no_argument, &dopt.outputNoTablespaces, 1}, + {"no-event-triggers", no_argument, &dopt.no_event_triggers, 1}, {"quote-all-identifiers", no_argument, "e_all_identifiers, 1}, {"load-via-partition-root", no_argument, &dopt.load_via_partition_root, 1}, {"role", required_argument, NULL, 3}, @@ -1004,6 +1005,7 @@ main(int argc, char **argv) ropt->noOwner = dopt.outputNoOwner; ropt->noTableAm = dopt.outputNoTableAm; ropt->noTablespace = dopt.outputNoTablespaces; + ropt->no_event_triggers = dopt.no_event_triggers; ropt->disable_triggers = dopt.disable_triggers; ropt->use_setsessauth = dopt.use_setsessauth; ropt->disable_dollar_quoting = dopt.disable_dollar_quoting; @@ -1116,6 +1118,7 @@ help(const char *progname) printf(_(" --no-subscriptions do not dump subscriptions\n")); printf(_(" --no-table-access-method do not dump table access methods\n")); printf(_(" --no-tablespaces do not dump tablespace assignments\n")); + printf(_(" --no-event-triggers do not dump event triggers\n")); printf(_(" --no-toast-compression do not dump TOAST compression methods\n")); printf(_(" --no-unlogged-table-data do not dump unlogged table data\n")); printf(_(" --on-conflict-do-nothing add ON CONFLICT DO NOTHING to INSERT commands\n")); @@ -6233,6 +6236,15 @@ getFuncs(Archive *fout, int *numFuncs) * pg_catalog if they have an ACL different from what's shown in * pg_init_privs (so we have to join to pg_init_privs; annoying). */ + + /* + * If --no-event-triggers is specified, exclude functions that return + * event triggers. + */ + const char *not_event_trigger_check; + + not_event_trigger_check = (fout->dopt->no_event_triggers ? "\n AND p.prorettype <> 'pg_catalog.event_trigger'::regtype" : " "); + if (fout->remoteVersion >= 90600) { const char *not_agg_check; @@ -6253,6 +6265,7 @@ getFuncs(Archive *fout, int *numFuncs) "AND pip.classoid = 'pg_proc'::regclass " "AND pip.objsubid = 0) " "WHERE %s" + "%s" "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " "WHERE classid = 'pg_proc'::regclass AND " "objid = p.oid AND deptype = 'i')" @@ -6268,6 +6281,7 @@ getFuncs(Archive *fout, int *numFuncs) "\n (p.oid = pg_transform.trffromsql" "\n OR p.oid = pg_transform.trftosql))", not_agg_check, + not_event_trigger_check, g_last_builtin_oid, g_last_builtin_oid); if (dopt->binary_upgrade) @@ -6291,6 +6305,7 @@ getFuncs(Archive *fout, int *numFuncs) "proowner " "FROM pg_proc p " "WHERE NOT proisagg" + "%s" "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " "WHERE classid = 'pg_proc'::regclass AND " "objid = p.oid AND deptype = 'i')" @@ -6301,6 +6316,7 @@ getFuncs(Archive *fout, int *numFuncs) "\n OR EXISTS (SELECT 1 FROM pg_cast" "\n WHERE pg_cast.oid > '%u'::oid" "\n AND p.oid = pg_cast.castfunc)", + not_event_trigger_check, g_last_builtin_oid); if (fout->remoteVersion >= 90500) @@ -8077,6 +8093,13 @@ getEventTriggers(Archive *fout, int *numEventTriggers) *numEventTriggers = 0; return NULL; } + + if (fout->dopt->no_event_triggers) + { + pg_log_info("skipping event triggers"); + *numEventTriggers = 0; + return NULL; + } query = createPQExpBuffer(); diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 9d8732ac736..4277e98b8b7 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -105,6 +105,7 @@ static int no_publications = 0; static int no_security_labels = 0; static int no_subscriptions = 0; static int no_toast_compression = 0; +static int no_event_triggers = 0; static int no_unlogged_table_data = 0; static int no_role_passwords = 0; static int server_version; @@ -172,6 +173,7 @@ main(int argc, char *argv[]) {"no-role-passwords", no_argument, &no_role_passwords, 1}, {"no-security-labels", no_argument, &no_security_labels, 1}, {"no-subscriptions", no_argument, &no_subscriptions, 1}, + {"no-event-triggers", no_argument, &no_event_triggers, 1}, {"no-sync", no_argument, NULL, 4}, {"no-toast-compression", no_argument, &no_toast_compression, 1}, {"no-unlogged-table-data", no_argument, &no_unlogged_table_data, 1}, @@ -448,6 +450,8 @@ main(int argc, char *argv[]) appendPQExpBufferStr(pgdumpopts, " --no-security-labels"); if (no_subscriptions) appendPQExpBufferStr(pgdumpopts, " --no-subscriptions"); + if (no_event_triggers) + appendPQExpBufferStr(pgdumpopts, " --no-event-triggers"); if (no_toast_compression) appendPQExpBufferStr(pgdumpopts, " --no-toast-compression"); if (no_unlogged_table_data) @@ -662,6 +666,7 @@ help(void) printf(_(" --no-role-passwords do not dump passwords for roles\n")); printf(_(" --no-security-labels do not dump security label assignments\n")); printf(_(" --no-subscriptions do not dump subscriptions\n")); + printf(_(" --no-event-triggers do not dump event triggers\n")); printf(_(" --no-sync do not wait for changes to be written safely to disk\n")); printf(_(" --no-table-access-method do not dump table access methods\n")); printf(_(" --no-tablespaces do not dump tablespace assignments\n")); diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c index 049a1006347..3539eea096e 100644 --- a/src/bin/pg_dump/pg_restore.c +++ b/src/bin/pg_dump/pg_restore.c @@ -73,6 +73,7 @@ main(int argc, char **argv) static int no_publications = 0; static int no_security_labels = 0; static int no_subscriptions = 0; + static int no_event_triggers = 0; static int strict_names = 0; struct option cmdopts[] = { @@ -123,6 +124,7 @@ main(int argc, char **argv) {"no-publications", no_argument, &no_publications, 1}, {"no-security-labels", no_argument, &no_security_labels, 1}, {"no-subscriptions", no_argument, &no_subscriptions, 1}, + {"no-event-triggers", no_argument, &no_event_triggers, 1}, {NULL, 0, NULL, 0} }; @@ -351,6 +353,7 @@ main(int argc, char **argv) opts->no_publications = no_publications; opts->no_security_labels = no_security_labels; opts->no_subscriptions = no_subscriptions; + opts->no_event_triggers = no_event_triggers; if (if_exists && !opts->dropSchema) pg_fatal("option --if-exists requires option -c/--clean"); @@ -472,6 +475,7 @@ usage(const char *progname) printf(_(" --no-subscriptions do not restore subscriptions\n")); printf(_(" --no-table-access-method do not restore table access methods\n")); printf(_(" --no-tablespaces do not restore tablespace assignments\n")); + printf(_(" --no-event-triggers do not restore event triggers\n")); printf(_(" --section=SECTION restore named section (pre-data, data, or post-data)\n")); printf(_(" --strict-names require table and/or schema include patterns to\n" " match at least one entity each\n")); diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl index b633b95f0d7..48f366c42de 100644 --- a/src/bin/pg_dump/t/002_pg_dump.pl +++ b/src/bin/pg_dump/t/002_pg_dump.pl @@ -534,6 +534,13 @@ '-B', 'postgres', ], }, + no_event_triggers => { + dump_cmd => [ + 'pg_dump', '--no-sync', + "--file=$tempdir/no_event_triggers.sql", + '--no-event-triggers', 'postgres', + ], + }, no_privs => { dump_cmd => [ 'pg_dump', '--no-sync', @@ -720,6 +727,7 @@ exclude_measurement_data => 1, no_toast_compression => 1, no_large_objects => 1, + no_event_triggers => 1, no_owner => 1, no_privs => 1, no_table_access_method => 1, @@ -2114,6 +2122,7 @@ unlike => { exclude_dump_test_schema => 1, only_dump_measurement => 1, + no_event_triggers => 1, }, }, @@ -2227,6 +2236,9 @@ \n\s+\QEXECUTE FUNCTION dump_test.event_trigger_func();\E /xm, like => { %full_runs, section_post_data => 1, }, + unlike => { + no_event_triggers => 1, + }, }, 'CREATE TRIGGER test_trigger' => { @@ -3832,6 +3844,7 @@ no_privs => 1, no_owner => 1, no_table_access_method => 1, + no_event_triggers => 1, only_dump_test_schema => 1, pg_dumpall_dbprivs => 1, pg_dumpall_exclude => 1, @@ -3925,6 +3938,7 @@ no_large_objects => 1, no_privs => 1, no_owner => 1, + no_event_triggers => 1, no_table_access_method => 1, pg_dumpall_dbprivs => 1, pg_dumpall_exclude => 1,