More consistent error reporting
This patch is a port of Daniele's commit 0be414ad10c32d from his own fork, "error_reporting" branch. reorg_all_database can return an error message: in case of any error different from "missing schema" return the error and keep processing the other databases instead of printing and stopping the program. The output of the program is now something like: $ pg_reorg --all pg_reorg: reorg database "contrib_regression" pg_reorg: reorg database "template1" ... skipped: pg_reorg is not installed in the database
This commit is contained in:
parent
8ba92a1f49
commit
3c73a0204a
@ -107,7 +107,7 @@ typedef struct repack_index
|
||||
} repack_index;
|
||||
|
||||
static void repack_all_databases(const char *order_by);
|
||||
static bool repack_one_database(const char *order_by);
|
||||
static bool repack_one_database(const char *order_by, char *errbuf, size_t errsize);
|
||||
static void repack_one_table(const repack_table *table, const char *order_by);
|
||||
static void repack_cleanup(bool fatal, const repack_table *table);
|
||||
|
||||
@ -178,10 +178,11 @@ main(int argc, char *argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!repack_one_database(orderby))
|
||||
char errbuf[256];
|
||||
if (!repack_one_database(orderby, errbuf, sizeof(errbuf)))
|
||||
ereport(ERROR,
|
||||
(errcode(ENOENT),
|
||||
errmsg("%s is not installed", PROGRAM_NAME)));
|
||||
(errcode(ERROR),
|
||||
errmsg("%s", errbuf)));
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -204,23 +205,24 @@ repack_all_databases(const char *orderby)
|
||||
for (i = 0; i < PQntuples(result); i++)
|
||||
{
|
||||
bool ret;
|
||||
char errbuf[256];
|
||||
|
||||
dbname = PQgetvalue(result, i, 0);
|
||||
|
||||
if (pgut_log_level >= INFO)
|
||||
{
|
||||
printf("%s: repack database \"%s\"", PROGRAM_NAME, dbname);
|
||||
printf("%s: repack database \"%s\"\n", PROGRAM_NAME, dbname);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
ret = repack_one_database(orderby);
|
||||
ret = repack_one_database(orderby, errbuf, sizeof(errbuf));
|
||||
|
||||
if (pgut_log_level >= INFO)
|
||||
{
|
||||
if (ret)
|
||||
printf("\n");
|
||||
else
|
||||
printf(" ... skipped\n");
|
||||
printf(" ... skipped: %s\n", errbuf);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
@ -252,7 +254,7 @@ getoid(PGresult *res, int row, int col)
|
||||
* Call repack_one_table for the target table or each table in a database.
|
||||
*/
|
||||
static bool
|
||||
repack_one_database(const char *orderby)
|
||||
repack_one_database(const char *orderby, char *errbuf, size_t errsize)
|
||||
{
|
||||
bool ret = true;
|
||||
PGresult *res;
|
||||
@ -303,22 +305,25 @@ repack_one_database(const char *orderby)
|
||||
res = execute_elevel(sql.data, 0, NULL, DEBUG2);
|
||||
}
|
||||
|
||||
/* on error skip the database */
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
if (sqlstate_equals(res, SQLSTATE_INVALID_SCHEMA_NAME))
|
||||
{
|
||||
/* Schema repack does not exist. Skip the database. */
|
||||
PQclear(res);
|
||||
ret = false;
|
||||
goto cleanup;
|
||||
if (errbuf)
|
||||
snprintf(errbuf, errsize,
|
||||
"%s is not installed in the database", PROGRAM_NAME);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* exit otherwise */
|
||||
elog(ERROR, "%s", PQerrorMessage(connection));
|
||||
PQclear(res);
|
||||
exit(1);
|
||||
/* Return the error message otherwise */
|
||||
if (errbuf)
|
||||
snprintf(errbuf, errsize, "%s", PQerrorMessage(connection));
|
||||
}
|
||||
ret = false;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
num = PQntuples(res);
|
||||
|
Loading…
x
Reference in New Issue
Block a user