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 @@ -928,6 +928,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
10 changes: 10 additions & 0 deletions doc/src/sgml/ref/pg_dumpall.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,16 @@ 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
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 @@ -653,6 +653,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-tablespaces</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 @@ -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
Expand Down Expand Up @@ -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;
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 @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
27 changes: 25 additions & 2 deletions src/bin/pg_dump/pg_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, &quote_all_identifiers, 1},
{"load-via-partition-root", no_argument, &dopt.load_via_partition_root, 1},
{"role", required_argument, NULL, 3},
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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')"
Expand All @@ -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)
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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,
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 @@ -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;
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"));
Expand Down
3 changes: 3 additions & 0 deletions src/bin/pg_dump/pg_restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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"
Expand Down
18 changes: 17 additions & 1 deletion src/bin/pg_dump/t/002_pg_dump.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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' => {
Expand Down Expand Up @@ -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' => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down