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

Commit1631598

Browse files
committed
pg_dump: Further reduce reliance on global variables.
This is another round of refactoring to make things simpler for parallelpg_dump. pg_dump.c now issues SQL queries through the relevant Archiveobject, rather than relying on the global variable g_conn. This commitisn't quite enough to get rid of g_conn entirely, but it makes a bigdent in its utilization and, along the way, manages to be slightly lesscode than before.
1 parenta347f96 commit1631598

File tree

5 files changed

+218
-270
lines changed

5 files changed

+218
-270
lines changed

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,16 @@ die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...)
14531453
va_end(ap);
14541454
}
14551455

1456+
/* As above, but with a complaint about a particular query. */
1457+
void
1458+
die_on_query_failure(ArchiveHandle*AH,constchar*modulename,
1459+
constchar*query)
1460+
{
1461+
write_msg(modulename,"query failed: %s",
1462+
PQerrorMessage(AH->connection));
1463+
die_horribly(AH,modulename,"query was: %s\n",query);
1464+
}
1465+
14561466
/* on some error, we may decide to go on... */
14571467
void
14581468
warn_or_die_horribly(ArchiveHandle*AH,

‎src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ typedef struct _tocEntry
325325

326326

327327
externvoiddie_horribly(ArchiveHandle*AH,constchar*modulename,constchar*fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE,3,4),noreturn));
328+
externvoiddie_on_query_failure(ArchiveHandle*AH,constchar*modulename,constchar*query) __attribute__((noreturn));
328329
externvoidwarn_or_die_horribly(ArchiveHandle*AH,constchar*modulename,constchar*fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE,3,4)));
329330

330331
externvoidWriteTOC(ArchiveHandle*AH);

‎src/bin/pg_dump/pg_backup_db.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,30 @@ notice_processor(void *arg, const char *message)
318318
}
319319

320320

321+
void
322+
ExecuteSqlStatement(Archive*AHX,constchar*query)
323+
{
324+
ArchiveHandle*AH= (ArchiveHandle*)AHX;
325+
PGresult*res;
326+
327+
res=PQexec(AH->connection,query);
328+
if (PQresultStatus(res)!=PGRES_COMMAND_OK)
329+
die_on_query_failure(AH,modulename,query);
330+
PQclear(res);
331+
}
332+
333+
PGresult*
334+
ExecuteSqlQuery(Archive*AHX,constchar*query,ExecStatusTypestatus)
335+
{
336+
ArchiveHandle*AH= (ArchiveHandle*)AHX;
337+
PGresult*res;
338+
339+
res=PQexec(AH->connection,query);
340+
if (PQresultStatus(res)!=status)
341+
die_on_query_failure(AH,modulename,query);
342+
returnres;
343+
}
344+
321345
/*
322346
* Convenience function to send a query.
323347
* Monitors result to detect COPY statements

‎src/bin/pg_dump/pg_backup_db.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
externintExecuteSqlCommandBuf(ArchiveHandle*AH,constchar*buf,size_tbufLen);
1414

15+
externvoidExecuteSqlStatement(Archive*AHX,constchar*query);
16+
externPGresult*ExecuteSqlQuery(Archive*AHX,constchar*query,
17+
ExecStatusTypestatus);
18+
1519
externvoidEndDBCopyMode(ArchiveHandle*AH,struct_tocEntry*te);
1620

1721
externvoidStartTransaction(ArchiveHandle*AH);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp