优化pg_recvlogical提示信息

This commit is contained in:
wangxin 2021-04-17 11:48:56 +08:00 committed by zhaowenhao
parent 78f38bb9cb
commit b872b011ea
2 changed files with 16 additions and 8 deletions

View File

@ -669,9 +669,9 @@ static int getOptions(const int argc, char* const* argv)
break;
case 'p':
check_env_value_c(optarg);
if (atoi(optarg) <= 0) {
if (checkIsDigit(optarg) == 0) {
fprintf(stderr, _("%s: invalid port number \"%s\"\n"), progname, optarg);
return 1;
exit(1);
}
dbport = pg_strdup(optarg);
break;
@ -736,8 +736,7 @@ static int getOptions(const int argc, char* const* argv)
fsync_interval = atoi(optarg) * 1000;
if (fsync_interval < 0) {
fprintf(stderr, _("%s: invalid fsync interval \"%s\"\n"), progname, optarg);
return -1;
fsync_interval = 0;
}
break;
case 'S':

View File

@ -22,6 +22,7 @@
#include "knl/knl_variable.h"
#include "utils/timestamp.h"
#include "streamutil.h"
#include "libpq/libpq-int.h"
#include <sys/time.h>
#include <stdio.h>
#include <string.h>
@ -138,6 +139,17 @@ static void CalculateArgCount(int *argcount)
return;
}
static void CheckConnectionHost(PGconn* tmpconn)
{
if (tmpconn == NULL || tmpconn->sock < 0) {
fprintf(stderr, "failed to connect %s:%s.\n",
(dbhost == NULL) ? "Unknown" : dbhost,
(dbport == NULL) ? "Unknown" : dbport);
PQfinish(tmpconn);
exit(1);
}
}
/*
* Connect to the server. Returns a valid PGconn pointer if connected,
* or NULL on non-permanent error. On permanent error, the function will
@ -212,10 +224,7 @@ PGconn* GetConnection(void)
* If there is too little memory even to allocate the PGconn object
* and PQconnectdbParams returns NULL, we call exit(1) directly.
*/
if (tmpconn == NULL) {
fprintf(stderr, _("%s: could not connect to server\n"), progname);
exit(1);
}
CheckConnectionHost(tmpconn);
if (PQstatus(tmpconn) == CONNECTION_BAD && PQconnectionNeedsPassword(tmpconn) && dbgetpassword != -1) {
dbgetpassword = 1; /* ask for password next time */