- PostgreSQL 9 High Availability Cookbook
- Shaun M. Thomas
- 325字
- 2021-12-08 12:32:04
Introduction
Abstraction can protect a database from even the busiest platform. At the time of writing this book, applications and web services often involve hundreds of servers. If we follow a simple and na?ve development cycle where applications have direct access to the database, each of these servers may require dozens of connections per program, even with a small server pool that can result in hundreds or thousands of direct connections to the database. Is this what we want? Consider the scenario illustrated in the following diagram:

We need a way to avoid overwhelming the database with the needs of too many clients. As we suggested in the previous chapter, a PostgreSQL server experiences its best performance when the amount of active connections is less than three times the available CPU count. With a thousand incoming client connections, we will need hundreds of CPU cores to satisfy the formula.
Every incoming connection requires resources such as memory for query calculations and results, file-handle and port allocations for network traffic, process management, and so on. In addition, each connection is another process the OS has to schedule for CPU time. Very large servers are extremely capable, but resources are not infinite. Even if the database can handle thousands of connections, performance will suffer for each in excess of design capacity. We need to change the map to something slightly different, as seen here:

By inserting a connection pool in front of the database, hundreds of PostgreSQL server processes are reduced to dozens. A database pool works by recycling database connections as soon as the client completes its current transaction or when its database work is complete. Instead of hundreds of mostly idle database connections, we maintain a specific set of highly active connections.
Two popular tools for PostgreSQL that provide pooling capability are pgBouncer
and pgpool
. In this chapter, we will explore how to use these services properly and reduce overhead and database availability.
- Facebook Application Development with Graph API Cookbook
- 零基礎(chǔ)搭建量化投資系統(tǒng):以Python為工具
- 高效微控制器C語(yǔ)言編程
- 無(wú)代碼編程:用云表搭建企業(yè)數(shù)字化管理平臺(tái)
- C++面向?qū)ο蟪绦蛟O(shè)計(jì)(微課版)
- Practical Data Science Cookbook(Second Edition)
- DevOps入門(mén)與實(shí)踐
- C語(yǔ)言程序設(shè)計(jì)上機(jī)指導(dǎo)與習(xí)題解答(第2版)
- Unity 2017 Mobile Game Development
- Python Essentials
- Unity Character Animation with Mecanim
- App Inventor 2 Essentials
- 快樂(lè)編程:青少年思維訓(xùn)練
- 虛擬現(xiàn)實(shí)建模與編程(SketchUp+OSG開(kāi)發(fā)技術(shù))
- Mastering Machine Learning with R