aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2015-03-23 15:57:11 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2015-03-23 15:57:11 -0300
commit871293fb7fa869fbe0f202bef2e0d781bfd21b3e (patch)
tree756e2bd697457b7db747fd75346840cf762bf31c
parent4babae1a8607ad445cbe761da7f46bb90b156287 (diff)
downloadpostgresql-871293fb7fa869fbe0f202bef2e0d781bfd21b3e.tar.gz
postgresql-871293fb7fa869fbe0f202bef2e0d781bfd21b3e.zip
vacuumdb: Check result status of PQsendQuery
Noticed by Coverity
-rw-r--r--src/bin/scripts/vacuumdb.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index c80848b3dde..2cd4aa65442 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -484,6 +484,11 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts,
else
free_slot = slots;
+ /*
+ * Execute the vacuum. If not in parallel mode, this terminates the
+ * program in case of an error. (The parallel case handles query
+ * errors in GetQueryResult through GetIdleSlot.)
+ */
run_vacuum_command(free_slot->connection, sql.data,
echo, dbname, tabname, progname, parallel);
@@ -661,21 +666,27 @@ prepare_vacuum_command(PQExpBuffer sql, PGconn *conn, vacuumingOptions *vacopts,
/*
* Execute a vacuum/analyze command to the server.
*
- * Result status is checked only if 'async' is false.
+ * Any errors during command execution are reported to stderr. If async is
+ * false, this function exits the program after reporting the error.
*/
static void
run_vacuum_command(PGconn *conn, const char *sql, bool echo,
const char *dbname, const char *table,
const char *progname, bool async)
{
+ bool status;
+
if (async)
{
if (echo)
printf("%s\n", sql);
- PQsendQuery(conn, sql);
+ status = PQsendQuery(conn, sql) == 1;
}
- else if (!executeMaintenanceCommand(conn, sql, echo))
+ else
+ status = executeMaintenanceCommand(conn, sql, echo);
+
+ if (!status)
{
if (table)
fprintf(stderr,
@@ -684,8 +695,12 @@ run_vacuum_command(PGconn *conn, const char *sql, bool echo,
else
fprintf(stderr, _("%s: vacuuming of database \"%s\" failed: %s"),
progname, dbname, PQerrorMessage(conn));
- PQfinish(conn);
- exit(1);
+
+ if (!async)
+ {
+ PQfinish(conn);
+ exit(1);
+ }
}
}