mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Add PQping and PQpingParams to libpq to allow detection of the server's
status, including a status where the server is running but refuses a postgres connection. Have pg_ctl use this new function. This fixes the case where pg_ctl reports that the server is not running (cannot connect) but in fact it is running.
This commit is contained in:
@ -285,6 +285,7 @@ static bool connectOptions1(PGconn *conn, const char *conninfo);
|
||||
static bool connectOptions2(PGconn *conn);
|
||||
static int connectDBStart(PGconn *conn);
|
||||
static int connectDBComplete(PGconn *conn);
|
||||
static PGPing internal_ping(PGconn *conn);
|
||||
static PGconn *makeEmptyPGconn(void);
|
||||
static void fillPGconn(PGconn *conn, PQconninfoOption *connOptions);
|
||||
static void freePGconn(PGconn *conn);
|
||||
@ -375,6 +376,20 @@ PQconnectdbParams(const char **keywords,
|
||||
|
||||
}
|
||||
|
||||
PGPing
|
||||
PQpingParams(const char **keywords,
|
||||
const char **values,
|
||||
int expand_dbname)
|
||||
{
|
||||
PGconn *conn = PQconnectStartParams(keywords, values, expand_dbname);
|
||||
PGPing ret;
|
||||
|
||||
ret = internal_ping(conn);
|
||||
PQfinish(conn);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* PQconnectdb
|
||||
*
|
||||
@ -408,6 +423,18 @@ PQconnectdb(const char *conninfo)
|
||||
return conn;
|
||||
}
|
||||
|
||||
PGPing
|
||||
PQping(const char *conninfo)
|
||||
{
|
||||
PGconn *conn = PQconnectStart(conninfo);
|
||||
PGPing ret;
|
||||
|
||||
ret = internal_ping(conn);
|
||||
PQfinish(conn);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* PQconnectStartParams
|
||||
*
|
||||
@ -2513,6 +2540,32 @@ error_return:
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* internal_ping
|
||||
* Determine if a server is running and if we can connect to it.
|
||||
*/
|
||||
PGPing
|
||||
internal_ping(PGconn *conn)
|
||||
{
|
||||
if (conn && conn->status != CONNECTION_BAD)
|
||||
{
|
||||
(void) connectDBComplete(conn);
|
||||
|
||||
/*
|
||||
* If the connection needs a password, we can consider the
|
||||
* server as accepting connections.
|
||||
*/
|
||||
if (conn && (conn->status != CONNECTION_BAD ||
|
||||
PQconnectionNeedsPassword(conn)))
|
||||
return PQACCESS;
|
||||
else
|
||||
return PQREJECT;
|
||||
}
|
||||
else
|
||||
return PQNORESPONSE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* makeEmptyPGconn
|
||||
* - create a PGconn data structure with (as yet) no interesting data
|
||||
|
Reference in New Issue
Block a user