diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index ee1134aea2..9e1c31413a 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -3297,10 +3297,20 @@ executeMetaCommand(CState *st, instr_time *now)
 
 	if (unlikely(__pg_log_level <= PG_LOG_DEBUG))
 	{
-		fprintf(stderr, "client %d executing \\%s", st->id, argv[0]);
+		PQExpBufferData	buf;
+
+		initPQExpBuffer(&buf);
+
+		printfPQExpBuffer(&buf, "client %d executing \\%s", st->id, argv[0]);
 		for (int i = 1; i < argc; i++)
-			fprintf(stderr, " %s", argv[i]);
-		fprintf(stderr, "\n");
+		{
+			appendPQExpBufferChar(&buf, ' ');
+			appendPQExpBufferStr(&buf, argv[i]);
+		}
+
+		pg_log_debug("%s", buf.data);
+
+		termPQExpBuffer(&buf);
 	}
 
 	if (command->meta == META_SLEEP)
