@@ -484,6 +484,11 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts,
484484else
485485free_slot = slots ;
486486
487+ /*
488+ * Execute the vacuum. If not in parallel mode, this terminates the
489+ * program in case of an error. (The parallel case handles query
490+ * errors in GetQueryResult through GetIdleSlot.)
491+ */
487492run_vacuum_command (free_slot -> connection ,sql .data ,
488493echo ,dbname ,tabname ,progname ,parallel );
489494
@@ -661,21 +666,27 @@ prepare_vacuum_command(PQExpBuffer sql, PGconn *conn, vacuumingOptions *vacopts,
661666/*
662667 * Execute a vacuum/analyze command to the server.
663668 *
664- * Result status is checked only if 'async' is false.
669+ * Any errors during command execution are reported to stderr. If async is
670+ * false, this function exits the program after reporting the error.
665671 */
666672static void
667673run_vacuum_command (PGconn * conn ,const char * sql ,bool echo ,
668674const char * dbname ,const char * table ,
669675const char * progname ,bool async )
670676{
677+ bool status ;
678+
671679if (async )
672680{
673681if (echo )
674682printf ("%s\n" ,sql );
675683
676- PQsendQuery (conn ,sql );
684+ status = PQsendQuery (conn ,sql )== 1 ;
677685}
678- else if (!executeMaintenanceCommand (conn ,sql ,echo ))
686+ else
687+ status = executeMaintenanceCommand (conn ,sql ,echo );
688+
689+ if (!status )
679690{
680691if (table )
681692fprintf (stderr ,
@@ -684,8 +695,12 @@ run_vacuum_command(PGconn *conn, const char *sql, bool echo,
684695else
685696fprintf (stderr ,_ ("%s: vacuuming of database \"%s\" failed: %s" ),
686697progname ,dbname ,PQerrorMessage (conn ));
687- PQfinish (conn );
688- exit (1 );
698+
699+ if (!async )
700+ {
701+ PQfinish (conn );
702+ exit (1 );
703+ }
689704}
690705}
691706