@@ -86,7 +86,6 @@ typedef struct
8686/* global decls */
8787bool g_verbose ;/* User wants verbose narration of our
8888 * activities. */
89- PGconn * g_conn ;/* the database connection */
9089
9190/* various user-settable parameters */
9291bool schemaOnly ;
@@ -614,9 +613,7 @@ main(int argc, char **argv)
614613 * Open the database using the Archiver, so it knows about it. Errors mean
615614 * death.
616615 */
617- g_conn = ConnectDatabase (fout ,dbname ,pghost ,pgport ,
618- username ,prompt_password );
619-
616+ ConnectDatabase (fout ,dbname ,pghost ,pgport ,username ,prompt_password );
620617setup_connection (fout ,dumpencoding ,use_role );
621618
622619/*
@@ -657,7 +654,8 @@ main(int argc, char **argv)
657654if (fout -> remoteVersion < 70300 )
658655{
659656if (fout -> remoteVersion >=70100 )
660- g_last_builtin_oid = findLastBuiltinOid_V71 (fout ,PQdb (g_conn ));
657+ g_last_builtin_oid = findLastBuiltinOid_V71 (fout ,
658+ PQdb (GetConnection (fout )));
661659else
662660g_last_builtin_oid = findLastBuiltinOid_V70 (fout );
663661if (g_verbose )
@@ -870,12 +868,13 @@ pgdump_cleanup_at_exit(int code, void *arg)
870868static void
871869setup_connection (Archive * AH ,const char * dumpencoding ,char * use_role )
872870{
871+ PGconn * conn = GetConnection (AH );
873872const char * std_strings ;
874873
875874/* Set the client encoding if requested */
876875if (dumpencoding )
877876{
878- if (PQsetClientEncoding (g_conn ,dumpencoding )< 0 )
877+ if (PQsetClientEncoding (conn ,dumpencoding )< 0 )
879878{
880879write_msg (NULL ,"invalid client encoding \"%s\" specified\n" ,
881880dumpencoding );
@@ -887,9 +886,9 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role)
887886 * Get the active encoding and the standard_conforming_strings setting, so
888887 * we know how to escape strings.
889888 */
890- AH -> encoding = PQclientEncoding (g_conn );
889+ AH -> encoding = PQclientEncoding (conn );
891890
892- std_strings = PQparameterStatus (g_conn ,"standard_conforming_strings" );
891+ std_strings = PQparameterStatus (conn ,"standard_conforming_strings" );
893892AH -> std_strings = (std_strings && strcmp (std_strings ,"on" )== 0 );
894893
895894/* Set the role if requested */
@@ -1018,9 +1017,8 @@ expand_schema_name_patterns(Archive *fout,
10181017appendPQExpBuffer (query ,"UNION ALL\n" );
10191018appendPQExpBuffer (query ,
10201019"SELECT oid FROM pg_catalog.pg_namespace n\n" );
1021- processSQLNamePattern (g_conn ,query ,cell -> val , false, false,
1022- NULL ,"n.nspname" ,NULL ,
1023- NULL );
1020+ processSQLNamePattern (GetConnection (fout ),query ,cell -> val , false,
1021+ false,NULL ,"n.nspname" ,NULL ,NULL );
10241022}
10251023
10261024res = ExecuteSqlQuery (fout ,query -> data ,PGRES_TUPLES_OK );
@@ -1068,8 +1066,8 @@ expand_table_name_patterns(Archive *fout,
10681066"\nWHERE c.relkind in ('%c', '%c', '%c', '%c')\n" ,
10691067RELKIND_RELATION ,RELKIND_SEQUENCE ,RELKIND_VIEW ,
10701068RELKIND_FOREIGN_TABLE );
1071- processSQLNamePattern (g_conn ,query ,cell -> val , true, false ,
1072- "n.nspname" ,"c.relname" ,NULL ,
1069+ processSQLNamePattern (GetConnection ( fout ) ,query ,cell -> val , true,
1070+ false, "n.nspname" ,"c.relname" ,NULL ,
10731071"pg_catalog.pg_table_is_visible(c.oid)" );
10741072}
10751073
@@ -1266,6 +1264,7 @@ dumpTableData_copy(Archive *fout, void *dcontext)
12661264const bool hasoids = tbinfo -> hasoids ;
12671265const bool oids = tdinfo -> oids ;
12681266PQExpBuffer q = createPQExpBuffer ();
1267+ PGconn * conn = GetConnection (fout );
12691268PGresult * res ;
12701269int ret ;
12711270char * copybuf ;
@@ -1332,7 +1331,7 @@ dumpTableData_copy(Archive *fout, void *dcontext)
13321331
13331332for (;;)
13341333{
1335- ret = PQgetCopyData (g_conn ,& copybuf ,0 );
1334+ ret = PQgetCopyData (conn ,& copybuf ,0 );
13361335
13371336if (ret < 0 )
13381337break ;/* done or error */
@@ -1395,17 +1394,17 @@ dumpTableData_copy(Archive *fout, void *dcontext)
13951394{
13961395/* copy data transfer failed */
13971396write_msg (NULL ,"Dumping the contents of table \"%s\" failed: PQgetCopyData() failed.\n" ,classname );
1398- write_msg (NULL ,"Error message from server: %s" ,PQerrorMessage (g_conn ));
1397+ write_msg (NULL ,"Error message from server: %s" ,PQerrorMessage (conn ));
13991398write_msg (NULL ,"The command was: %s\n" ,q -> data );
14001399exit_nicely (1 );
14011400}
14021401
14031402/* Check command status and return to normal libpq state */
1404- res = PQgetResult (g_conn );
1403+ res = PQgetResult (conn );
14051404if (PQresultStatus (res )!= PGRES_COMMAND_OK )
14061405{
14071406write_msg (NULL ,"Dumping the contents of table \"%s\" failed: PQgetResult() failed.\n" ,classname );
1408- write_msg (NULL ,"Error message from server: %s" ,PQerrorMessage (g_conn ));
1407+ write_msg (NULL ,"Error message from server: %s" ,PQerrorMessage (conn ));
14091408write_msg (NULL ,"The command was: %s\n" ,q -> data );
14101409exit_nicely (1 );
14111410}
@@ -1830,6 +1829,7 @@ dumpDatabase(Archive *fout)
18301829PQExpBuffer dbQry = createPQExpBuffer ();
18311830PQExpBuffer delQry = createPQExpBuffer ();
18321831PQExpBuffer creaQry = createPQExpBuffer ();
1832+ PGconn * conn = GetConnection (fout );
18331833PGresult * res ;
18341834int ntups ;
18351835int i_tableoid ,
@@ -1850,7 +1850,7 @@ dumpDatabase(Archive *fout)
18501850* tablespace ;
18511851uint32 frozenxid ;
18521852
1853- datname = PQdb (g_conn );
1853+ datname = PQdb (conn );
18541854
18551855if (g_verbose )
18561856write_msg (NULL ,"saving database definition\n" );
@@ -2150,10 +2150,10 @@ dumpDatabase(Archive *fout)
21502150{
21512151PQExpBuffer seclabelQry = createPQExpBuffer ();
21522152
2153- buildShSecLabelQuery (g_conn ,"pg_database" ,dbCatId .oid ,seclabelQry );
2153+ buildShSecLabelQuery (conn ,"pg_database" ,dbCatId .oid ,seclabelQry );
21542154res = ExecuteSqlQuery (fout ,seclabelQry -> data ,PGRES_TUPLES_OK );
21552155resetPQExpBuffer (seclabelQry );
2156- emitShSecLabels (g_conn ,res ,seclabelQry ,"DATABASE" ,datname );
2156+ emitShSecLabels (conn ,res ,seclabelQry ,"DATABASE" ,datname );
21572157if (strlen (seclabelQry -> data ))
21582158ArchiveEntry (fout ,dbCatId ,createDumpId (),datname ,NULL ,NULL ,
21592159dba , false,"SECURITY LABEL" ,SECTION_NONE ,
@@ -2362,6 +2362,7 @@ dumpBlobs(Archive *fout, void *arg)
23622362{
23632363const char * blobQry ;
23642364const char * blobFetchQry ;
2365+ PGconn * conn = GetConnection (fout );
23652366PGresult * res ;
23662367char buf [LOBBUFSIZE ];
23672368int ntups ;
@@ -2404,11 +2405,11 @@ dumpBlobs(Archive *fout, void *arg)
24042405
24052406blobOid = atooid (PQgetvalue (res ,i ,0 ));
24062407/* Open the BLOB */
2407- loFd = lo_open (g_conn ,blobOid ,INV_READ );
2408+ loFd = lo_open (conn ,blobOid ,INV_READ );
24082409if (loFd == -1 )
24092410{
24102411write_msg (NULL ,"could not open large object %u: %s" ,
2411- blobOid ,PQerrorMessage (g_conn ));
2412+ blobOid ,PQerrorMessage (conn ));
24122413exit_nicely (1 );
24132414}
24142415
@@ -2417,18 +2418,18 @@ dumpBlobs(Archive *fout, void *arg)
24172418/* Now read it in chunks, sending data to archive */
24182419do
24192420{
2420- cnt = lo_read (g_conn ,loFd ,buf ,LOBBUFSIZE );
2421+ cnt = lo_read (conn ,loFd ,buf ,LOBBUFSIZE );
24212422if (cnt < 0 )
24222423{
24232424write_msg (NULL ,"error reading large object %u: %s" ,
2424- blobOid ,PQerrorMessage (g_conn ));
2425+ blobOid ,PQerrorMessage (conn ));
24252426exit_nicely (1 );
24262427}
24272428
24282429WriteData (fout ,buf ,cnt );
24292430}while (cnt > 0 );
24302431
2431- lo_close (g_conn ,loFd );
2432+ lo_close (conn ,loFd );
24322433
24332434EndBlob (fout ,blobOid );
24342435}
@@ -4298,7 +4299,7 @@ getTables(Archive *fout, int *numTables)
42984299 */
42994300resetPQExpBuffer (query );
43004301appendPQExpBuffer (query ,"SET statement_timeout = " );
4301- appendStringLiteralConn (query ,lockWaitTimeout ,g_conn );
4302+ appendStringLiteralConn (query ,lockWaitTimeout ,GetConnection ( fout ) );
43024303ExecuteSqlStatement (fout ,query -> data );
43034304}
43044305