diff options
author | Robert Haas <rhaas@postgresql.org> | 2021-10-05 12:52:49 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2021-10-05 12:52:49 -0400 |
commit | 0266e98c6b865246c3031bbf55cb15f330134e30 (patch) | |
tree | b577574caa7d894120f2c643bb192cbe7a751825 /src/bin/pg_basebackup/streamutil.c | |
parent | 0ba281cb4bf9f5f65529dfa4c8282abb734dd454 (diff) | |
download | postgresql-0266e98c6b865246c3031bbf55cb15f330134e30.tar.gz postgresql-0266e98c6b865246c3031bbf55cb15f330134e30.zip |
Flexible options for CREATE_REPLICATION_SLOT.
Like BASE_BACKUP, CREATE_REPLICATION_SLOT has historically used a
hard-coded syntax. To improve future extensibility, adopt a flexible
options syntax here, too.
In the new syntax, instead of three mutually exclusive options
EXPORT_SNAPSHOT, USE_SNAPSHOT, and NOEXPORT_SNAPSHOT, there is now a single
SNAPSHOT option with three possible values: 'export', 'use', and 'nothing'.
This commit does not remove support for the old syntax. It just adds
the new one as an additional option, makes pg_receivewal,
pg_recvlogical, and walreceiver processes use it.
Patch by me, reviewed by Fabien Coelho, Sergei Kornilov, and
Fujii Masao.
Discussion: http://postgr.es/m/CA+TgmobAczXDRO_Gr2euo_TxgzaH1JxbNxvFx=HYvBinefNH8Q@mail.gmail.com
Discussion: http://postgr.es/m/CA+TgmoZGwR=ZVWFeecncubEyPdwghnvfkkdBe9BLccLSiqdf9Q@mail.gmail.com
Diffstat (limited to 'src/bin/pg_basebackup/streamutil.c')
-rw-r--r-- | src/bin/pg_basebackup/streamutil.c | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c index d782b81adc6..37237cd5d95 100644 --- a/src/bin/pg_basebackup/streamutil.c +++ b/src/bin/pg_basebackup/streamutil.c @@ -490,6 +490,7 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin, { PQExpBuffer query; PGresult *res; + bool use_new_option_syntax = (PQserverVersion(conn) >= 150000); query = createPQExpBuffer(); @@ -498,27 +499,54 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin, Assert(!(two_phase && is_physical)); Assert(slot_name != NULL); - /* Build query */ + /* Build base portion of query */ appendPQExpBuffer(query, "CREATE_REPLICATION_SLOT \"%s\"", slot_name); if (is_temporary) appendPQExpBufferStr(query, " TEMPORARY"); if (is_physical) - { appendPQExpBufferStr(query, " PHYSICAL"); + else + appendPQExpBuffer(query, " LOGICAL \"%s\"", plugin); + + /* Add any requested options */ + if (use_new_option_syntax) + appendPQExpBufferStr(query, " ("); + if (is_physical) + { if (reserve_wal) - appendPQExpBufferStr(query, " RESERVE_WAL"); + AppendPlainCommandOption(query, use_new_option_syntax, + "RESERVE_WAL"); } else { - appendPQExpBuffer(query, " LOGICAL \"%s\"", plugin); if (two_phase && PQserverVersion(conn) >= 150000) - appendPQExpBufferStr(query, " TWO_PHASE"); + AppendPlainCommandOption(query, use_new_option_syntax, + "TWO_PHASE"); if (PQserverVersion(conn) >= 100000) + { /* pg_recvlogical doesn't use an exported snapshot, so suppress */ - appendPQExpBufferStr(query, " NOEXPORT_SNAPSHOT"); + if (use_new_option_syntax) + AppendStringCommandOption(query, use_new_option_syntax, + "SNAPSHOT", "nothing"); + else + AppendPlainCommandOption(query, use_new_option_syntax, + "NOEXPORT_SNAPSHOT"); + } + } + if (use_new_option_syntax) + { + /* Suppress option list if it would be empty, otherwise terminate */ + if (query->data[query->len - 1] == '(') + { + query->len -= 2; + query->data[query->len] = '\0'; + } + else + appendPQExpBufferChar(query, ')'); } + /* Now run the query */ res = PQexec(conn, query->data); if (PQresultStatus(res) != PGRES_TUPLES_OK) { |