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

From Joshua Elsasser
Subject [PATCH 5/6] pg_basebackup: allow GetConnection() to make non-replication connections.
Date
Msg-id 1443564988-17928-6-git-send-email-josh@idealist.org
Whole thread Raw
In response to Re: Add pg_basebackup single tar output format  (Joshua Elsasser <josh@idealist.org>)
Responses Re: [PATCH 5/6] pg_basebackup: allow GetConnection() to make non-replication connections.  (Robert Haas <robertmhaas@gmail.com>)
List 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




pgsql-hackers by date:

Previous
From: Joshua Elsasser
Date:
Subject: [PATCH 2/6] pg_basebackup: factor out tar open/close code for reusability.
Next
From: Joshua Elsasser
Date:
Subject: [PATCH 4/6] pg_basebackup: don't lose a zero-length file at the end of a tablespace.