How to do it...

Follow these steps to examine the PostgreSQL processes in various ways:

  1. In our PostgreSQL connection, execute the following query to find the process ID of the server backend assigned to us:
        SELECT pg_backend_pid() AS pid; 
  1. As our root-capable user, attach strace to the preceding pid (4200, for example) with this command:
        sudo strace -p 4200
  1. In our PostgreSQL connection, execute the following query to generate some activity:
        SELECT 1; 
  1. In the terminal where strace is running, press Ctrl + C to disconnect.
  2. Attach strace again, but collect the statistics with the following command:
        strace -c -S calls -p 4200
  1. Now, execute the following query to generate some complex activity:
 SELECT * FROM information_schema.columns; ...

Get PostgreSQL High Availability Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.