Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit689d0eb

Browse files
committed
pg_dump: Remove global connection pointer.
Parallel pg_dump wants to have multiple ArchiveHandle objects, andtherefore multiple PGconns, in play at the same time. This shouldbe just about the end of the refactoring that we need in order tomake that workable.
1 parent549e93c commit689d0eb

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed

‎src/bin/pg_dump/pg_backup.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,14 @@ typedef struct _restoreOptions
159159
* Main archiver interface.
160160
*/
161161

162-
externPGconn*ConnectDatabase(Archive*AH,
162+
externvoidConnectDatabase(Archive*AH,
163163
constchar*dbname,
164164
constchar*pghost,
165165
constchar*pgport,
166166
constchar*username,
167167
enumtrivalueprompt_password);
168168
externvoidDisconnectDatabase(Archive*AHX);
169+
externPGconn*GetConnection(Archive*AHX);
169170

170171
/* Called to add a TOC entry */
171172
externvoidArchiveEntry(Archive*AHX,

‎src/bin/pg_dump/pg_backup_db.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ _connectDB(ArchiveHandle *AH, const char *reqdb, const char *requser)
225225
* cache if the username keeps changing. In current usage, however, the
226226
* username never does change, so one savedPassword is sufficient.
227227
*/
228-
PGconn*
228+
void
229229
ConnectDatabase(Archive*AHX,
230230
constchar*dbname,
231231
constchar*pghost,
@@ -306,8 +306,6 @@ ConnectDatabase(Archive *AHX,
306306
_check_database_version(AH);
307307

308308
PQsetNoticeProcessor(AH->connection,notice_processor,NULL);
309-
310-
returnAH->connection;
311309
}
312310

313311
void
@@ -319,6 +317,13 @@ DisconnectDatabase(Archive *AHX)
319317
AH->connection=NULL;
320318
}
321319

320+
PGconn*
321+
GetConnection(Archive*AHX)
322+
{
323+
ArchiveHandle*AH= (ArchiveHandle*)AHX;
324+
325+
returnAH->connection;
326+
}
322327

323328
staticvoid
324329
notice_processor(void*arg,constchar*message)

‎src/bin/pg_dump/pg_dump.c

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ typedef struct
8686
/* global decls */
8787
boolg_verbose;/* User wants verbose narration of our
8888
* activities. */
89-
PGconn*g_conn;/* the database connection */
9089

9190
/* various user-settable parameters */
9291
boolschemaOnly;
@@ -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);
620617
setup_connection(fout,dumpencoding,use_role);
621618

622619
/*
@@ -657,7 +654,8 @@ main(int argc, char **argv)
657654
if (fout->remoteVersion<70300)
658655
{
659656
if (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)));
661659
else
662660
g_last_builtin_oid=findLastBuiltinOid_V70(fout);
663661
if (g_verbose)
@@ -870,12 +868,13 @@ pgdump_cleanup_at_exit(int code, void *arg)
870868
staticvoid
871869
setup_connection(Archive*AH,constchar*dumpencoding,char*use_role)
872870
{
871+
PGconn*conn=GetConnection(AH);
873872
constchar*std_strings;
874873

875874
/* Set the client encoding if requested */
876875
if (dumpencoding)
877876
{
878-
if (PQsetClientEncoding(g_conn,dumpencoding)<0)
877+
if (PQsetClientEncoding(conn,dumpencoding)<0)
879878
{
880879
write_msg(NULL,"invalid client encoding \"%s\" specified\n",
881880
dumpencoding);
@@ -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");
893892
AH->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,
10181017
appendPQExpBuffer(query,"UNION ALL\n");
10191018
appendPQExpBuffer(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

10261024
res=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",
10691067
RELKIND_RELATION,RELKIND_SEQUENCE,RELKIND_VIEW,
10701068
RELKIND_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)
12661264
constboolhasoids=tbinfo->hasoids;
12671265
constbooloids=tdinfo->oids;
12681266
PQExpBufferq=createPQExpBuffer();
1267+
PGconn*conn=GetConnection(fout);
12691268
PGresult*res;
12701269
intret;
12711270
char*copybuf;
@@ -1332,7 +1331,7 @@ dumpTableData_copy(Archive *fout, void *dcontext)
13321331

13331332
for (;;)
13341333
{
1335-
ret=PQgetCopyData(g_conn,&copybuf,0);
1334+
ret=PQgetCopyData(conn,&copybuf,0);
13361335

13371336
if (ret<0)
13381337
break;/* done or error */
@@ -1395,17 +1394,17 @@ dumpTableData_copy(Archive *fout, void *dcontext)
13951394
{
13961395
/* copy data transfer failed */
13971396
write_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));
13991398
write_msg(NULL,"The command was: %s\n",q->data);
14001399
exit_nicely(1);
14011400
}
14021401

14031402
/* Check command status and return to normal libpq state */
1404-
res=PQgetResult(g_conn);
1403+
res=PQgetResult(conn);
14051404
if (PQresultStatus(res)!=PGRES_COMMAND_OK)
14061405
{
14071406
write_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));
14091408
write_msg(NULL,"The command was: %s\n",q->data);
14101409
exit_nicely(1);
14111410
}
@@ -1830,6 +1829,7 @@ dumpDatabase(Archive *fout)
18301829
PQExpBufferdbQry=createPQExpBuffer();
18311830
PQExpBufferdelQry=createPQExpBuffer();
18321831
PQExpBuffercreaQry=createPQExpBuffer();
1832+
PGconn*conn=GetConnection(fout);
18331833
PGresult*res;
18341834
intntups;
18351835
inti_tableoid,
@@ -1850,7 +1850,7 @@ dumpDatabase(Archive *fout)
18501850
*tablespace;
18511851
uint32frozenxid;
18521852

1853-
datname=PQdb(g_conn);
1853+
datname=PQdb(conn);
18541854

18551855
if (g_verbose)
18561856
write_msg(NULL,"saving database definition\n");
@@ -2150,10 +2150,10 @@ dumpDatabase(Archive *fout)
21502150
{
21512151
PQExpBufferseclabelQry=createPQExpBuffer();
21522152

2153-
buildShSecLabelQuery(g_conn,"pg_database",dbCatId.oid,seclabelQry);
2153+
buildShSecLabelQuery(conn,"pg_database",dbCatId.oid,seclabelQry);
21542154
res=ExecuteSqlQuery(fout,seclabelQry->data,PGRES_TUPLES_OK);
21552155
resetPQExpBuffer(seclabelQry);
2156-
emitShSecLabels(g_conn,res,seclabelQry,"DATABASE",datname);
2156+
emitShSecLabels(conn,res,seclabelQry,"DATABASE",datname);
21572157
if (strlen(seclabelQry->data))
21582158
ArchiveEntry(fout,dbCatId,createDumpId(),datname,NULL,NULL,
21592159
dba, false,"SECURITY LABEL",SECTION_NONE,
@@ -2362,6 +2362,7 @@ dumpBlobs(Archive *fout, void *arg)
23622362
{
23632363
constchar*blobQry;
23642364
constchar*blobFetchQry;
2365+
PGconn*conn=GetConnection(fout);
23652366
PGresult*res;
23662367
charbuf[LOBBUFSIZE];
23672368
intntups;
@@ -2404,11 +2405,11 @@ dumpBlobs(Archive *fout, void *arg)
24042405

24052406
blobOid=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);
24082409
if (loFd==-1)
24092410
{
24102411
write_msg(NULL,"could not open large object %u: %s",
2411-
blobOid,PQerrorMessage(g_conn));
2412+
blobOid,PQerrorMessage(conn));
24122413
exit_nicely(1);
24132414
}
24142415

@@ -2417,18 +2418,18 @@ dumpBlobs(Archive *fout, void *arg)
24172418
/* Now read it in chunks, sending data to archive */
24182419
do
24192420
{
2420-
cnt=lo_read(g_conn,loFd,buf,LOBBUFSIZE);
2421+
cnt=lo_read(conn,loFd,buf,LOBBUFSIZE);
24212422
if (cnt<0)
24222423
{
24232424
write_msg(NULL,"error reading large object %u: %s",
2424-
blobOid,PQerrorMessage(g_conn));
2425+
blobOid,PQerrorMessage(conn));
24252426
exit_nicely(1);
24262427
}
24272428

24282429
WriteData(fout,buf,cnt);
24292430
}while (cnt>0);
24302431

2431-
lo_close(g_conn,loFd);
2432+
lo_close(conn,loFd);
24322433

24332434
EndBlob(fout,blobOid);
24342435
}
@@ -4298,7 +4299,7 @@ getTables(Archive *fout, int *numTables)
42984299
*/
42994300
resetPQExpBuffer(query);
43004301
appendPQExpBuffer(query,"SET statement_timeout = ");
4301-
appendStringLiteralConn(query,lockWaitTimeout,g_conn);
4302+
appendStringLiteralConn(query,lockWaitTimeout,GetConnection(fout));
43024303
ExecuteSqlStatement(fout,query->data);
43034304
}
43044305

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp