aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-trace.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2024-08-16 13:23:18 -0400
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2024-08-16 13:23:18 -0400
commitb8b3f861fbd7ff40055225ec48cec97df925ff04 (patch)
tree789bdecb4f5b0c775bd282e1a3c6d89d383d7396 /src/interfaces/libpq/fe-trace.c
parent6be39d77a70df52d5a0f2eb414ef9901ccf17e5a (diff)
downloadpostgresql-b8b3f861fbd7ff40055225ec48cec97df925ff04.tar.gz
postgresql-b8b3f861fbd7ff40055225ec48cec97df925ff04.zip
libpq: Trace all messages received from the server
Not all messages that libpq received from the server would be sent through our message tracing logic. This commit tries to fix that by introducing a new function pqParseDone which make it harder to forget about doing so. The messages that we now newly send through our tracing logic are: - CopyData (received by COPY TO STDOUT) - Authentication requests - NegotiateProtocolVersion - Some ErrorResponse messages during connection startup - ReadyForQuery when received after a FunctionCall message Author: Jelte Fennema-Nio <postgres@jeltef.nl> Discussion: https://postgr.es/m/CAGECzQSoPHtZ4xe0raJ6FYSEiPPS+YWXBhOGo+Y1YecLgknF3g@mail.gmail.com
Diffstat (limited to 'src/interfaces/libpq/fe-trace.c')
-rw-r--r--src/interfaces/libpq/fe-trace.c68
1 files changed, 63 insertions, 5 deletions
diff --git a/src/interfaces/libpq/fe-trace.c b/src/interfaces/libpq/fe-trace.c
index 3527b9f0f5d..bff7d919d57 100644
--- a/src/interfaces/libpq/fe-trace.c
+++ b/src/interfaces/libpq/fe-trace.c
@@ -281,6 +281,14 @@ pqTraceOutput_CommandComplete(FILE *f, const char *message, int *cursor)
}
static void
+pqTraceOutput_CopyData(FILE *f, const char *message, int *cursor, int length,
+ bool suppress)
+{
+ fprintf(f, "CopyData\t");
+ pqTraceOutputNchar(f, length - *cursor + 1, message, cursor, suppress);
+}
+
+static void
pqTraceOutput_DataRow(FILE *f, const char *message, int *cursor)
{
int nfields;
@@ -472,10 +480,58 @@ pqTraceOutput_Query(FILE *f, const char *message, int *cursor)
}
static void
-pqTraceOutput_Authentication(FILE *f, const char *message, int *cursor)
+pqTraceOutput_Authentication(FILE *f, const char *message, int *cursor,
+ int length, bool suppress)
{
- fprintf(f, "Authentication\t");
- pqTraceOutputInt32(f, message, cursor, false);
+ int authType = 0;
+
+ memcpy(&authType, message + *cursor, 4);
+ authType = (int) pg_ntoh32(authType);
+ *cursor += 4;
+ switch (authType)
+ {
+ case AUTH_REQ_OK:
+ fprintf(f, "AuthenticationOk");
+ break;
+ /* AUTH_REQ_KRB4 not supported */
+ /* AUTH_REQ_KRB5 not supported */
+ case AUTH_REQ_PASSWORD:
+ fprintf(f, "AuthenticationCleartextPassword");
+ break;
+ /* AUTH_REQ_CRYPT not supported */
+ case AUTH_REQ_MD5:
+ fprintf(f, "AuthenticationMD5Password");
+ break;
+ case AUTH_REQ_GSS:
+ fprintf(f, "AuthenticationGSS");
+ break;
+ case AUTH_REQ_GSS_CONT:
+ fprintf(f, "AuthenticationGSSContinue\t");
+ pqTraceOutputNchar(f, length - *cursor + 1, message, cursor,
+ suppress);
+ break;
+ case AUTH_REQ_SSPI:
+ fprintf(f, "AuthenticationSSPI");
+ break;
+ case AUTH_REQ_SASL:
+ fprintf(f, "AuthenticationSASL\t");
+ while (message[*cursor] != '\0')
+ pqTraceOutputString(f, message, cursor, false);
+ pqTraceOutputString(f, message, cursor, false);
+ break;
+ case AUTH_REQ_SASL_CONT:
+ fprintf(f, "AuthenticationSASLContinue\t");
+ pqTraceOutputNchar(f, length - *cursor + 1, message, cursor,
+ suppress);
+ break;
+ case AUTH_REQ_SASL_FIN:
+ fprintf(f, "AuthenticationSASLFinal\t");
+ pqTraceOutputNchar(f, length - *cursor + 1, message, cursor,
+ suppress);
+ break;
+ default:
+ fprintf(f, "Unknown authentication message %d", authType);
+ }
}
static void
@@ -625,7 +681,8 @@ pqTraceOutputMessage(PGconn *conn, const char *message, bool toServer)
pqTraceOutput_CommandComplete(conn->Pfdebug, message, &logCursor);
break;
case PqMsg_CopyData:
- /* Drop COPY data to reduce the overhead of logging. */
+ pqTraceOutput_CopyData(conn->Pfdebug, message, &logCursor,
+ length, regress);
break;
case PqMsg_Describe:
/* Describe(F) and DataRow(B) use the same identifier. */
@@ -714,7 +771,8 @@ pqTraceOutputMessage(PGconn *conn, const char *message, bool toServer)
pqTraceOutput_Query(conn->Pfdebug, message, &logCursor);
break;
case PqMsg_AuthenticationRequest:
- pqTraceOutput_Authentication(conn->Pfdebug, message, &logCursor);
+ pqTraceOutput_Authentication(conn->Pfdebug, message, &logCursor,
+ length, regress);
break;
case PqMsg_PortalSuspended:
fprintf(conn->Pfdebug, "PortalSuspended");