Performance Analysis at Full Power: Julien Rouhaud
Performance Analysis at Full Power: Julien Rouhaud
Performance Analysis at Full Power: Julien Rouhaud
Julien Rouhaud
pgconf.eu 2019
1/40
Julien Rouhaud Performance analysis at full power
Who am I
2/40
Julien Rouhaud Performance analysis at full power
Why this talk
My own experience
3/40
Julien Rouhaud Performance analysis at full power
Why this talk
PostgreSQL’s moving fast
PostgreSQL changes
New features for better performance
New bottlenecks
New performance counters
Lot of metrics available on the OS side
top, perf, iostat...
PostgreSQL’s core statistics
some metrics available
Cumulated statistics
No underlying system metrics
but extensible, there are tools to help !
4/40
Julien Rouhaud Performance analysis at full power
PostgreSQL statistics
How it works
5/40
Julien Rouhaud Performance analysis at full power
PostgreSQL statistics
List of in-core views
6/40
Julien Rouhaud Performance analysis at full power
PostgreSQL statistics
The limits
7/40
Julien Rouhaud Performance analysis at full power
PostgreSQL statistics
Raw data
8/40
Julien Rouhaud Performance analysis at full power
PostgreSQL statistics
The solution
9/40
Julien Rouhaud Performance analysis at full power
PostgreSQL statistics
Time visualisation
10/40
Julien Rouhaud Performance analysis at full power
pg_stat_statements
Must have extensions
Official contrib
Global view of what’s happening on your server
Query normalization, based on object identifiers
Cumulate many statistics per queryid, userid,
dbid
cumulated runtime and number of execution
min, max, mean time
shared/local buffers access (hit, read, dirtied,
written)
temps files
IO timing (depending on track_io_timing)
11/40
Julien Rouhaud Performance analysis at full power
pg_stat_statements
What can we learn ?
12/40
Julien Rouhaud Performance analysis at full power
pg_stat_statements
Query example
13/40
Julien Rouhaud Performance analysis at full power
pg_stat_statements
Over time
15/40
Julien Rouhaud Performance analysis at full power
pg_stat_statements
Identify slow queries
16/40
Julien Rouhaud Performance analysis at full power
pg_stat_kcache
Kernel metrics
github.com/powa-team/pg_stat_kcache
Wrapper around get_rusage(2)
Gives access to kernel metrics, aggregated per
(queryid, dbid, userid) :
Physical disk reads and writes
User and system CPU
Context switches, page faults
17/40
Julien Rouhaud Performance analysis at full power
pg_stat_kcache
What can we learn ?
18/40
Julien Rouhaud Performance analysis at full power
pg_stat_kcache
Examples - per database
19/40
Julien Rouhaud Performance analysis at full power
pg_stat_kcache
Examples - per query
20/40
Julien Rouhaud Performance analysis at full power
pg_wait_sampling
Wait events monitoring
github.com/postgrespro/pg_wait_sampling/
Developed by Postgres Professional
Efficient high frequency sampling of wait events
Default period is 10ms, customisable
Aggregated per queryid, dbid
For 9.6+ only, when Wait Events were introduced
21/40
Julien Rouhaud Performance analysis at full power
pg_wait_sampling
What can we learn ?
22/40
Julien Rouhaud Performance analysis at full power
pg_wait_sampling
Examples
Per database :
23/40
Julien Rouhaud Performance analysis at full power
pg_wait_sampling
Examples
Per query :
24/40
Julien Rouhaud Performance analysis at full power
pg_qualstats
Statistics on predicates
github.com/powa-team/pg_qualstats
Gather statistics on predicates (WHERE / JOIN
clauses)
Number of underlying query executions
Number of predicate’s operator execution
Selectivity
Sequential scan or index scan
Per queryid, userid, dbid
Sampled to avoid overhead (default is 1 /
max_connections)
25/40
Julien Rouhaud Performance analysis at full power
pg_qualstats
What can we learn ?
26/40
Julien Rouhaud Performance analysis at full power
pg_qualstats
Constant distribution
27/40
Julien Rouhaud Performance analysis at full power
pg_qualstats
Index suggestion
28/40
Julien Rouhaud Performance analysis at full power
HypoPG
Hypothetical indexes
github.com/HypoPG/hypopg
Hypothetical indexes, aka. "What if this index
existed ?"
Create "fake" indexes instantly, without any
resource consumption
EXPLAIN can use such index
29/40
Julien Rouhaud Performance analysis at full power
pg_qualstats + HypoPG
Index validation
30/40
Julien Rouhaud Performance analysis at full power
pg_qualstats + HypoPG
Global index suggestion
31/40
Julien Rouhaud Performance analysis at full power
pg_qualstats + HypoPG
Global index suggestion
32/40
Julien Rouhaud Performance analysis at full power
pg_track_settings
History of configuration changes
github.com/rjuju/pg_track_settings/
SQL only extension
detect and store the settings changed since last call
both global and object specific (eg. ALTER
DATABASE SET)
and also postgres restart
33/40
Julien Rouhaud Performance analysis at full power
pg_track_settings
Example
34/40
Julien Rouhaud Performance analysis at full power
pg_track_settings
Example
35/40
Julien Rouhaud Performance analysis at full power
pg_track_settings
Example
36/40
Julien Rouhaud Performance analysis at full power
pg_track_settings
Graph annotation
37/40
Julien Rouhaud Performance analysis at full power
Demo
Demo
dev-powa.anayrat.info
(not credential required, just click connect)
38/40
Julien Rouhaud Performance analysis at full power
Conclusion
39/40
Julien Rouhaud Performance analysis at full power
Questions ?
rjuju.github.io
@rjuju123
Ïpowateam (pg12 compatible)
40/40
Julien Rouhaud Performance analysis at full power