When running a VACUUM or CLUSTER command, the namespace name is not part of
the emitted message.

Using `vacuumdb` CLI tool recently with multiple jobs, I found that
reading the output messages harder to match the relations with their
namespaces.

Example:

INFO:  vacuuming "sendgrid.open"
INFO:  vacuuming "mailgun.open"
...
INFO:  "open": found 0 removable, 31460776 nonremovable row versions in
1358656 pages
DETAIL:  0 dead row versions cannot be removed yet.
CPU 31.35s/261.26u sec elapsed 1620.68 sec.
...

In this example. the user can't readily tell which `open` relation was
completed.

Attached is a patch using existing functions to include the namespace in
the output string.

Looking forward to feedback!
-Mike Fiedler
From c66506ad7440a1b501cca858b5120cc568f7a00b Mon Sep 17 00:00:00 2001
From: Mike Fiedler <miketheman@gmail.com>
Date: Tue, 22 Jun 2021 12:05:48 -0400
Subject: [PATCH] Emit namespace in post-copy output

During a VACUUM or CLUSTER command, the initial output emits the
relation namespace along with the relation name.

Add the namespace to the post-action to match the initial `errmsg`
using the same functions to build the string.

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
---
 src/backend/access/heap/vacuumlazy.c | 3 ++-
 src/backend/commands/cluster.c       | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c
index 44f198398c..bd30461dec 100644
--- a/src/backend/access/heap/vacuumlazy.c
+++ b/src/backend/access/heap/vacuumlazy.c
@@ -1673,7 +1673,8 @@ lazy_scan_heap(LVRelState *vacrel, VacuumParams *params, bool aggressive)
 	appendStringInfo(&buf, _("%s."), pg_rusage_show(&ru0));
 
 	ereport(elevel,
-			(errmsg("\"%s\": found %lld removable, %lld nonremovable row versions in %u out of %u pages",
+			(errmsg("\"%s.%s\": found %lld removable, %lld nonremovable row versions in %u out of %u pages",
+					vacrel->relnamespace,
 					vacrel->relname,
 					(long long) vacrel->tuples_deleted,
 					(long long) vacrel->num_tuples, vacrel->scanned_pages,
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c
index 6487a9e3fc..e4c577cfff 100644
--- a/src/backend/commands/cluster.c
+++ b/src/backend/commands/cluster.c
@@ -921,7 +921,8 @@ copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, bool verbose,
 
 	/* Log what we did */
 	ereport(elevel,
-			(errmsg("\"%s\": found %.0f removable, %.0f nonremovable row versions in %u pages",
+			(errmsg("\"%s.%s\": found %.0f removable, %.0f nonremovable row versions in %u pages",
+					get_namespace_name(RelationGetNamespace(OldHeap)),
 					RelationGetRelationName(OldHeap),
 					tups_vacuumed, num_tuples,
 					RelationGetNumberOfBlocks(OldHeap)),
-- 
2.30.1 (Apple Git-130)

Reply via email to