/* global decls */
bool g_verbose; /* User wants verbose narration of our
* activities. */
-PGconn *g_conn; /* the database connection */
/* various user-settable parameters */
bool schemaOnly;
* Open the database using the Archiver, so it knows about it. Errors mean
* death.
*/
- g_conn = ConnectDatabase(fout, dbname, pghost, pgport,
- username, prompt_password);
-
+ ConnectDatabase(fout, dbname, pghost, pgport, username, prompt_password);
setup_connection(fout, dumpencoding, use_role);
/*
if (fout->remoteVersion < 70300)
{
if (fout->remoteVersion >= 70100)
- g_last_builtin_oid = findLastBuiltinOid_V71(fout, PQdb(g_conn));
+ g_last_builtin_oid = findLastBuiltinOid_V71(fout,
+ PQdb(GetConnection(fout)));
else
g_last_builtin_oid = findLastBuiltinOid_V70(fout);
if (g_verbose)
static void
setup_connection(Archive *AH, const char *dumpencoding, char *use_role)
{
+ PGconn *conn = GetConnection(AH);
const char *std_strings;
/* Set the client encoding if requested */
if (dumpencoding)
{
- if (PQsetClientEncoding(g_conn, dumpencoding) < 0)
+ if (PQsetClientEncoding(conn, dumpencoding) < 0)
{
write_msg(NULL, "invalid client encoding \"%s\" specified\n",
dumpencoding);
* Get the active encoding and the standard_conforming_strings setting, so
* we know how to escape strings.
*/
- AH->encoding = PQclientEncoding(g_conn);
+ AH->encoding = PQclientEncoding(conn);
- std_strings = PQparameterStatus(g_conn, "standard_conforming_strings");
+ std_strings = PQparameterStatus(conn, "standard_conforming_strings");
AH->std_strings = (std_strings && strcmp(std_strings, "on") == 0);
/* Set the role if requested */
appendPQExpBuffer(query, "UNION ALL\n");
appendPQExpBuffer(query,
"SELECT oid FROM pg_catalog.pg_namespace n\n");
- processSQLNamePattern(g_conn, query, cell->val, false, false,
- NULL, "n.nspname", NULL,
- NULL);
+ processSQLNamePattern(GetConnection(fout), query, cell->val, false,
+ false, NULL, "n.nspname", NULL, NULL);
}
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
"\nWHERE c.relkind in ('%c', '%c', '%c', '%c')\n",
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW,
RELKIND_FOREIGN_TABLE);
- processSQLNamePattern(g_conn, query, cell->val, true, false,
- "n.nspname", "c.relname", NULL,
+ processSQLNamePattern(GetConnection(fout), query, cell->val, true,
+ false, "n.nspname", "c.relname", NULL,
"pg_catalog.pg_table_is_visible(c.oid)");
}
const bool hasoids = tbinfo->hasoids;
const bool oids = tdinfo->oids;
PQExpBuffer q = createPQExpBuffer();
+ PGconn *conn = GetConnection(fout);
PGresult *res;
int ret;
char *copybuf;
for (;;)
{
- ret = PQgetCopyData(g_conn, ©buf, 0);
+ ret = PQgetCopyData(conn, ©buf, 0);
if (ret < 0)
break; /* done or error */
{
/* copy data transfer failed */
write_msg(NULL, "Dumping the contents of table \"%s\" failed: PQgetCopyData() failed.\n", classname);
- write_msg(NULL, "Error message from server: %s", PQerrorMessage(g_conn));
+ write_msg(NULL, "Error message from server: %s", PQerrorMessage(conn));
write_msg(NULL, "The command was: %s\n", q->data);
exit_nicely(1);
}
/* Check command status and return to normal libpq state */
- res = PQgetResult(g_conn);
+ res = PQgetResult(conn);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
write_msg(NULL, "Dumping the contents of table \"%s\" failed: PQgetResult() failed.\n", classname);
- write_msg(NULL, "Error message from server: %s", PQerrorMessage(g_conn));
+ write_msg(NULL, "Error message from server: %s", PQerrorMessage(conn));
write_msg(NULL, "The command was: %s\n", q->data);
exit_nicely(1);
}
PQExpBuffer dbQry = createPQExpBuffer();
PQExpBuffer delQry = createPQExpBuffer();
PQExpBuffer creaQry = createPQExpBuffer();
+ PGconn *conn = GetConnection(fout);
PGresult *res;
int ntups;
int i_tableoid,
*tablespace;
uint32 frozenxid;
- datname = PQdb(g_conn);
+ datname = PQdb(conn);
if (g_verbose)
write_msg(NULL, "saving database definition\n");
{
PQExpBuffer seclabelQry = createPQExpBuffer();
- buildShSecLabelQuery(g_conn, "pg_database", dbCatId.oid, seclabelQry);
+ buildShSecLabelQuery(conn, "pg_database", dbCatId.oid, seclabelQry);
res = ExecuteSqlQuery(fout, seclabelQry->data, PGRES_TUPLES_OK);
resetPQExpBuffer(seclabelQry);
- emitShSecLabels(g_conn, res, seclabelQry, "DATABASE", datname);
+ emitShSecLabels(conn, res, seclabelQry, "DATABASE", datname);
if (strlen(seclabelQry->data))
ArchiveEntry(fout, dbCatId, createDumpId(), datname, NULL, NULL,
dba, false, "SECURITY LABEL", SECTION_NONE,
{
const char *blobQry;
const char *blobFetchQry;
+ PGconn *conn = GetConnection(fout);
PGresult *res;
char buf[LOBBUFSIZE];
int ntups;
blobOid = atooid(PQgetvalue(res, i, 0));
/* Open the BLOB */
- loFd = lo_open(g_conn, blobOid, INV_READ);
+ loFd = lo_open(conn, blobOid, INV_READ);
if (loFd == -1)
{
write_msg(NULL, "could not open large object %u: %s",
- blobOid, PQerrorMessage(g_conn));
+ blobOid, PQerrorMessage(conn));
exit_nicely(1);
}
/* Now read it in chunks, sending data to archive */
do
{
- cnt = lo_read(g_conn, loFd, buf, LOBBUFSIZE);
+ cnt = lo_read(conn, loFd, buf, LOBBUFSIZE);
if (cnt < 0)
{
write_msg(NULL, "error reading large object %u: %s",
- blobOid, PQerrorMessage(g_conn));
+ blobOid, PQerrorMessage(conn));
exit_nicely(1);
}
WriteData(fout, buf, cnt);
} while (cnt > 0);
- lo_close(g_conn, loFd);
+ lo_close(conn, loFd);
EndBlob(fout, blobOid);
}
*/
resetPQExpBuffer(query);
appendPQExpBuffer(query, "SET statement_timeout = ");
- appendStringLiteralConn(query, lockWaitTimeout, g_conn);
+ appendStringLiteralConn(query, lockWaitTimeout, GetConnection(fout));
ExecuteSqlStatement(fout, query->data);
}