Given the pg_stat_statements view, which query will return the SQL statement with the highest average execution time?
SELECT query, mean_time FROM pg_stat_statements ORDER BY mean_time DESC LIMIT 1;
Think about which column shows the average time per execution and how to get the highest value.
The mean_time column shows the average execution time of each query. Ordering by it descending and limiting to 1 returns the slowest average query.
Which column in pg_stat_statements helps identify how many times a query was executed?
Look for the column that counts executions.
The calls column shows how many times the query was executed.
Which SQL command correctly resets all statistics collected by pg_stat_statements?
Resetting statistics is done by a function call, not by deleting or truncating.
The function pg_stat_statements_reset() resets all statistics collected by the extension.
You want to find queries that are both slow on average and executed many times. Which query correctly selects queries with average time over 100ms and calls over 1000?
SELECT query, mean_time, calls FROM pg_stat_statements WHERE mean_time > 100 AND calls > 1000 ORDER BY mean_time DESC;
Use AND to combine conditions that must both be true.
Option B correctly filters queries with mean_time greater than 100ms and calls greater than 1000, ordering by slowest first.
You run this query but get an error: ERROR: relation "pg_stat_statements" does not exist. What is the most likely cause?
Check if the extension is installed and enabled.
The error usually means the extension is not installed or enabled in the current database. You must run CREATE EXTENSION pg_stat_statements; first.