1. Tool : pg_stat_statements
a. Enabling: to enable statement
log add following entries to postgresql.conf and restart the database.
shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.max = 10000
pg_stat_statements.track = all
Login
to database as super user and issue following command
CREATE extension pg_stat_statements;
b. Monitor: Following SQL statement
would show all the latest SQL statements executed on database server.
select * from pg_stat_statements;
c. Space & Recommendation: as
value for pg_stat_statements.max is set to 10000, postgres would keep latest
10,000 SQLs and flush older ones. So the table size would remain in control. This
could be enabled on production system as it has les performance cost.
2. Tool : auto_explain
a. Enabling: to enable execution
plan log add following entries to postgresql.conf and restart the
database.
shared_preload_libraries = 'auto_explain'
auto_explain.log_min_duration = '10s'
auto_explain.log_nested_statements = on
b. Monitor: if query took more
than 10 secs, postgres would log the SQL statement with its execution plan in
server log file under pg_log.
c Space & Recommendation: It
consumes the space in server log file there is cost for log writing and disk
space. We should enable this setting only when there is trouble. Enabling this
would provide detail execution plan and query statistics.
Comments
Post a Comment