Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc31671f

Browse files
committed
pg_dump: Dump subscriptions by default
Dump subscriptions if the current user is a superuser, otherwise write awarning and skip them. Remove the pg_dump option--include-subscriptions.Discussion:https://www.postgresql.org/message-id/e4fbfad5-c6ac-fd50-6777-18c84b34eb2f@2ndquadrant.com
1 parent73c1748 commitc31671f

File tree

7 files changed

+50
-39
lines changed

7 files changed

+50
-39
lines changed

‎doc/src/sgml/logical-replication.sgml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@
167167
</para>
168168

169169
<para>
170-
Subscriptions are not dumped by <command>pg_dump</command> by default, but
171-
this can be requested using the command-line
172-
option <option>--include-subscriptions</option>.
170+
Subscriptions are dumped by <command>pg_dump</command> if the current user
171+
is a superuser. Otherwise a warning is written and subscriptions are
172+
skipped, because non-superusers cannot read all subscription information
173+
from the <structname>pg_subscription</structname> catalog.
173174
</para>
174175

175176
<para>

‎doc/src/sgml/ref/pg_dump.sgml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -755,15 +755,6 @@ PostgreSQL documentation
755755
</listitem>
756756
</varlistentry>
757757

758-
<varlistentry>
759-
<term><option>--include-subscriptions</option></term>
760-
<listitem>
761-
<para>
762-
Include logical replication subscriptions in the dump.
763-
</para>
764-
</listitem>
765-
</varlistentry>
766-
767758
<varlistentry>
768759
<term><option>--inserts</option></term>
769760
<listitem>

‎src/bin/pg_dump/pg_backup.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ typedef struct _restoreOptions
119119
bool*idWanted;/* array showing which dump IDs to emit */
120120
intenable_row_security;
121121
intsequence_data;/* dump sequence data even in schema-only mode */
122-
intinclude_subscriptions;
123122
intbinary_upgrade;
124123
}RestoreOptions;
125124

@@ -154,7 +153,6 @@ typedef struct _dumpOptions
154153
intoutputNoTablespaces;
155154
intuse_setsessauth;
156155
intenable_row_security;
157-
intinclude_subscriptions;
158156
intno_subscription_connect;
159157

160158
/* default, if no "inclusion" switches appear, is to dump everything */

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
171171
dopt->include_everything=ropt->include_everything;
172172
dopt->enable_row_security=ropt->enable_row_security;
173173
dopt->sequence_data=ropt->sequence_data;
174-
dopt->include_subscriptions=ropt->include_subscriptions;
175174

176175
returndopt;
177176
}

‎src/bin/pg_dump/pg_dump.c

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ main(int argc, char **argv)
342342
{"enable-row-security", no_argument, &dopt.enable_row_security, 1},
343343
{"exclude-table-data", required_argument, NULL, 4},
344344
{"if-exists", no_argument, &dopt.if_exists, 1},
345-
{"include-subscriptions", no_argument, &dopt.include_subscriptions, 1},
346345
{"inserts", no_argument, &dopt.dump_inserts, 1},
347346
{"lock-wait-timeout", required_argument, NULL, 2},
348347
{"no-tablespaces", no_argument, &dopt.outputNoTablespaces, 1},
@@ -868,7 +867,6 @@ main(int argc, char **argv)
868867
ropt->include_everything = dopt.include_everything;
869868
ropt->enable_row_security = dopt.enable_row_security;
870869
ropt->sequence_data = dopt.sequence_data;
871-
ropt->include_subscriptions = dopt.include_subscriptions;
872870
ropt->binary_upgrade = dopt.binary_upgrade;
873871

874872
if (compressLevel == -1)
@@ -951,7 +949,6 @@ help(const char *progname)
951949
" access to)\n"));
952950
printf(_(" --exclude-table-data=TABLE do NOT dump data for the named table(s)\n"));
953951
printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
954-
printf(_(" --include-subscriptions dump logical replication subscriptions\n"));
955952
printf(_(" --inserts dump data as INSERT commands, rather than COPY\n"));
956953
printf(_(" --no-security-labels do not dump security label assignments\n"));
957954
printf(_(" --no-subscription-connect dump subscriptions so they don't connect on restore\n"));
@@ -3641,6 +3638,22 @@ dumpPublicationTable(Archive *fout, PublicationRelInfo *pubrinfo)
36413638
destroyPQExpBuffer(query);
36423639
}
36433640

3641+
/*
3642+
* Is the currently connected user a superuser?
3643+
*/
3644+
static bool
3645+
is_superuser(Archive *fout)
3646+
{
3647+
ArchiveHandle *AH = (ArchiveHandle *) fout;
3648+
const char *val;
3649+
3650+
val = PQparameterStatus(AH->connection, "is_superuser");
3651+
3652+
if (val && strcmp(val, "on") == 0)
3653+
return true;
3654+
3655+
return false;
3656+
}
36443657

36453658
/*
36463659
* getSubscriptions
@@ -3649,7 +3662,6 @@ dumpPublicationTable(Archive *fout, PublicationRelInfo *pubrinfo)
36493662
void
36503663
getSubscriptions(Archive *fout)
36513664
{
3652-
DumpOptions *dopt = fout->dopt;
36533665
PQExpBuffer query;
36543666
PGresult *res;
36553667
SubscriptionInfo *subinfo;
@@ -3664,9 +3676,25 @@ getSubscriptions(Archive *fout)
36643676
inti,
36653677
ntups;
36663678

3667-
if (!dopt->include_subscriptions ||fout->remoteVersion < 100000)
3679+
if (fout->remoteVersion < 100000)
36683680
return;
36693681

3682+
if (!is_superuser(fout))
3683+
{
3684+
int n;
3685+
3686+
res = ExecuteSqlQuery(fout,
3687+
"SELECT count(*) FROM pg_subscription "
3688+
"WHERE subdbid = (SELECT oid FROM pg_catalog.pg_database"
3689+
" WHERE datname = current_database())",
3690+
PGRES_TUPLES_OK);
3691+
n = atoi(PQgetvalue(res, 0, 0));
3692+
if (n > 0)
3693+
write_msg(NULL, "WARNING: subscriptions not dumped because current user is not a superuser\n");
3694+
PQclear(res);
3695+
return;
3696+
}
3697+
36703698
query = createPQExpBuffer();
36713699

36723700
resetPQExpBuffer(query);
@@ -3714,6 +3742,9 @@ getSubscriptions(Archive *fout)
37143742
if (strlen(subinfo[i].rolname) == 0)
37153743
write_msg(NULL, "WARNING: owner of subscription \"%s\" appears to be invalid\n",
37163744
subinfo[i].dobj.name);
3745+
3746+
/* Decide whether we want to dump it */
3747+
selectDumpableObject(&(subinfo[i].dobj), fout);
37173748
}
37183749
PQclear(res);
37193750

@@ -3735,7 +3766,7 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo)
37353766
intnpubnames = 0;
37363767
inti;
37373768

3738-
if (dopt->dataOnly)
3769+
if (!(subinfo->dobj.dump & DUMP_COMPONENT_DEFINITION))
37393770
return;
37403771

37413772
delq = createPQExpBuffer();

‎src/bin/pg_dump/pg_restore.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ main(int argc, char **argv)
6767
char*inputFileSpec;
6868
staticintdisable_triggers=0;
6969
staticintenable_row_security=0;
70-
staticintinclude_subscriptions=0;
7170
staticintif_exists=0;
7271
staticintno_data_for_failed_tables=0;
7372
staticintoutputNoTablespaces=0;
@@ -112,7 +111,6 @@ main(int argc, char **argv)
112111
{"disable-triggers",no_argument,&disable_triggers,1},
113112
{"enable-row-security",no_argument,&enable_row_security,1},
114113
{"if-exists",no_argument,&if_exists,1},
115-
{"include-subscriptions",no_argument,&include_subscriptions,1},
116114
{"no-data-for-failed-tables",no_argument,&no_data_for_failed_tables,1},
117115
{"no-tablespaces",no_argument,&outputNoTablespaces,1},
118116
{"role",required_argument,NULL,2},
@@ -353,7 +351,6 @@ main(int argc, char **argv)
353351

354352
opts->disable_triggers=disable_triggers;
355353
opts->enable_row_security=enable_row_security;
356-
opts->include_subscriptions=include_subscriptions;
357354
opts->noDataForFailedTables=no_data_for_failed_tables;
358355
opts->noTablespace=outputNoTablespaces;
359356
opts->use_setsessauth=use_setsessauth;

‎src/bin/pg_dump/t/002_pg_dump.pl

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
'--format=custom',
4444
"--file=$tempdir/binary_upgrade.dump",
4545
'-w',
46-
'--include-subscriptions',# XXX Should not be necessary?
4746
'--schema-only',
4847
'--binary-upgrade',
4948
'-d','postgres',# alternative way to specify database
@@ -58,7 +57,6 @@
5857
'pg_dump',
5958
'--no-sync',
6059
"--file=$tempdir/clean.sql",
61-
'--include-subscriptions',
6260
'-c',
6361
'-d','postgres',# alternative way to specify database
6462
], },
@@ -67,7 +65,6 @@
6765
'pg_dump',
6866
'--no-sync',
6967
"--file=$tempdir/clean_if_exists.sql",
70-
'--include-subscriptions',
7168
'-c',
7269
'--if-exists',
7370
'--encoding=UTF8',# no-op, just tests that option is accepted
@@ -85,7 +82,6 @@
8582
'pg_dump',
8683
'--no-sync',
8784
"--file=$tempdir/createdb.sql",
88-
'--include-subscriptions',
8985
'-C',
9086
'-R',# no-op, just for testing
9187
'-v',
@@ -95,7 +91,6 @@
9591
'pg_dump',
9692
'--no-sync',
9793
"--file=$tempdir/data_only.sql",
98-
'--include-subscriptions',
9994
'-a',
10095
'--superuser=test_superuser',
10196
'--disable-triggers',
@@ -253,7 +248,6 @@
253248
section_pre_data=> {
254249
dump_cmd=> [
255250
'pg_dump',"--file=$tempdir/section_pre_data.sql",
256-
'--include-subscriptions',
257251
'--section=pre-data','--no-sync','postgres', ], },
258252
section_data=> {
259253
dump_cmd=> [
@@ -271,7 +265,7 @@
271265
with_oids=> {
272266
dump_cmd=> [
273267
'pg_dump','--oids',
274-
'--include-subscriptions','--no-sync',
268+
'--no-sync',
275269
"--file=$tempdir/with_oids.sql",'postgres', ], },);
276270

277271
###############################################################
@@ -1405,7 +1399,7 @@
14051399
# catch-all for ALTER ... OWNER (except LARGE OBJECTs and PUBLICATIONs)
14061400
'ALTER ... OWNER commands (except LARGE OBJECTs and PUBLICATIONs)'=> {
14071401
all_runs=> 0,# catch-all
1408-
regexp=>qr/^ALTER (?!LARGE OBJECT|PUBLICATION)(.*) OWNER TO .*;/m,
1402+
regexp=>qr/^ALTER (?!LARGE OBJECT|PUBLICATION|SUBSCRIPTION)(.*) OWNER TO .*;/m,
14091403
like=> {},# use more-specific options above
14101404
unlike=> {
14111405
column_inserts=> 1,
@@ -4318,25 +4312,25 @@
43184312
clean => 1,
43194313
clean_if_exists => 1,
43204314
createdb => 1,
4321-
with_oids => 1, },
4322-
unlike => {
43234315
defaults => 1,
43244316
exclude_test_table_data => 1,
43254317
exclude_dump_test_schema => 1,
43264318
exclude_test_table => 1,
4327-
section_pre_data => 1,
43284319
no_blobs => 1,
43294320
no_privs => 1,
43304321
no_owner => 1,
4322+
pg_dumpall_dbprivs => 1,
4323+
schema_only => 1,
4324+
section_post_data => 1,
4325+
with_oids => 1, },
4326+
unlike => {
4327+
section_pre_data => 1,
43314328
only_dump_test_schema => 1,
43324329
only_dump_test_table => 1,
4333-
pg_dumpall_dbprivs => 1,
43344330
pg_dumpall_globals => 1,
43354331
pg_dumpall_globals_clean => 1,
4336-
schema_only => 1, # XXX Should be like?
43374332
role => 1,
4338-
section_pre_data => 1, # XXX Should be like?
4339-
section_post_data => 1,
4333+
section_pre_data => 1,
43404334
test_schema_plus_blobs => 1, }, },
43414335
43424336
'ALTER PUBLICATION pub1 ADD TABLE test_table' => {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp