Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/src/sgml/ref/pg_dump.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,15 @@ PostgreSQL documentation
</listitem>
</varlistentry>

<varlistentry>
<term><option>--no-event-triggers</option></term>
<listitem>
<para>
Do not dump event triggers.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--no-sync</option></term>
<listitem>
Expand Down
9 changes: 9 additions & 0 deletions doc/src/sgml/ref/pg_dumpall.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,15 @@ exclude database <replaceable class="parameter">PATTERN</replaceable>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--no-event-triggers</option></term>
<listitem>
<para>
Do not dump event triggers.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--no-sync</option></term>
<listitem>
Expand Down
10 changes: 10 additions & 0 deletions doc/src/sgml/ref/pg_restore.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,16 @@ PostgreSQL documentation
</listitem>
</varlistentry>

<varlistentry>
<term><option>--no-event-triggers</option></term>
<listitem>
<para>
Do not output commands to restore event triggers, even if the archive
contains them.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--no-table-access-method</option></term>
<listitem>
Expand Down
2 changes: 2 additions & 0 deletions src/bin/pg_dump/pg_backup.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,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 issue event-trigger-related commands */
int disable_triggers; /* disable triggers during data-only
* restore */
int use_setsessauth; /* Use SET SESSION AUTHORIZATION commands
Expand Down Expand Up @@ -187,6 +188,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;
Expand Down
5 changes: 5 additions & 0 deletions src/bin/pg_dump/pg_backup_archiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,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;
Expand Down Expand Up @@ -2959,6 +2960,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)
{
Expand Down
23 changes: 23 additions & 0 deletions src/bin/pg_dump/pg_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ main(int argc, char **argv)
{"no-publications", no_argument, &dopt.no_publications, 1},
{"no-security-labels", no_argument, &dopt.no_security_labels, 1},
{"no-subscriptions", no_argument, &dopt.no_subscriptions, 1},
{"no-event-triggers", no_argument, &dopt.no_event_triggers, 1},
{"no-toast-compression", no_argument, &dopt.no_toast_compression, 1},
{"no-unlogged-table-data", no_argument, &dopt.no_unlogged_table_data, 1},
{"no-sync", no_argument, NULL, 7},
Expand Down Expand Up @@ -1047,6 +1048,7 @@ main(int argc, char **argv)
ropt->no_publications = dopt.no_publications;
ropt->no_security_labels = dopt.no_security_labels;
ropt->no_subscriptions = dopt.no_subscriptions;
ropt->no_event_triggers = dopt.no_event_triggers;
ropt->lockWaitTimeout = dopt.lockWaitTimeout;
ropt->include_everything = dopt.include_everything;
ropt->enable_row_security = dopt.enable_row_security;
Expand Down Expand Up @@ -1153,6 +1155,7 @@ help(const char *progname)
printf(_(" --no-publications do not dump publications\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-table-access-method do not dump table access methods\n"));
printf(_(" --no-tablespaces do not dump tablespace assignments\n"));
printf(_(" --no-toast-compression do not dump TOAST compression methods\n"));
Expand Down Expand Up @@ -6585,6 +6588,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;
Expand All @@ -6605,6 +6617,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')"
Expand All @@ -6620,6 +6633,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)
Expand All @@ -6643,6 +6657,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')"
Expand All @@ -6653,6 +6668,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)
Expand Down Expand Up @@ -8359,6 +8375,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();

appendPQExpBufferStr(query,
Expand Down
5 changes: 5 additions & 0 deletions src/bin/pg_dump/pg_dumpall.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -453,6 +455,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)
Expand Down Expand Up @@ -668,6 +672,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"));
Expand Down
4 changes: 4 additions & 0 deletions src/bin/pg_dump/pg_restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,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[] = {
Expand Down Expand Up @@ -126,6 +127,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},
{"filter", required_argument, NULL, 4},

{NULL, 0, NULL, 0}
Expand Down Expand Up @@ -370,6 +372,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");
Expand Down Expand Up @@ -491,6 +494,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-table-access-method do not restore table access methods\n"));
printf(_(" --no-tablespaces do not restore tablespace assignments\n"));
printf(_(" --section=SECTION restore named section (pre-data, data, or post-data)\n"));
Expand Down
12 changes: 12 additions & 0 deletions src/bin/pg_dump/t/002_pg_dump.pl
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,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',
Expand Down Expand Up @@ -709,6 +716,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,
Expand Down Expand Up @@ -2116,6 +2124,7 @@
unlike => {
exclude_dump_test_schema => 1,
only_dump_measurement => 1,
no_event_triggers => 1,
},
},

Expand Down Expand Up @@ -2229,6 +2238,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' => {
Expand Down