PostgreSQL source code can be freely available, and its open source protocol allows researchers to arbitrarily modify, here to introduce the source of PostgreSQL and some implementation mechanism. After downloading the PostgreSQL source code and decompression, its first-level directory structure is as follows:
PostgreSQL Source code level structure
Where the Config directory contains some system configuration files. The contrib directory includes some peripheral tools and some experimental development code that are not integrated into the core code. The doc directory is the Help document, written by SGML. SRC is the system core code, other files belong to the compilation and installation related files. SRC directory, each subdirectory and its corresponding contents are as follows:
subdirectory structure under the PostgreSQL source code src Directory
Backend |
Database Engine code, also known as background program code. |
Bin |
Peripheral tools, such as the database Connection tool Psql. |
Include |
Header file directory. |
Interface |
External interfaces provided by the system, such as LIBPQ. |
Makefiles |
Platform-related makefile files. |
Pl |
Implementation code such as process language pl/postgresqlsql. |
Port |
Platform compatible processing module. |
Template |
A compiled script template for different platforms. |
Test |
Regression test cases and automated test frameworks. |
TimeZone |
Time zone-related code and data. |
Tools |
Accessibility tools, such as compiling a version of Windows Script. |
Tutorial |
An example of some of the examples provided by the system. |
The core implementation code of the system is located in the Src\backend directory
Access |
The data access layer, which includes the operation of the table data index and the transaction-related code. |
Bootstrap |
The database initialization module is closely related to the code under SRC\BIN\INITDB |
Catalog |
The operation-related code for the system table. |
Commands |
SQL command execution, including vacuum, copy, Alter, and so on. |
Executor |
SQL statement execution, including the execution of SELECT, INSERT, UPDATE, and DELETE statements. |
Foreign |
FDW (Foreign Data Wrapper) handles related code |
Lib |
A common library that contains several common programs. |
Libpq |
The front-end communication handles the related code. |
Main |
The system main entry function, which is responsible for transferring control to postmaster or Postgres. |
Nodes |
Node-related code, which is the storage unit in the query plan. |
Optimizer |
Query optimization related code, responsible for creating query paths and query plans. |
Parser |
SQL statement parsing module. |
Po |
Internationalization (i18n) processing module |
Port |
Platform compatible processing module. |
Postmaster |
The main process postmaster related code. |
Regex |
The regular expression processing module. |
Replicati/on |
Streaming replicati/on related code. |
Rewrite |
Rule system module. |
Snowball |
The word breaker is used to implement full-text retrieval. |
Storage |
Storage-tier modules, including Storage Manager, buffer management, file management, lock management, and so on. |
Tcop |
The SQL command Distribution module is responsible for invoking functions in parser, optimizer, executor, and commands. |
Tsearch |
Full-text retrieval module. |
Utils |
Some ancillary programs, such as the built-in data types, error reporting, sorting implementation, and other related code. |