1.1. Logical Structure of Database Cluster

A database cluster is a collection of databases managed by a PostgreSQL instance. If you are hearing this definition for the first time, you might be wondering what it means. The term “database cluster” in PostgreSQL does not mean “a group of database servers”. A PostgreSQL instance runs on a single host and manages a single database cluster.

Figure 1.1 shows the logical structure of a database cluster. A database contains various database objects, including tables, indexes, sequences, views, and functions. In PostgreSQL, databases themselves are also considered database objects and are logically isolated from one another. All other database objects (e.g., tables and indexes) belong to their respective databases.

Figure 1.1. Logical structure of a database cluster.

All the database objects in PostgreSQL are internally managed by respective object identifiers (OIDs), which are unsigned 4-byte integers. The relations between database objects and their respective OIDs are stored in appropriate system catalogs, depending on the type of objects. For example, OIDs of databases and heap tables are stored in pg_database and pg_class, respectively.

These identifiers can be examined through the system catalogs. To find the desired OIDs, execute the following queries:

sampledb=# SELECT datname, oid FROM pg_database WHERE datname = 'sampledb';
 datname  |  oid
----------+-------
 sampledb | 16384
(1 row)

sampledb=# SELECT relname, oid FROM pg_class WHERE relname = 'sampletbl';
  relname  |  oid
-----------+-------
 sampletbl | 18740
(1 row)