Haroon walked us through various tips and tricks on how we can enhance PostgreSQL performance while highlighting some typical pitfalls people encounter. If you are planning for capacity, doing scalability analysis, or simply facing degradation in performance of your apps or queries running against PostgreSQL, you should definitely attend this session.
2. Who am I ??
● Working in PostgreSQL space @ 2ndQuadrant
● Part of PostgreSQL family for more than a decade
● Work in almost all areas of PostgreSQL from development to professional services
● Past stints with PostgreSQL family include
○ EnterpriseDB
○ OpenSCG
● Headed Engineering & IT efforts @ IBEX
● Served as Principal Architect/Product Owner @ TRG
Email: haroon@2ndQuadrant.com
: contact.mharoon@gmail.com
Skype: contact.haroon
7. SQL query analysis
- Explain/Explain analyze
- Look for unusual/undesired query plans
- Log and find long running queries
- Third party tools for query analysis
10. PostgreSQL configuration - postgresql.conf
- Generally located inside the data directory
- Configs are in key-value pair format
- Config parameters can be set via command line at startup as well
- Additional config files can be used by ‘include’ directive
11. Configuration (cont.)
- Database level configs
- User level
- Session level
- Transaction level
Change in some parameters can only be done via command line at startup or postgresql.conf. Some changes might requires a server
reload or restart.
14. Autovacuum
- Automatically vacuums and analyzes tables when vacuum/analyze thresholds
are met.
- autovacuum_* config settings in postgresql.conf
15. Performance check - How ?
PostgreSQL comes with pgbench.
- Used for running benchmark test on PostgreSQL
- Loosely based on TPC-B by default involving 5 SELECT, UPDATE and INSERTS per transaction
Sample output:
transaction type: <builtin: TPC-B (sort of)>
scaling factor: 10
query mode: simple
number of clients: 10
number of threads: 1
number of transactions per client: 1000
number of transactions actually processed: 10000/10000
tps = 85.184871 (including connections establishing)
tps = 85.296346 (excluding connections establishing)
16. Monitoring
- Run pgbench often
- Use tools like top, iostat
- Keep an eye on Bloating
- Long running queries
- Number of connections
- Disk
- pg_buffercache
17. Thank you for your time
Questions ?
● Worried about the health of your databases ?
● Need customized PostgreSQL suited to your
needs?
● Looking for PostgreSQL training ?
● Need help migrating to PostgreSQL ?
● Need PostgreSQL production support ?
● Got specific PostgreSQL needs ?
● Looking for cloud and/or hybrid high availability
clusters ?
Let us help you!
Email: haroon@2ndQuadrant.com
Skype: contact.haroon