PoWA 3 June, 28 2016 - 5432... Meet us! Authors Ronan Dunklau DBA - - PowerPoint PPT Presentation

powa 3
SMART_READER_LITE
LIVE PREVIEW

PoWA 3 June, 28 2016 - 5432... Meet us! Authors Ronan Dunklau DBA - - PowerPoint PPT Presentation

PoWA 3 June, 28 2016 - 5432... Meet us! Authors Ronan Dunklau DBA @ Dalibo Open-Source: Multicorn... Some PostgreSQL contributions (IMPORT FOREIGN SCHEMA...) Julien Rouhaud DBA @ Dalibo Open-Source: HypoPG, OPM... Some PostgreSQL


slide-1
SLIDE 1

PoWA 3

June, 28 2016 - 5432... Meet us!

slide-2
SLIDE 2

Authors

slide-3
SLIDE 3

Ronan Dunklau DBA @ Dalibo Open-Source: Multicorn... Some PostgreSQL contributions (IMPORT FOREIGN SCHEMA...) Julien Rouhaud DBA @ Dalibo Open-Source: HypoPG, OPM... Some PostgreSQL contributions But also...

slide-4
SLIDE 4

WHAT IS POWA [t] 2cm 5cm

slide-5
SLIDE 5

PRESENTATION pg_stat_statements pg_stat_statements github.com/dalibo/pg_stat_kcache github.com/dalibo/pg_qualstats github.com/dalibo/powa-archivist github.com/dalibo/powa-web

slide-6
SLIDE 6

PRESENTATION Official PostgreSQL contrib Normalized queries Cumulative counters (buffers, execution time...), by user database query pg_stat_statements

slide-7
SLIDE 7

USEFUL INDICATORS Number of execution per normalized query Average execution time Temporary file creation Blocks access from or outside PostgreSQL’s cache pg_stat_statements

slide-8
SLIDE 8

IN ACTION 1 image pg_stat_statements

slide-9
SLIDE 9

IN ACTION 2 image pg_stat_kcache

slide-10
SLIDE 10

PRESENTATION Collects system metrics, by normalized queries Physical disk access CPU usage pg_stat_kcache

slide-11
SLIDE 11

MEANING... “real” hit-ratio (PostgreSQL cache Vs system cache) Identify CPU bound queries pg_stat_kcache

slide-12
SLIDE 12

IN ACTION 1 image pg_stat_kcache

slide-13
SLIDE 13

IN ACTION 2 image pg_qualstats

slide-14
SLIDE 14

PRESENTATION Predicate analysis WHERE clauses JOIN clauses Collects various metrics Selectivity Constants sampling (most executed, most filtering...) Execution count Evalutation type (Index clause or post-scan filtering) pg_qualstats

slide-15
SLIDE 15

IN ACTION 1 image pg_qualstats

slide-16
SLIDE 16

IN ACTION 2 image pg_qualstats

slide-17
SLIDE 17

IN ACTION 3 image pg_qualstats

slide-18
SLIDE 18

IN ACTION 4 image powa-archivist

slide-19
SLIDE 19

PRESENTATION Archive those data sources Configurable (retention, frequency...) Extensible to other datasources powa-archivist

slide-20
SLIDE 20

WHAT TO GET Where / when are the bottlenecks For what reason How to fix Live! Compatibility

slide-21
SLIDE 21

PostgreSQL 9.4 et later PoWA 1 compatible with 9.3, but much more limited powa-web

slide-22
SLIDE 22

PRESENTATION Web interface for PoWA Manage one or more PoWA instance Drill-down analysis powa-web

slide-23
SLIDE 23

USAGE EXAMPLE problem: bad performance on parts of an application Select an analysis period Identify the database powa-web

slide-24
SLIDE 24

CLUSTER VIEW - 1 image powa-web

slide-25
SLIDE 25

CLUSTER VIEW - 2 image powa-web

slide-26
SLIDE 26

DATABASE VIEW Problematic database has been identified... let’s drill down to the query level! powa-web

slide-27
SLIDE 27

DATABASE VIEW - 1 image powa-web

slide-28
SLIDE 28

DATABASE VIEW - 2 image powa-web

slide-29
SLIDE 29

DATABASE VIEW - 3 image powa-web

slide-30
SLIDE 30

QUERY VIEW 2 problematic queries Drill down on each of them [fragile]

slide-31
SLIDE 31

POWA-WEB

slide-32
SLIDE 32

FIRST QUERY - SQL [mathescape, numbersep=5pt, gobble=2, frame=lines, framesep=2mm]sql SELECT com.id, sum(cl.pric) AS totalprice FROM command com JOIN commandline cl ON com.id = cl.idcommand JOIN client cli ON cli.id = com.idclient WHERE cli.id = ? GROUP BY com.id powa-web

slide-33
SLIDE 33

FIRST QUERY - CACHE image powa-web

slide-34
SLIDE 34

FIRST QUERY - CPU image powa-web

slide-35
SLIDE 35

FIRST QUERY - PREDICATES image powa-web

slide-36
SLIDE 36

FIRST QUERY - INDEX image [fragile]powa-web

slide-37
SLIDE 37

SECOND QUERY - SQL [mathescape, numbersep=5pt, gobble=2, frame=lines, framesep=2mm]sql SELECT id, dt FROM command WHERE state = ? powa-web

slide-38
SLIDE 38

SECOND QUERY - EXPLAIN image powa-web

slide-39
SLIDE 39

SECOND QUERY - DISTRIBUTION image powa-web

slide-40
SLIDE 40

VIDEO powa-web

slide-41
SLIDE 41

WHAT’S NEW IN VERSION 3 extension support Global index suggestion HypoPG github.com/dalibo/HypoPG

slide-42
SLIDE 42

PRESENTATION Allow for hypothetical indexes creation Instant creation, no impact on resources and no lock Only used in EXPLAIN statements [fragile]HypoPG

slide-43
SLIDE 43

EXAMPLE [mathescape, numbersep=5pt, gobble=2, frame=lines, framesep=2mm]sql rjuju=# EXPLAIN SELECT * FROM t1 WHERE id = 3 ; QUERY PLAN ————————————————— Seq Scan on t1 (cost=0.00..1693.00 rows=1 width=4) Filter: (id = 3) (2 rows) [fragile]HypoPG

slide-44
SLIDE 44

EXAMPLE [mathescape, numbersep=5pt, gobble=2, frame=lines, framesep=2mm]sql # SELECT hypopgcreateindex(’CREATE INDEX ON t1(id)’) ; hypopgcreateindex ————————– (77523,<77523>btreet1id) (1 row) rjuju=# EXPLAIN SELECT * FROM t1 WHERE id = 3 ; QUERY PLAN ————————————————————————– Index Only Scan using <77523>btreet1id on t1 (0.04..8.06 rows=1 width=4) Index Cond: (id = 3) (2 rows) HypoPG

slide-45
SLIDE 45

WHAT IS IT USEFUL FOR Will PostgreSQL use such an index What size can I expect it to be How useful can it be HypoPG

slide-46
SLIDE 46

IN ACTION image Global optimization

slide-47
SLIDE 47

PRESENTATION Find the optimal set of index to add Helping every queries Minimum set of indexes Privileging multi-column indexes Global optimization

slide-48
SLIDE 48

ALGORITHM - 1 Fetch the predicates that need optimization (pg_qualstats) Predicates filtering more than X lines out Predicates filtering more than X% of lines out Predicates used as part of a Seq Scan Global optimization

slide-49
SLIDE 49

ALGORITHM - 2 Group predicates by supported access methods Hint: Think about btree_gist and btree_gin Build a list of predicates “contained” by each predicates WHERE id = ? AND label = ? WHERE id = ? WHERE label = ? For each node, attribute a “score” to it (currently, number

  • f columns)

Global optimization

slide-50
SLIDE 50

ALGORITHM - 3 For each node, compute a path containing all included node Score it (sum of individual nodes scores) Starting with the highest scoring path, generate the index definition for it Delete any other path made obsolete by this one Loop until no path is le unoptimized Global optimization

slide-51
SLIDE 51

VALIDATION

slide-52
SLIDE 52

IN ACTION

slide-53
SLIDE 53

IN ACTION image Global optimization

slide-54
SLIDE 54

IN ACTION image Global optimization

slide-55
SLIDE 55

IN ACTION image Global optimization

slide-56
SLIDE 56

IN ACTION image Global optimization

slide-57
SLIDE 57

IN ACTION vidéo What’s next

slide-58
SLIDE 58

FUTURE ENHANCEMENTS Find correlations, and suggest them once correlated statistics are available WHERE cityname = ? AND zipcode = ? (10 rows avg) WHERE cityname = ? (10 rows avg) WHERE zipcode = ? (10 rows avg) It means that cityname and zipcode are probably correlated Collect statistics on table to take DML workload into account Suggest partial indexes based on most-oen used values

slide-59
SLIDE 59

powa-archivist powa-web pg_qualstats t t k h dalibo.github.io/powa (website) github.com/dalibo/powa-archivist (repository) github.com/dalibo/powa-web (repository) demo-powa.dalibo.com (demo) github.com/dalibo/pg_qualstats (repository) article on rdunklau.github.io

slide-60
SLIDE 60

contact@dalibo.com powa@dalibo.com powa.readthedocs.org