How to do it...

All queries in this recipe should be performed by the bench_user mapped user in the pgbench database on the pg-report PostgreSQL server. Follow these steps:

  1. Execute the following simple query to view a remote query plan:
        EXPLAIN VERBOSE
        SELECT aid, bid, abalance
          FROM pgbench_accounts
         WHERE aid BETWEEN 500000 AND 500004;
  1. Execute this SQL statement to examine how PostgreSQL handles remote aggregates:
        EXPLAIN VERBOSE
         SELECT sum(abalance)
           FROM pgbench_accounts
          WHERE aid BETWEEN 500000 AND 500004;
  1. Execute this SQL statement to see a query plan involving a JOIN:
        EXPLAIN VERBOSE
        SELECT a2.aid, a2.bid, a2.abalance
          FROM pgbench_accounts a1
          JOIN pgbench_accounts a2 USING (aid)
     WHERE a1.aid BETWEEN 500000 AND 500004; ...

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.