Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1631598

Browse files
committed
pg_dump: Further reduce reliance on global variables.
This is another round of refactoring to make things simpler for parallel pg_dump. pg_dump.c now issues SQL queries through the relevant Archive object, rather than relying on the global variable g_conn. This commit isn't quite enough to get rid of g_conn entirely, but it makes a big dent in its utilization and, along the way, manages to be slightly less code than before.
1 parent a347f96 commit 1631598

File tree

5 files changed

+218
-270
lines changed

5 files changed

+218
-270
lines changed

src/bin/pg_dump/pg_backup_archiver.c

+10
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, const char *modulename,
1459+
const char *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

+1
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ typedef struct _tocEntry
325325

326326

327327
extern void die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4), noreturn));
328+
extern void die_on_query_failure(ArchiveHandle *AH, const char *modulename, const char *query) __attribute__((noreturn));
328329
extern void warn_or_die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
329330

330331
extern void WriteTOC(ArchiveHandle *AH);

src/bin/pg_dump/pg_backup_db.c

+24
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, const char *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, const char *query, ExecStatusType status)
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+
return res;
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

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
extern int ExecuteSqlCommandBuf(ArchiveHandle *AH, const char *buf, size_t bufLen);
1414

15+
extern void ExecuteSqlStatement(Archive *AHX, const char *query);
16+
extern PGresult *ExecuteSqlQuery(Archive *AHX, const char *query,
17+
ExecStatusType status);
18+
1519
extern void EndDBCopyMode(ArchiveHandle *AH, struct _tocEntry * te);
1620

1721
extern void StartTransaction(ArchiveHandle *AH);

0 commit comments

Comments
 (0)