summaryrefslogtreecommitdiff
path: root/src/bin/pg_basebackup/streamutil.c
diff options
context:
space:
mode:
authorAndres Freund2015-07-12 20:06:27 +0000
committerAndres Freund2015-07-12 20:15:20 +0000
commitff27db5dd2fc096d89d3f995d3f650ec6d3bc147 (patch)
tree4e57e6befd68986468c4547a136ef9f6011ba65d /src/bin/pg_basebackup/streamutil.c
parent0a0fe2ff6ef65e3a1cf4d83d96eab144477a0220 (diff)
Optionally don't error out due to preexisting slots in commandline utilities.
pg_receivexlog and pg_recvlogical error out when --create-slot is specified and a slot with the same name already exists. In some cases, especially with pg_receivexlog, that's rather annoying and requires additional scripting. Backpatch to 9.5 as slot control functions have newly been added to pg_receivexlog, and there doesn't seem much point leaving it in a less useful state. Discussion: [email protected]
Diffstat (limited to 'src/bin/pg_basebackup/streamutil.c')
-rw-r--r--src/bin/pg_basebackup/streamutil.c44
1 files changed, 19 insertions, 25 deletions
diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c
index 0ed61440b09..a5cad350f8a 100644
--- a/src/bin/pg_basebackup/streamutil.c
+++ b/src/bin/pg_basebackup/streamutil.c
@@ -31,6 +31,8 @@
#include "common/fe_memutils.h"
#include "datatype/timestamp.h"
+#define ERRCODE_DUPLICATE_OBJECT "42710"
+
const char *progname;
char *connection_string = NULL;
char *dbhost = NULL;
@@ -314,7 +316,7 @@ RunIdentifySystem(PGconn *conn, char **sysid, TimeLineID *starttli,
*/
bool
CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
- XLogRecPtr *startpos, bool is_physical)
+ bool is_physical, bool slot_exists_ok)
{
PQExpBuffer query;
PGresult *res;
@@ -336,12 +338,23 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
res = PQexec(conn, query->data);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
- progname, query->data, PQerrorMessage(conn));
+ const char *sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
- destroyPQExpBuffer(query);
- PQclear(res);
- return false;
+ if (slot_exists_ok && strcmp(sqlstate, ERRCODE_DUPLICATE_OBJECT) == 0)
+ {
+ destroyPQExpBuffer(query);
+ PQclear(res);
+ return true;
+ }
+ else
+ {
+ fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
+ progname, query->data, PQerrorMessage(conn));
+
+ destroyPQExpBuffer(query);
+ PQclear(res);
+ return false;
+ }
}
if (PQntuples(res) != 1 || PQnfields(res) != 4)
@@ -356,25 +369,6 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
return false;
}
- /* Get LSN start position if necessary */
- if (startpos != NULL)
- {
- uint32 hi,
- lo;
-
- if (sscanf(PQgetvalue(res, 0, 1), "%X/%X", &hi, &lo) != 2)
- {
- fprintf(stderr,
- _("%s: could not parse transaction log location \"%s\"\n"),
- progname, PQgetvalue(res, 0, 1));
-
- destroyPQExpBuffer(query);
- PQclear(res);
- return false;
- }
- *startpos = ((uint64) hi) << 32 | lo;
- }
-
destroyPQExpBuffer(query);
PQclear(res);
return true;