Using PQtrace

To enable PQtrace, we need to add the following code into the client-side source in the function where it establishes the connection with the server.

FILE *trace_file;
.
.
.
<PQconnectdb>
trace_file = fopen("/tmp/trace.out","w");
PQtrace(conn, trace_file);
.
.
.
fclose(trace_file);
<return>

First, declare the file variable and just after the connection is established on the client-side (by PQconnectdb), open the file with write permissions and start the trace. Do not forget to close the file before your return from the function where you have added this code.

From the file specified, we can get all the messages exchanged between the client and the server.

If you need to further debug the source of the messages being passed then run the client command from gdb with a breakpoint at PQconnectdb where it connects to the server. When the process breaks, attach another gdb process to the server process created and set the libpq function breakpoints.

In the client-side put a breakpoint on the following:
b pqPutc b pqPuts b pqPutnchar b pqPutInt b pqPutMsgStart b pqPutMsgEnd  

In the server-side put a breakpoint on the following:
b socket_putmessage

Now continue and you can easily monitor step by step how the messages are passed from both sides as it hits the breakpoints above.

Investigating bulk load operation in partitioned tables

This blog is published on the EDB website.

pgbench partitions pgbench_accounts which is the largest table and uses the bulkload command COPY populate it. The time taken to run COPY on pgbench_accounts table is logged separately. This blog will explore how this operation is affected by table partitioning.