Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: DBI and keeping track of planner statistics

by erix (Prior)
on Jan 03, 2017 at 21:45 UTC ( [id://1178882]=note: print w/replies, xml ) Need Help??


in reply to DBI and keeping track of planner statistics

In the main postgres configuration file, postgresql.conf, you could set log_min_duration_statement to some value larger than zero. The value is expressed in milliseconds, so for instance setting it to 1000 makes the server log all SQL statements that take longer than 1 second. It may or may not fit your case. (You'd also need some process monitoring that log, I guess.)

The default setting of this parameter is -1 (=disabled):

log_min_duration_statement = -1 # -1 is disabled, 0 logs all statem +ents # and their durations, > 0 logs only # statements running at least this number # of milliseconds

And, by the way, you don't need to run "EXPLAIN" queries manually. EXPLAIN has nice machine-readable output formats like json and yaml. For example:

echo " create table t(n integer primary key); insert into t select * from generate_series(1,10000); analyze t; --> gather table statistics explain (analyze, verbose, format yaml) select count(*) from t where n + between 10 and 20; " | psql -qtAX

The output:

- Plan: Node Type: "Aggregate" Strategy: "Plain" Partial Mode: "Simple" Parallel Aware: false Startup Cost: 8.51 Total Cost: 8.52 Plan Rows: 1 Plan Width: 8 Actual Startup Time: 0.040 Actual Total Time: 0.040 Actual Rows: 1 Actual Loops: 1 Output: - "count(*)" Plans: - Node Type: "Index Only Scan" Parent Relationship: "Outer" Parallel Aware: false Scan Direction: "Forward" Index Name: "t_pkey" Relation Name: "t" Schema: "public" Alias: "t" Startup Cost: 0.29 Total Cost: 8.48 Plan Rows: 10 Plan Width: 0 Actual Startup Time: 0.022 Actual Total Time: 0.029 Actual Rows: 11 Actual Loops: 1 Output: - "n" Index Cond: "((t.n >= 10) AND (t.n <= 20))" Rows Removed by Index Recheck: 0 Heap Fetches: 11 Planning Time: 0.481 Triggers: Execution Time: 0.149

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1178882]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-23 12:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found