From 8465774c33b200c1a531465acaef85d2d261bb26 Mon Sep 17 00:00:00 2001
From: Timur Birsh <taem@linukz.org>
Date: Wed, 12 Jun 2019 04:13:29 +0000
Subject: [PATCH 1/2] vacuumlo: print the number of large objects going to be
 removed

If tables has a lot of rows with large objects (>1_000_000) that
removed throughout the day, it would be useful to know how many
LOs going to be removed.
---
 contrib/vacuumlo/vacuumlo.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/contrib/vacuumlo/vacuumlo.c b/contrib/vacuumlo/vacuumlo.c
index 73c06a043e..beade1c9c0 100644
--- a/contrib/vacuumlo/vacuumlo.c
+++ b/contrib/vacuumlo/vacuumlo.c
@@ -64,6 +64,7 @@ vacuumlo(const char *database, const struct _param *param)
 	PGresult   *res,
 			   *res2;
 	char		buf[BUFSIZE];
+	long		to_delete = 0;
 	long		matched;
 	long		deleted;
 	int			i;
@@ -276,6 +277,25 @@ vacuumlo(const char *database, const struct _param *param)
 	}
 	PQclear(res);
 
+	if (param->verbose)
+	{
+		snprintf(buf, BUFSIZE, "SELECT count(*) FROM vacuum_l");
+		res = PQexec(conn, buf);
+		if (PQresultStatus(res) != PGRES_TUPLES_OK)
+		{
+			fprintf(stderr, "Failed to get number of large objects "
+					"going to be removed:\n");
+			fprintf(stderr, "%s", PQerrorMessage(conn));
+			PQclear(res);
+			PQfinish(conn);
+			return -1;
+		}
+		to_delete = strtol(PQgetvalue(res, 0, 0), NULL, 10);
+		PQclear(res);
+		fprintf(stdout, "%ld large objects will be removed\n",
+				to_delete);
+	}
+
 	/*
 	 * Now, those entries remaining in vacuum_l are orphans.  Delete 'em.
 	 *
-- 
2.17.1

