Postgresql 中文操作指南

38.1. How Extensibility Works #

PostgreSQL 是可扩展的,因为它的操作是由目录驱动的。如果你熟悉标准关系数据库系统,那么你应该知道,它们以系统目录形式存储有关数据库、表、列等的信息。(一些系统称之为数据字典。)目录对用户来说看起来与其他表类似,但 DBMS 会在其中存储其内部簿记。PostgreSQL 与标准关系数据库系统之间的一个主要区别是,PostgreSQL 存储在其目录中的信息更多:不仅包括表和列的信息,还包括数据类型、函数、访问方法等信息。这些表可以由用户修改,既然 PostgreSQL 是基于这些表来运行,这意味着用户可以扩展 PostgreSQL。相比之下,传统数据库系统只能通过更改源代码中的硬编码过程或加载 DBMS 供应商专门编写的模块才能扩展。

PostgreSQL is extensible because its operation is catalog-driven. If you are familiar with standard relational database systems, you know that they store information about databases, tables, columns, etc., in what are commonly known as system catalogs. (Some systems call this the data dictionary.) The catalogs appear to the user as tables like any other, but the DBMS stores its internal bookkeeping in them. One key difference between PostgreSQL and standard relational database systems is that PostgreSQL stores much more information in its catalogs: not only information about tables and columns, but also information about data types, functions, access methods, and so on. These tables can be modified by the user, and since PostgreSQL bases its operation on these tables, this means that PostgreSQL can be extended by users. By comparison, conventional database systems can only be extended by changing hardcoded procedures in the source code or by loading modules specially written by the DBMS vendor.

此外,PostgreSQL 服务器可以通过动态加载将用户编写的代码合并到自身中。也就是说,用户可以指定一个实现新类型或函数的对象代码文件(例如,共享库),PostgreSQL 将在需要时对其进行加载。以 SQL 编写的代码添加到服务器中就更加简单了。这种“即时”修改其操作的能力使得 PostgreSQL 非常适合对新应用和存储结构进行快速原型设计。

The PostgreSQL server can moreover incorporate user-written code into itself through dynamic loading. That is, the user can specify an object code file (e.g., a shared library) that implements a new type or function, and PostgreSQL will load it as required. Code written in SQL is even more trivial to add to the server. This ability to modify its operation “on the fly” makes PostgreSQL uniquely suited for rapid prototyping of new applications and storage structures.