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;
 		}
 	}
