summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorTom Lane2020-07-18 16:44:51 +0000
committerTom Lane2020-07-18 16:44:51 +0000
commit9de77b5453130242654ff0b30a551c9c862ed661 (patch)
tree9c48ed25ee4711934006078939a834186c8e9727 /src/bin
parent9add405014f8e47e038af7124528b7601249a2ac (diff)
Allow logical replication to transfer data in binary format.
This patch adds a "binary" option to CREATE/ALTER SUBSCRIPTION. When that's set, the publisher will send data using the data type's typsend function if any, rather than typoutput. This is generally faster, if slightly less robust. As committed, we won't try to transfer user-defined array or composite types in binary, for fear that type OIDs won't match at the subscriber. This might be changed later, but it seems like fit material for a follow-on patch. Dave Cramer, reviewed by Daniel Gustafsson, Petr Jelinek, and others; adjusted some by me Discussion: https://postgr.es/m/CADK3HH+R3xMn=8t3Ct+uD+qJ1KD=Hbif5NFMJ+d5DkoCzp6Vgw@mail.gmail.com
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/pg_dump/pg_dump.c33
-rw-r--r--src/bin/pg_dump/pg_dump.h1
-rw-r--r--src/bin/psql/describe.c8
3 files changed, 32 insertions, 10 deletions
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 857c7c2278a..94459b3539a 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -4205,6 +4205,7 @@ getSubscriptions(Archive *fout)
int i_subslotname;
int i_subsynccommit;
int i_subpublications;
+ int i_subbinary;
int i,
ntups;
@@ -4229,18 +4230,26 @@ getSubscriptions(Archive *fout)
query = createPQExpBuffer();
- resetPQExpBuffer(query);
-
/* Get the subscriptions in current database. */
appendPQExpBuffer(query,
- "SELECT s.tableoid, s.oid, s.subname,"
- "(%s s.subowner) AS rolname, "
- " s.subconninfo, s.subslotname, s.subsynccommit, "
- " s.subpublications "
- "FROM pg_subscription s "
- "WHERE s.subdbid = (SELECT oid FROM pg_database"
- " WHERE datname = current_database())",
+ "SELECT s.tableoid, s.oid, s.subname,\n"
+ " (%s s.subowner) AS rolname,\n"
+ " s.subconninfo, s.subslotname, s.subsynccommit,\n"
+ " s.subpublications,\n",
username_subquery);
+
+ if (fout->remoteVersion >= 140000)
+ appendPQExpBuffer(query,
+ " s.subbinary\n");
+ else
+ appendPQExpBuffer(query,
+ " false AS subbinary\n");
+
+ appendPQExpBuffer(query,
+ "FROM pg_subscription s\n"
+ "WHERE s.subdbid = (SELECT oid FROM pg_database\n"
+ " WHERE datname = current_database())");
+
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
ntups = PQntuples(res);
@@ -4253,6 +4262,7 @@ getSubscriptions(Archive *fout)
i_subslotname = PQfnumber(res, "subslotname");
i_subsynccommit = PQfnumber(res, "subsynccommit");
i_subpublications = PQfnumber(res, "subpublications");
+ i_subbinary = PQfnumber(res, "subbinary");
subinfo = pg_malloc(ntups * sizeof(SubscriptionInfo));
@@ -4274,6 +4284,8 @@ getSubscriptions(Archive *fout)
pg_strdup(PQgetvalue(res, i, i_subsynccommit));
subinfo[i].subpublications =
pg_strdup(PQgetvalue(res, i, i_subpublications));
+ subinfo[i].subbinary =
+ pg_strdup(PQgetvalue(res, i, i_subbinary));
if (strlen(subinfo[i].rolname) == 0)
pg_log_warning("owner of subscription \"%s\" appears to be invalid",
@@ -4342,6 +4354,9 @@ dumpSubscription(Archive *fout, SubscriptionInfo *subinfo)
else
appendPQExpBufferStr(query, "NONE");
+ if (strcmp(subinfo->subbinary, "t") == 0)
+ appendPQExpBuffer(query, ", binary = true");
+
if (strcmp(subinfo->subsynccommit, "off") != 0)
appendPQExpBuffer(query, ", synchronous_commit = %s", fmtId(subinfo->subsynccommit));
diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h
index 0c2fcfb3a9c..da97b731b15 100644
--- a/src/bin/pg_dump/pg_dump.h
+++ b/src/bin/pg_dump/pg_dump.h
@@ -625,6 +625,7 @@ typedef struct _SubscriptionInfo
char *rolname;
char *subconninfo;
char *subslotname;
+ char *subbinary;
char *subsynccommit;
char *subpublications;
} SubscriptionInfo;
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 3b870c3b17e..e197dcdb4d2 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -5963,7 +5963,7 @@ describeSubscriptions(const char *pattern, bool verbose)
PGresult *res;
printQueryOpt myopt = pset.popt;
static const bool translate_columns[] = {false, false, false, false,
- false, false};
+ false, false, false};
if (pset.sversion < 100000)
{
@@ -5989,6 +5989,12 @@ describeSubscriptions(const char *pattern, bool verbose)
if (verbose)
{
+ /* Binary mode is only supported in v14 and higher */
+ if (pset.sversion >= 140000)
+ appendPQExpBuffer(&buf,
+ ", subbinary AS \"%s\"\n",
+ gettext_noop("Binary"));
+
appendPQExpBuffer(&buf,
", subsynccommit AS \"%s\"\n"
", subconninfo AS \"%s\"\n",