[PATCH 5/6] pg_basebackup: allow GetConnection() to make non-replication connections.

From: Joshua Elsasser <josh(at)idealist(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Joshua Elsasser <josh(at)idealist(dot)org>
Subject: [PATCH 5/6] pg_basebackup: allow GetConnection() to make non-replication connections.
Date: 2015-09-29 22:16:27
Message-ID: 1443564988-17928-6-git-send-email-josh@idealist.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

---
src/bin/pg_basebackup/pg_basebackup.c | 4 ++--
src/bin/pg_basebackup/pg_receivexlog.c | 4 ++--
src/bin/pg_basebackup/pg_recvlogical.c | 4 ++--
src/bin/pg_basebackup/streamutil.c | 6 +++---
src/bin/pg_basebackup/streamutil.h | 2 +-
5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index ccd0890..e29e466 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -454,7 +454,7 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier)
#endif

/* Get a second connection */
- param->bgconn = GetConnection();
+ param->bgconn = GetConnection(true);
if (!param->bgconn)
/* Error message already written in GetConnection() */
exit(1);
@@ -1652,7 +1652,7 @@ BaseBackup(void)
/*
* Connect in replication mode to the server
*/
- conn = GetConnection();
+ conn = GetConnection(true);
if (!conn)
/* Error message already written in GetConnection() */
exit(1);
diff --git a/src/bin/pg_basebackup/pg_receivexlog.c b/src/bin/pg_basebackup/pg_receivexlog.c
index 0c322d1..3c61372 100644
--- a/src/bin/pg_basebackup/pg_receivexlog.c
+++ b/src/bin/pg_basebackup/pg_receivexlog.c
@@ -285,7 +285,7 @@ StreamLog(void)
* Connect in replication mode to the server
*/
if (conn == NULL)
- conn = GetConnection();
+ conn = GetConnection(true);
if (!conn)
/* Error message already written in GetConnection() */
return;
@@ -533,7 +533,7 @@ main(int argc, char **argv)
/*
* Obtain a connection before doing anything.
*/
- conn = GetConnection();
+ conn = GetConnection(true);
if (!conn)
/* error message already written in GetConnection() */
exit(1);
diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c
index 93f61c3..faf7cbf 100644
--- a/src/bin/pg_basebackup/pg_recvlogical.c
+++ b/src/bin/pg_basebackup/pg_recvlogical.c
@@ -216,7 +216,7 @@ StreamLogicalLog(void)
* Connect in replication mode to the server
*/
if (!conn)
- conn = GetConnection();
+ conn = GetConnection(true);
if (!conn)
/* Error message already written in GetConnection() */
return;
@@ -856,7 +856,7 @@ main(int argc, char **argv)
* helps to get more precise error messages about authentification,
* required GUC parameters and such.
*/
- conn = GetConnection();
+ conn = GetConnection(true);
if (!conn)
/* Error message already written in GetConnection() */
exit(1);
diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c
index 2c963b6..74cfb5b 100644
--- a/src/bin/pg_basebackup/streamutil.c
+++ b/src/bin/pg_basebackup/streamutil.c
@@ -50,7 +50,7 @@ PGconn *conn = NULL;
* call exit(1) directly.
*/
PGconn *
-GetConnection(void)
+GetConnection(bool replication)
{
PGconn *tmpconn;
int argcount = 7; /* dbname, replication, fallback_app_name,
@@ -104,10 +104,10 @@ GetConnection(void)
}

keywords[i] = "dbname";
- values[i] = dbname == NULL ? "replication" : dbname;
+ values[i] = dbname == NULL ? (replication ? "replication" : "postgres") : dbname;
i++;
keywords[i] = "replication";
- values[i] = dbname == NULL ? "true" : "database";
+ values[i] = replication ? (dbname == NULL ? "true" : "database") : "false";
i++;
keywords[i] = "fallback_application_name";
values[i] = progname;
diff --git a/src/bin/pg_basebackup/streamutil.h b/src/bin/pg_basebackup/streamutil.h
index b95f83f..21a6331 100644
--- a/src/bin/pg_basebackup/streamutil.h
+++ b/src/bin/pg_basebackup/streamutil.h
@@ -28,7 +28,7 @@ extern char *replication_slot;
/* Connection kept global so we can disconnect easily */
extern PGconn *conn;

-extern PGconn *GetConnection(void);
+extern PGconn *GetConnection(bool replication);

/* Replication commands */
extern bool CreateReplicationSlot(PGconn *conn, const char *slot_name,
--
2.3.0

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Joshua Elsasser 2015-09-29 22:16:28 [PATCH 6/6] pg_basebackup: add a single-tar output format.
Previous Message Joshua Elsasser 2015-09-29 22:16:26 [PATCH 4/6] pg_basebackup: don't lose a zero-length file at the end of a tablespace.