@@ -484,6 +484,11 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts,
484484 else
485485 free_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+ */
487492 run_vacuum_command (free_slot -> connection , sql .data ,
488493 echo , 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 ,
668674 const char * dbname , const char * table ,
669675 const char * progname , bool async )
670676{
677+ bool status ;
678+
671679 if (async )
672680 {
673681 if (echo )
674682 printf ("%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 {
680691 if (table )
681692 fprintf (stderr ,
@@ -684,8 +695,12 @@ run_vacuum_command(PGconn *conn, const char *sql, bool echo,
684695 else
685696 fprintf (stderr , _ ("%s: vacuuming of database \"%s\" failed: %s" ),
686697 progname , dbname , PQerrorMessage (conn ));
687- PQfinish (conn );
688- exit (1 );
698+
699+ if (!async )
700+ {
701+ PQfinish (conn );
702+ exit (1 );
703+ }
689704 }
690705}
691706
0 commit comments