Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
PostgreSQL 9.0 High Performance

You're reading from   PostgreSQL 9.0 High Performance If you’re an intermediate to advanced database administrator, this book is the shortcut to optimizing and troubleshooting your PostgreSQL database. With a balanced mix of theory and practice, it will quickly hone your expertise.

Arrow left icon
Product type Paperback
Published in Oct 2010
Publisher Packt
ISBN-13 9781849510301
Length 468 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Gregory Smith Gregory Smith
Author Profile Icon Gregory Smith
Gregory Smith
Arrow right icon
View More author details
Toc

Table of Contents (120) Chapters Close

Preface
1. What this book covers
2. What you need for this book FREE CHAPTER
3. Who this book is for
4. Conventions 5. Reader feedback
6. Customer support 7. Chapter 1. PostgreSQL Versions
8. Performance of historical PostgreSQL releases 9. PostgreSQL or another database?
10. PostgreSQL tools 11. PostgreSQL application scaling lifecycle
12. Performance tuning as a practice
13. Summary
14. Chapter 2. Database Hardware
15. Balancing hardware spending 16. Reliable controller and disk setup 17. Summary
18. Chapter 3. Database Hardware Benchmarking
19. CPU and memory benchmarking 20. Physical disk performance 21. Disk benchmarking tools 22. Sample disk results 23. Summary
24. Chapter 4. Disk Setup
25. Maximum filesystem sizes
26. Filesystem crash recovery 27. Linux filesystems 28. Solaris and FreeBSD filesystems 29. Windows filesystems 30. Disk layout for PostgreSQL 31. Summary
32. Chapter 5. Memory for Database Caching 33. Inspecting the database cache 34. Crash recovery and the buffer cache 35. Database buffer cache versus operating system cache 36. Analyzing buffer cache contents 37. Summary
38. Chapter 6. Server Configuration Tuning
39. Interacting with the live configuration 40. Server-wide settings 41. Per-client settings 42. New server tuning
43. Dedicated server guidelines
44. Shared server guidelines
45. pgtune
46. Summary
47. Chapter 7. Routine Maintenance
48. Transaction visibility with multiversion concurrency control 49. Vacuum 50. Autoanalyze
51. Index bloat 52. Detailed data and index page monitoring
53. Monitoring query logs 54. Summary
55. Chapter 8. Database Benchmarking
56. pgbench default tests 57. Running pgbench manually
58. Graphing results with pgbench-tools 59. Sample pgbench test results 60. Sources for bad results and variation 61. pgbench custom tests 62. Transaction Processing Performance Council benchmarks
63. Summary
64. Chapter 9. Database Indexing
65. Indexing example walkthrough 66. Index creation and maintenance 67. Index types 68. Advanced index use 69. Summary
70. Chapter 10. Query Optimization
71. Sample data sets 72. EXPLAIN basics 73. Query plan node structure 74. Explain analysis tools 75. Assembling row sets 76. Processing nodes 77. Joins 78. Statistics 79. Other query planning parameters 80. Executing other statement types
81. Improving queries 82. SQL Limitations 83. Summary
84. Chapter 11. Database Activity and Statistics
85. Statistics views
86. Cumulative and live views
87. Table statistics 88. Index statistics 89. Database wide totals
90. Connections and activity
91. Locks 92. Disk usage 93. Buffer, background writer, and checkpoint activity 94. Summary
95. Chapter 12. Monitoring and Trending
96. UNIX monitoring tools 97. Windows monitoring tools 98. Trending software 99. Summary
100. Chapter 13. Pooling and Caching
101. Connection pooling 102. Database caching 103. Summary
104. Chapter 14. Scaling with Replication
105. Hot Standby 106. Replication queue managers 107. Special application requirements 108. Other interesting replication projects
109. Summary
110. Chapter 15. Partitioning Data
111. Table range partitioning 112. Horizontal partitioning with PL/Proxy 113. Summary
114. Chapter 16. Avoiding Common Problems
115. Bulk loading 116. Common performance issues 117. Profiling the database 118. Performance related features by version 119. Summary

Pooling connection counts

The fundamental idea behind sizing a connection pool is that you should have enough connections to use all of the available resources, but not significantly more than that. The right size to saturate the server in most cases depends on the number of CPU cores, how much of the database is cached in memory, and the speed of the underlying disks. Once you've moved beyond the point where the server is busy all the time, adding more connections only serves to reduce efficiency, forcing the server to swap among multiple tasks when it would be better served with a smaller number.

It's hard to predict how many pooled connections to the database are necessary to keep it fully loaded without overloading it. Many users report optimal pooling counts to be between two and three times the number of cores on the system, perhaps more on a system with a large number of drives. A standard iterative technique is to start with 100 connections and then tune the number down from there if the server load seems too high. Prepare to be surprised at how low the optimal count really is; it's probably lower than you'd expect. Even though you might think that your server needs lots of connections to service a heavy load, in reality once you've saturated all of the CPUs on the server trying to execute more things at once just decreases efficiency. Almost all of the time, you'll be better off queuing the connections, so that they wait without causing contention and then execute on a lightly loaded server.

There are a few rules of thumb for how many connections define too many. On a typical UNIX derived operating systems such as Linux, the point at which adding additional connections becomes really ineffective is generally between 500 and 1000 active ones. If many of your connections spend a good chunk of their time IDLE (as shown by pg_stat_activity), you can discount their average overhead to some extent. Generally, having fewer connections than that is optimal, but you don't necessarily want to add the overhead of maintaining a pool until the server is really swamped. If your connections count is well into the thousands of active sessions, you definitely want to use a pool rather than direct connections.

Windows systems don't scale to as many connections in general, and there's a hard limit you'll run into in most cases too. If you are running the PostgreSQL server as a service, rather than directly from the command line, it will typically be assigned 512 KB of "Desktop Heap" space to work with. Since each connection takes approximately 3.2 KB of space, expect your server to run out of space in the heap and therefore stop accepting new connections after approximately 125 of them. It's possible to increase the heap size, but there's a potential that your system will not boot if you set it too high. See the "I cannot run with more than about 125 connections at once" entry at http://wiki.postgresql.org/wiki/Running_%26_Installing_PostgreSQL_On_Native_Windows for more information about this limitation and possible workarounds. Generally, the best workaround is to use a connection pooler that limits the number of connections to be below this threshold, as this will improve server efficiency too.

From a monitoring perspective, connection pooling is likely to help if you have hundreds or more of connections and you see that most of your system's processors are being fully utilized. Connection overhead will show up as a mix of user and system/kernel time, so expect both to reduce with a pooler in front of the database. If your system spends most of its time waiting for disk I/O instead, it's unlikely a pooler will help you out. Caching might however.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image