#include "funcapi.h"
#include "lib/stringinfo.h"
#include "libpq-fe.h"
+#include "libpq/libpq-be-fe-helpers.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "parser/scansup.h"
connstr = conname_or_str;
dblink_connstr_check(connstr);
- /*
- * We must obey fd.c's limit on non-virtual file descriptors. Assume
- * that a PGconn represents one long-lived FD. (Doing this here also
- * ensures that VFDs are closed if needed to make room.)
- */
- if (!AcquireExternalFD())
- {
-#ifndef WIN32 /* can't write #if within ereport() macro */
- ereport(ERROR,
- (errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
- errmsg("could not establish connection"),
- errdetail("There are too many open files on the local server."),
- errhint("Raise the server's max_files_per_process and/or \"ulimit -n\" limits.")));
-#else
- ereport(ERROR,
- (errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
- errmsg("could not establish connection"),
- errdetail("There are too many open files on the local server."),
- errhint("Raise the server's max_files_per_process setting.")));
-#endif
- }
-
/* OK to make connection */
- conn = PQconnectdb(connstr);
+ conn = libpqsrv_connect(connstr, PG_WAIT_EXTENSION);
if (PQstatus(conn) == CONNECTION_BAD)
{
char *msg = pchomp(PQerrorMessage(conn));
- PQfinish(conn);
- ReleaseExternalFD();
+ libpqsrv_disconnect(conn);
ereport(ERROR,
(errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
errmsg("could not establish connection"),
/* check password in connection string if not superuser */
dblink_connstr_check(connstr);
- /*
- * We must obey fd.c's limit on non-virtual file descriptors. Assume that
- * a PGconn represents one long-lived FD. (Doing this here also ensures
- * that VFDs are closed if needed to make room.)
- */
- if (!AcquireExternalFD())
- {
-#ifndef WIN32 /* can't write #if within ereport() macro */
- ereport(ERROR,
- (errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
- errmsg("could not establish connection"),
- errdetail("There are too many open files on the local server."),
- errhint("Raise the server's max_files_per_process and/or \"ulimit -n\" limits.")));
-#else
- ereport(ERROR,
- (errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
- errmsg("could not establish connection"),
- errdetail("There are too many open files on the local server."),
- errhint("Raise the server's max_files_per_process setting.")));
-#endif
- }
-
/* OK to make connection */
- conn = PQconnectdb(connstr);
+ conn = libpqsrv_connect(connstr, PG_WAIT_EXTENSION);
if (PQstatus(conn) == CONNECTION_BAD)
{
msg = pchomp(PQerrorMessage(conn));
- PQfinish(conn);
- ReleaseExternalFD();
+ libpqsrv_disconnect(conn);
if (rconn)
pfree(rconn);
else
{
if (pconn->conn)
- {
- PQfinish(pconn->conn);
- ReleaseExternalFD();
- }
+ libpqsrv_disconnect(conn);
pconn->conn = conn;
}
if (!conn)
dblink_conn_not_avail(conname);
- PQfinish(conn);
- ReleaseExternalFD();
+ libpqsrv_disconnect(conn);
if (rconn)
{
deleteConnection(conname);
{
/* if needed, close the connection to the database */
if (freeconn)
- {
- PQfinish(conn);
- ReleaseExternalFD();
- }
+ libpqsrv_disconnect(conn);
}
PG_END_TRY();
{
/* if needed, close the connection to the database */
if (freeconn)
- {
- PQfinish(conn);
- ReleaseExternalFD();
- }
+ libpqsrv_disconnect(conn);
}
PG_END_TRY();
if (found)
{
- PQfinish(rconn->conn);
- ReleaseExternalFD();
+ libpqsrv_disconnect(rconn->conn);
pfree(rconn);
ereport(ERROR,
{
if (!PQconnectionUsedPassword(conn))
{
- PQfinish(conn);
- ReleaseExternalFD();
+ libpqsrv_disconnect(conn);
if (rconn)
pfree(rconn);
#include "catalog/pg_user_mapping.h"
#include "commands/defrem.h"
#include "funcapi.h"
+#include "libpq/libpq-be-fe-helpers.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "pgstat.h"
/* verify the set of connection parameters */
check_conn_params(keywords, values, user);
- /*
- * We must obey fd.c's limit on non-virtual file descriptors. Assume
- * that a PGconn represents one long-lived FD. (Doing this here also
- * ensures that VFDs are closed if needed to make room.)
- */
- if (!AcquireExternalFD())
- {
-#ifndef WIN32 /* can't write #if within ereport() macro */
- ereport(ERROR,
- (errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
- errmsg("could not connect to server \"%s\"",
- server->servername),
- errdetail("There are too many open files on the local server."),
- errhint("Raise the server's max_files_per_process and/or \"ulimit -n\" limits.")));
-#else
- ereport(ERROR,
- (errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
- errmsg("could not connect to server \"%s\"",
- server->servername),
- errdetail("There are too many open files on the local server."),
- errhint("Raise the server's max_files_per_process setting.")));
-#endif
- }
-
/* OK to make connection */
- conn = PQconnectdbParams(keywords, values, false);
-
- if (!conn)
- ReleaseExternalFD(); /* because the PG_CATCH block won't */
+ conn = libpqsrv_connect_params(keywords, values,
+ /* expand_dbname = */ false,
+ PG_WAIT_EXTENSION);
if (!conn || PQstatus(conn) != CONNECTION_OK)
ereport(ERROR,
}
PG_CATCH();
{
- /* Release PGconn data structure if we managed to create one */
- if (conn)
- {
- PQfinish(conn);
- ReleaseExternalFD();
- }
+ libpqsrv_disconnect(conn);
PG_RE_THROW();
}
PG_END_TRY();
{
if (entry->conn != NULL)
{
- PQfinish(entry->conn);
+ libpqsrv_disconnect(entry->conn);
entry->conn = NULL;
- ReleaseExternalFD();
}
}