diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml index 5e5c141e178..c85cb15c341 100644 --- a/doc/src/sgml/ref/pg_dump.sgml +++ b/doc/src/sgml/ref/pg_dump.sgml @@ -928,6 +928,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 0d77a4836ae..417048c41e0 100644 --- a/doc/src/sgml/ref/pg_dumpall.sgml +++ b/doc/src/sgml/ref/pg_dumpall.sgml @@ -433,6 +433,16 @@ 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 d3065210c7f..9e4e56a6887 100644 --- a/doc/src/sgml/ref/pg_restore.sgml +++ b/doc/src/sgml/ref/pg_restore.sgml @@ -653,6 +653,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 3c1cd858a85..cf683d66e42 100644 --- a/src/bin/pg_dump/pg_backup.h +++ b/src/bin/pg_dump/pg_backup.h @@ -77,6 +77,7 @@ typedef struct _restoreOptions int createDB; /* Issue commands to create the database */ int noOwner; /* Don't try to match original object owner */ 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 @@ -164,6 +165,7 @@ typedef struct _dumpOptions int serializable_deferrable; int disable_triggers; 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 6d4a610d191..9dd3e24157d 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -204,6 +204,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; @@ -2856,6 +2857,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 7d83dda2124..f19fcb34796 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -382,6 +382,7 @@ main(int argc, char **argv) {"inserts", no_argument, NULL, 9}, {"lock-wait-timeout", required_argument, NULL, 2}, {"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}, @@ -966,6 +967,7 @@ main(int argc, char **argv) ropt->createDB = dopt.outputCreateDB; ropt->noOwner = dopt.outputNoOwner; 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; @@ -1072,6 +1074,7 @@ help(const char *progname) printf(_(" --no-subscriptions do not dump subscriptions\n")); printf(_(" --no-synchronized-snapshots do not use synchronized snapshots in parallel jobs\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")); @@ -6214,6 +6217,15 @@ getFuncs(Archive *fout, int *numFuncs) * pg_catalog if they have an ACL different from what's shown in * pg_init_privs. */ + + /* + * 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) { PQExpBuffer acl_subquery = createPQExpBuffer(); @@ -6244,6 +6256,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')" @@ -6264,6 +6277,7 @@ getFuncs(Archive *fout, int *numFuncs) initracl_subquery->data, username_subquery, not_agg_check, + not_event_trigger_check, g_last_builtin_oid, g_last_builtin_oid); if (dopt->binary_upgrade) @@ -6292,8 +6306,10 @@ getFuncs(Archive *fout, int *numFuncs) "pronamespace, " "(%s proowner) AS rolname " "FROM pg_proc p " - "WHERE NOT proisagg", - username_subquery); + "WHERE NOT proisagg" + "%s", + username_subquery, + not_event_trigger_check); if (fout->remoteVersion >= 90200) appendPQExpBufferStr(query, "\n AND NOT EXISTS (SELECT 1 FROM pg_depend " @@ -8450,6 +8466,13 @@ getEventTriggers(Archive *fout, int *numEventTriggers) return NULL; } + if (fout->dopt->no_event_triggers) + { + pg_log_info("skipping event triggers"); + *numEventTriggers = 0; + return NULL; + } + query = createPQExpBuffer(); appendPQExpBuffer(query, diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 9ab05f74cc2..d65aa83ab6f 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -78,6 +78,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; @@ -144,6 +145,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}, @@ -430,6 +432,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) @@ -654,6 +658,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-tablespaces do not dump tablespace assignments\n")); printf(_(" --no-toast-compression do not dump TOAST compression methods\n")); diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c index 589b4aed539..9a48e5f9d98 100644 --- a/src/bin/pg_dump/pg_restore.c +++ b/src/bin/pg_dump/pg_restore.c @@ -71,6 +71,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[] = { @@ -376,6 +377,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) { @@ -499,6 +501,7 @@ usage(const char *progname) printf(_(" --no-publications do not restore publications\n")); printf(_(" --no-security-labels do not restore security labels\n")); printf(_(" --no-subscriptions do not restore subscriptions\n")); + printf(_(" --no-event-triggers do not restore event triggers\n")); printf(_(" --no-tablespaces do not restore tablespace assignments\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" diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl index da7578709e5..e1dddaa81c7 100644 --- a/src/bin/pg_dump/t/002_pg_dump.pl +++ b/src/bin/pg_dump/t/002_pg_dump.pl @@ -247,6 +247,13 @@ '--no-toast-compression', 'postgres', ], }, + no_event_triggers => { + dump_cmd => [ + 'pg_dump', '--no-sync', + "--file=$tempdir/no_event_triggers.sql", + '--no-event-triggers', 'postgres', + ], + }, no_blobs => { dump_cmd => [ 'pg_dump', '--no-sync', @@ -417,6 +424,7 @@ exclude_test_table => 1, exclude_test_table_data => 1, no_toast_compression => 1, + no_event_triggers => 1, no_blobs => 1, no_owner => 1, no_privs => 1, @@ -1625,7 +1633,10 @@ \$\$;/xm, like => { %full_runs, %dump_test_schema_runs, section_pre_data => 1, }, - unlike => { exclude_dump_test_schema => 1, }, + unlike => { + exclude_dump_test_schema => 1, + no_event_triggers => 1, + }, }, 'CREATE OPERATOR FAMILY dump_test.op_family' => { @@ -1726,6 +1737,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' => { @@ -2935,6 +2949,7 @@ exclude_test_table => 1, exclude_test_table_data => 1, no_toast_compression => 1, + no_event_triggers => 1, no_blobs => 1, no_privs => 1, no_owner => 1, @@ -3008,6 +3023,7 @@ exclude_test_table => 1, exclude_test_table_data => 1, no_toast_compression => 1, + no_event_triggers => 1, no_blobs => 1, no_privs => 1, no_owner => 1,