6.5 The Architecture of PostgreSQL


In this section you will learn about the basic concepts of PostgreSQL's architecture. With this knowledge, it will be easier for you to understand the behavior of the server and to build sophisticated applications. Knowing about PostgreSQL's internals will also help you to write your own server-side extensions you can use to solve problems and challenges more efficiently and more reliably.

6.5.1 Postmasters and Children

PostgreSQL is based on a clear and easy-to-understand architecture. The key to PostgreSQL's power and stability lies in its flexibility. The entire project is built on the KISS principle (Keep It Small and Simple), which means that the server consists of easy-to-understand modules.

When you start PostgreSQL, a daemon called postmaster is started. This daemon starts a process for every connection established to the server. These processes started by the postmaster are called backend processes. The postmaster is also responsible for managing the memory usage of the system as well as things like caching and security. One backend process can only handle one connection at a time, and one postmaster daemon can only operate on one database cluster.

All parameters that a backend needs are passed to it by the postmaster, which allows dynamic reconfiguration of your server because the parameters are passed to a backend every time a connection to the server is established.

6.5.2 The Database Cluster

Every postmaster running is working on one database cluster. (In the case of PostgreSQL, a database cluster is not a set of machines but a set of databases located on one machine.) Every database cluster contains at least two databases. The database template0 is the parent database. template1 inherits everything from template0. template1 contains everything a new PostgreSQL database normally consists of, such as system tables and a set of data types.

Every database created on the system will inherit all components of template1 if not defined otherwise. Every new database is an exact copy of template1, which means that it contains all data types and all system tables that template1 contains as well. However, if template1 is modified after a database has been created, these modifications will not be inherited by the new databases. PostgreSQL does not support dynamic inheritance. This has some significant advantages because every database in the database cluster is an independent island of data that cannot be influenced by other databases. However, if, for instance, a new data type is introduced, all new databases will automatically contain this data type if it has been inserted into template1. All databases that will need this data type as well have to be modified separately.

PostgreSQL's way of treating databases within a cluster makes PostgreSQL extremely flexible. It allows you to define groups of databases that have their own sets of functions and data types. Especially when working with extensions to PostgreSQL, this is extremely comfortable because you can work with many different versions of one data type by simply using it in various databases. This allows you to separate your development environment from the production system (if it is located on the same machine).



PHP and PostgreSQL. Advanced Web Programming2002
PHP and PostgreSQL. Advanced Web Programming2002
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 201

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net