Skip to content

Commit a9254e6

Browse files
committed
pg_dump: Always dump subscriptions NOCONNECT
This removes the pg_dump option --no-subscription-connect and makes it the default. Dumping a subscription so that it activates right away when restored is not very useful, because the state of the publication server is unclear. Discussion: https://www.postgresql.org/message-id/e4fbfad5-c6ac-fd50-6777-18c84b34eb2f@2ndquadrant.com
1 parent c31671f commit a9254e6

File tree

5 files changed

+17
-37
lines changed

5 files changed

+17
-37
lines changed

doc/src/sgml/ref/pg_dump.sgml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -798,19 +798,6 @@ PostgreSQL documentation
798798
</listitem>
799799
</varlistentry>
800800

801-
<varlistentry>
802-
<term><option>--no-subscription-connect</option></term>
803-
<listitem>
804-
<para>
805-
When dumping logical replication subscriptions,
806-
generate <command>CREATE SUBSCRIPTION</command> commands that do not
807-
make remote connections for creating replication slot or initial table
808-
copy. That way, the dump can be restored without requiring network
809-
access to the remote servers.
810-
</para>
811-
</listitem>
812-
</varlistentry>
813-
814801
<varlistentry>
815802
<term><option>--no-synchronized-snapshots</></term>
816803
<listitem>
@@ -1235,6 +1222,19 @@ CREATE DATABASE foo WITH TEMPLATE template0;
12351222
in cross-version cases, as it can prevent problems arising from varying
12361223
reserved-word lists in different <productname>PostgreSQL</> versions.
12371224
</para>
1225+
1226+
<para>
1227+
When dumping logical replication subscriptions,
1228+
<application>pg_dump</application> will generate <command>CREATE
1229+
SUBSCRIPTION</command> commands that use the <literal>NOCONNECT</literal>
1230+
option, so that restoring the subscription does not make remote connections
1231+
for creating a replication slot or for initial table copy. That way, the
1232+
dump can be restored without requiring network access to the remote
1233+
servers. It is then up to the user to reactivate the subscriptions in a
1234+
suitable way. If the involved hosts have changed, the connection
1235+
information might have to be changed. It might also be appropriate to
1236+
truncate the target tables before initiating a new full table copy.
1237+
</para>
12381238
</refsect1>
12391239

12401240
<refsect1 id="pg-dump-examples">

src/bin/pg_dump/pg_backup.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ typedef struct _dumpOptions
153153
int outputNoTablespaces;
154154
int use_setsessauth;
155155
int enable_row_security;
156-
int no_subscription_connect;
157156

158157
/* default, if no "inclusion" switches appear, is to dump everything */
159158
bool include_everything;

src/bin/pg_dump/pg_dump.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ main(int argc, char **argv)
353353
{"strict-names", no_argument, &strict_names, 1},
354354
{"use-set-session-authorization", no_argument, &dopt.use_setsessauth, 1},
355355
{"no-security-labels", no_argument, &dopt.no_security_labels, 1},
356-
{"no-subscription-connect", no_argument, &dopt.no_subscription_connect, 1},
357356
{"no-synchronized-snapshots", no_argument, &dopt.no_synchronized_snapshots, 1},
358357
{"no-unlogged-table-data", no_argument, &dopt.no_unlogged_table_data, 1},
359358
{"no-sync", no_argument, NULL, 7},
@@ -951,7 +950,6 @@ help(const char *progname)
951950
printf(_(" --if-exists use IF EXISTS when dropping objects\n"));
952951
printf(_(" --inserts dump data as INSERT commands, rather than COPY\n"));
953952
printf(_(" --no-security-labels do not dump security label assignments\n"));
954-
printf(_(" --no-subscription-connect dump subscriptions so they don't connect on restore\n"));
955953
printf(_(" --no-synchronized-snapshots do not use synchronized snapshots in parallel jobs\n"));
956954
printf(_(" --no-tablespaces do not dump tablespace assignments\n"));
957955
printf(_(" --no-unlogged-table-data do not dump unlogged table data\n"));
@@ -3669,7 +3667,6 @@ getSubscriptions(Archive *fout)
36693667
int i_oid;
36703668
int i_subname;
36713669
int i_rolname;
3672-
int i_subenabled;
36733670
int i_subconninfo;
36743671
int i_subslotname;
36753672
int i_subpublications;
@@ -3702,7 +3699,7 @@ getSubscriptions(Archive *fout)
37023699
/* Get the subscriptions in current database. */
37033700
appendPQExpBuffer(query,
37043701
"SELECT s.tableoid, s.oid, s.subname,"
3705-
"(%s s.subowner) AS rolname, s.subenabled, "
3702+
"(%s s.subowner) AS rolname, "
37063703
" s.subconninfo, s.subslotname, s.subpublications "
37073704
"FROM pg_catalog.pg_subscription s "
37083705
"WHERE s.subdbid = (SELECT oid FROM pg_catalog.pg_database"
@@ -3716,7 +3713,6 @@ getSubscriptions(Archive *fout)
37163713
i_oid = PQfnumber(res, "oid");
37173714
i_subname = PQfnumber(res, "subname");
37183715
i_rolname = PQfnumber(res, "rolname");
3719-
i_subenabled = PQfnumber(res, "subenabled");
37203716
i_subconninfo = PQfnumber(res, "subconninfo");
37213717
i_subslotname = PQfnumber(res, "subslotname");
37223718
i_subpublications = PQfnumber(res, "subpublications");
@@ -3732,8 +3728,6 @@ getSubscriptions(Archive *fout)
37323728
AssignDumpId(&subinfo[i].dobj);
37333729
subinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_subname));
37343730
subinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
3735-
subinfo[i].subenabled =
3736-
(strcmp(PQgetvalue(res, i, i_subenabled), "t") == 0);
37373731
subinfo[i].subconninfo = pg_strdup(PQgetvalue(res, i, i_subconninfo));
37383732
subinfo[i].subslotname = pg_strdup(PQgetvalue(res, i, i_subslotname));
37393733
subinfo[i].subpublications =
@@ -3758,7 +3752,6 @@ getSubscriptions(Archive *fout)
37583752
static void
37593753
dumpSubscription(Archive *fout, SubscriptionInfo *subinfo)
37603754
{
3761-
DumpOptions *dopt = fout->dopt;
37623755
PQExpBuffer delq;
37633756
PQExpBuffer query;
37643757
PQExpBuffer publications;
@@ -3799,19 +3792,8 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo)
37993792
appendPQExpBufferStr(publications, fmtId(pubnames[i]));
38003793
}
38013794

3802-
appendPQExpBuffer(query, " PUBLICATION %s WITH (", publications->data);
3803-
3804-
if (subinfo->subenabled)
3805-
appendPQExpBufferStr(query, "ENABLED");
3806-
else
3807-
appendPQExpBufferStr(query, "DISABLED");
3808-
3809-
appendPQExpBufferStr(query, ", SLOT NAME = ");
3795+
appendPQExpBuffer(query, " PUBLICATION %s WITH (NOCONNECT, SLOT NAME = ", publications->data);
38103796
appendStringLiteralAH(query, subinfo->subslotname, fout);
3811-
3812-
if (dopt->no_subscription_connect)
3813-
appendPQExpBufferStr(query, ", NOCONNECT");
3814-
38153797
appendPQExpBufferStr(query, ");\n");
38163798

38173799
ArchiveEntry(fout, subinfo->dobj.catId, subinfo->dobj.dumpId,

src/bin/pg_dump/pg_dump.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,6 @@ typedef struct _SubscriptionInfo
614614
{
615615
DumpableObject dobj;
616616
char *rolname;
617-
bool subenabled;
618617
char *subconninfo;
619618
char *subslotname;
620619
char *subpublications;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4303,9 +4303,9 @@
43034303
create_order => 50,
43044304
create_sql => 'CREATE SUBSCRIPTION sub1
43054305
CONNECTION \'dbname=doesnotexist\' PUBLICATION pub1
4306-
WITH (DISABLED, NOCONNECT);',
4306+
WITH (NOCONNECT);',
43074307
regexp => qr/^
4308-
\QCREATE SUBSCRIPTION sub1 CONNECTION 'dbname=doesnotexist' PUBLICATION pub1 WITH (DISABLED, SLOT NAME = 'sub1');\E
4308+
\QCREATE SUBSCRIPTION sub1 CONNECTION 'dbname=doesnotexist' PUBLICATION pub1 WITH (NOCONNECT, SLOT NAME = 'sub1');\E
43094309
/xm,
43104310
like => {
43114311
binary_upgrade => 1,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy