Broken PQtrace CopyData display

From: "Ran Benita" <ran(at)unusedvar(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Broken PQtrace CopyData display
Date: 2025-08-29 19:45:18
Message-ID: a3383211-4539-459b-9d51-95c736ef08e0@app.fastmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

I used PQtrace to trace a logical decoding session, and was confused to see
lines like this:

2025-08-29 22:09:57.633980 F 38 CopyData 'r\x00\x00\x00\x00\xffffff8e\x07\xffffff85x\x00\x00\x00\x00\xffffff8e\x07\xffffff85x\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\xffffffe0\xffffff84\xffffff89R\xffffffd7\xffffffb8\x00'

The data doesn't make sense and has the wrong length. A quick look shows that
the \xffffff85 parts are a signedness issue (on my compiler char is signed).

I instead expect to see output like this:

2025-08-29 22:39:17.041261 F 38 CopyData 'r\x00\x00\x00\x00\x8e\x07\x89\xf8\x00\x00\x00\x00\x8e\x07\x89\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\xe0\x84\xf21Dh\x00'

The diff below fixes this particular problem, though they say bugs are like
mushrooms, if you find one then there are probably others nearby, so a more
comprehensive fix may be warranted.

diff --git i/src/interfaces/libpq/fe-trace.c w/src/interfaces/libpq/fe-trace.c
index a45f0d85587..f487c111fc7 100644
--- i/src/interfaces/libpq/fe-trace.c
+++ w/src/interfaces/libpq/fe-trace.c
@@ -212,7 +212,7 @@ pqTraceOutputNchar(FILE *pfdebug, int len, const char *data, int *cursor, bool s
else
{
fwrite(v + next, 1, i - next, pfdebug);
- fprintf(pfdebug, "\\x%02x", v[i]);
+ fprintf(pfdebug, "\\x%02x", (unsigned char) v[i]);
next = i + 1;
}
}

Browse pgsql-bugs by date

  From Date Subject
Next Message ZhangChi 2025-08-30 01:51:46 Re: BUG #19036: Failed prepared INSERT statement make another SELECT query generate wrong result
Previous Message Tom Lane 2025-08-29 15:55:46 Re: BUG #18959: Name collisions of expression indexes during parallel Index creations on a pratitioned table.