1.1. Logical Structure of Database Cluster
A database cluster is a collection of databases managed by a PostgreSQL server. 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 server runs on a single host and manages a single database cluster.
Figure 1.1 shows the logical structure of a database cluster. A database is a collection of database objects. In the relational database theory, a database object is a data structure used to store or reference data. A (heap) table is a typical example, and there are many others, such as indexes, sequences, views, functions. In PostgreSQL, databases themselves are also database objects and are logically separated from each other. All other database objects (e.g., tables, indexes, etc) belong to their respective databases.
数据库集群是由PostgreSQL服务器管理的一组数据库。如果你是第一次听到这个定义,你可能会感到困惑。在PostgreSQL中,“数据库集群”并不意味着“一组数据库服务器”。PostgreSQL服务器运行在单个主机上,并管理一个数据库集群。
图1.1显示了数据库集群的逻辑结构。数据库是数据库对象的集合。在关系数据库理论中,数据库对象是一种用于存储或引用数据的数据结构。堆表是一个典型的例子,还有许多其他对象,如索引、序列、视图、函数等。在PostgreSQL中,数据库本身也是数据库对象,并且彼此逻辑上是分离的。所有其他数据库对象(例如表、索引等)都属于它们各自的数据库。

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.
To find the desired OIDs, execute the following queries:
在PostgreSQL中,所有数据库对象都通过各自的对象标识符(OIDs)进行内部管理,这些OID是无符号的4字节整数。数据库对象与其各自OID之间的关系存储在相应的系统目录中,具体取决于对象的类型。例如,数据库的OID存储在`pg_database`中,堆表的OID存储在`pg_class`中。
为了找到所需的OID,可以执行以下查询语句:
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)



