The following command-line options control the database connection parameters.
+
+ -d connstr
+ --dbname=connstr
+
+ Specifies parameters used to connect to the server, as a connection
+ string. See for more information.
+
+ The option is called --dbname> for consistency with other
+ client applications, but because
pg_basebackup
+ doesn't connect to any particular database in the cluster, database
+ name in the connection string will be ignored.
+
+
+
+
-h host
--host=host
The following command-line options control the database connection parameters.
+
+ -d connstr
+ --dbname=connstr
+
+ Specifies parameters used to connect to the server, as a connection
+ string. See for more information.
+
+ The option is called --dbname> for consistency with other
+ client applications, but because
pg_basebackup
+ doesn't connect to any particular database in the cluster, database
+ name in the connection string will be ignored.
+
+
+
+
-h host
--host=host
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("\nConnection options:\n"));
+ printf(_(" -d, --dbname=CONNSTR connection string\n"));
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
printf(_(" -p, --port=PORT database server port number\n"));
printf(_(" -s, --status-interval=INTERVAL\n"
{"gzip", no_argument, NULL, 'z'},
{"compress", required_argument, NULL, 'Z'},
{"label", required_argument, NULL, 'l'},
+ {"dbname", required_argument, NULL, 'd'},
{"host", required_argument, NULL, 'h'},
{"port", required_argument, NULL, 'p'},
{"username", required_argument, NULL, 'U'},
}
}
- while ((c = getopt_long(argc, argv, "D:F:RxX:l:zZ:c:h:p:U:s:wWvP",
+ while ((c = getopt_long(argc, argv, "D:F:RxX:l:zZ:d: c:h:p:U:s:wWvP",
long_options, &option_index)) != -1)
{
switch (c)
exit(1);
}
break;
+ case 'd':
+ connection_string = pg_strdup(optarg);
+ break;
case 'h':
dbhost = pg_strdup(optarg);
break;
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("\nConnection options:\n"));
+ printf(_(" -d, --dbname=CONNSTR connection string\n"));
printf(_(" -h, --host=HOSTNAME database server host or socket directory\n"));
printf(_(" -p, --port=PORT database server port number\n"));
printf(_(" -s, --status-interval=INTERVAL\n"
{"help", no_argument, NULL, '?'},
{"version", no_argument, NULL, 'V'},
{"directory", required_argument, NULL, 'D'},
+ {"dbname", required_argument, NULL, 'd'},
{"host", required_argument, NULL, 'h'},
{"port", required_argument, NULL, 'p'},
{"username", required_argument, NULL, 'U'},
}
}
- while ((c = getopt_long(argc, argv, "D:h:p:U:s:nwWv",
+ while ((c = getopt_long(argc, argv, "D:d: h:p:U:s:nwWv",
long_options, &option_index)) != -1)
{
switch (c)
case 'D':
basedir = pg_strdup(optarg);
break;
+ case 'd':
+ connection_string = pg_strdup(optarg);
+ break;
case 'h':
dbhost = pg_strdup(optarg);
break;
#include
const char *progname;
+char *connection_string = NULL;
char *dbhost = NULL;
char *dbuser = NULL;
char *dbport = NULL;
GetConnection(void)
{
PGconn *tmpconn;
- int argcount = 4 ; /* dbname, replication, fallback_app_name,
- * password */
+ int argcount = 7 ; /* dbname, replication, fallback_app_name,
+ * host, user, port, password */
int i;
const char **keywords;
const char **values;
char *password = NULL;
const char *tmpparam;
+ PQconninfoOption *conn_opts = NULL;
+ PQconninfoOption *conn_opt;
+ char *err_msg = NULL;
+
+ /*
+ * Merge the connection info inputs given in form of connection string,
+ * options and default values (dbname=replication, replication=true,
+ * etc.)
+ */
+ i = 0;
+ if (connection_string)
+ {
+ conn_opts = PQconninfoParse(connection_string, &err_msg);
+ if (conn_opts == NULL)
+ {
+ fprintf(stderr, "%s: %s\n", progname, err_msg);
+ return NULL;
+ }
+
+ for (conn_opt = conn_opts; conn_opt->keyword != NULL; conn_opt++)
+ {
+ if (conn_opt->val != NULL && conn_opt->val[0] != '\0')
+ argcount++;
+ }
+
+ keywords = pg_malloc0((argcount + 1) * sizeof(*keywords));
+ values = pg_malloc0((argcount + 1) * sizeof(*values));
+
+ for (conn_opt = conn_opts; conn_opt->keyword != NULL; conn_opt++)
+ {
+ if (conn_opt->val != NULL && conn_opt->val[0] != '\0')
+ {
+ keywords[i] = conn_opt->keyword;
+ values[i] = conn_opt->val;
+ i++;
+ }
+ }
+ }
+ else
+ {
+ keywords = pg_malloc0((argcount + 1) * sizeof(*keywords));
+ values = pg_malloc0((argcount + 1) * sizeof(*values));
+ }
+
+ keywords[i] = "dbname";
+ values[i] = "replication";
+ i++;
+ keywords[i] = "replication";
+ values[i] = "true";
+ i++;
+ keywords[i] = "fallback_application_name";
+ values[i] = progname;
+ i++;
- if (dbhost)
- argcount++;
- if (dbuser)
- argcount++;
- if (dbport)
- argcount++;
-
- keywords = pg_malloc0((argcount + 1) * sizeof(*keywords));
- values = pg_malloc0((argcount + 1) * sizeof(*values));
-
- keywords[0] = "dbname";
- values[0] = "replication";
- keywords[1] = "replication";
- values[1] = "true";
- keywords[2] = "fallback_application_name";
- values[2] = progname;
- i = 3;
if (dbhost)
{
keywords[i] = "host";
* meaning this is the call for a second session to the same
* database, so just forcibly reuse that password.
*/
- keywords[argcount - 1 ] = "password";
- values[argcount - 1 ] = dbpassword;
+ keywords[i ] = "password";
+ values[i ] = dbpassword;
dbgetpassword = -1; /* Don't try again if this fails */
}
else if (dbgetpassword == 1)
{
password = simple_prompt(_("Password: "), 100, false);
- keywords[argcount - 1 ] = "password";
- values[argcount - 1 ] = password;
+ keywords[i ] = "password";
+ values[i ] = password;
}
tmpconn = PQconnectdbParams(keywords, values, true);
PQfinish(tmpconn);
free(values);
free(keywords);
+ if (conn_opts)
+ PQconninfoFree(conn_opts);
return NULL;
}
/* Connection ok! */
free(values);
free(keywords);
+ if (conn_opts)
+ PQconninfoFree(conn_opts);
/*
* Ensure we have the same value of integer timestamps as the server
#include "libpq-fe.h"
extern const char *progname;
+extern char *connection_string;
extern char *dbhost;
extern char *dbuser;
extern char *dbport;