From 2350a42ec46ab511020060b3f4427848628b0ecb Mon Sep 17 00:00:00 2001 From: Timur Birsh Date: Fri, 14 Jun 2019 04:31:28 +0000 Subject: [PATCH] Report the number of large objects going to be removed --- contrib/vacuumlo/vacuumlo.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/contrib/vacuumlo/vacuumlo.c b/contrib/vacuumlo/vacuumlo.c index 73c06a043e..77e91ff7ad 100644 --- a/contrib/vacuumlo/vacuumlo.c +++ b/contrib/vacuumlo/vacuumlo.c @@ -60,17 +60,18 @@ static void usage(const char *progname); static int vacuumlo(const char *database, const struct _param *param) { - PGconn *conn; - PGresult *res, - *res2; + PGconn *conn; + PGresult *res, + *res2; char buf[BUFSIZE]; + long to_delete = 0; long matched; long deleted; - int i; + int i; bool new_pass; bool success = true; - static bool have_password = false; - static char password[100]; + static bool have_password = false; + static char password[100]; /* Note: password can be carried over from a previous call */ if (param->pg_prompt == TRI_YES && !have_password) @@ -171,6 +172,7 @@ vacuumlo(const char *database, const struct _param *param) PQfinish(conn); return -1; } + to_delete = strtol(PQcmdTuples(res), NULL, 10); PQclear(res); /* @@ -221,9 +223,10 @@ vacuumlo(const char *database, const struct _param *param) for (i = 0; i < PQntuples(res); i++) { - char *schema, - *table, - *field; + char *schema, + *table, + *field; + long excluded; schema = PQgetvalue(res, i, 0); table = PQgetvalue(res, i, 1); @@ -268,7 +271,9 @@ vacuumlo(const char *database, const struct _param *param) PQfreemem(field); return -1; } + excluded = strtol(PQcmdTuples(res2), NULL, 10); PQclear(res2); + to_delete -= excluded; PQfreemem(schema); PQfreemem(table); @@ -276,6 +281,9 @@ vacuumlo(const char *database, const struct _param *param) } PQclear(res); + if (param->verbose) + fprintf(stdout, "%ld large objects will be removed\n", to_delete); + /* * Now, those entries remaining in vacuum_l are orphans. Delete 'em. * @@ -339,7 +347,8 @@ vacuumlo(const char *database, const struct _param *param) if (param->verbose) { - fprintf(stdout, "\rRemoving lo %6u ", lo); + fprintf(stdout, "\rRemoving lo %6u\t(%3.f%%)", lo, + ((float) deleted / (float) to_delete) * 100); fflush(stdout); } -- 2.17.1