PostgreSQL is a program that belongs to the class of database management systems.

#1 The Internals

Processes

Screenshot 2024-06-15 at 10.18.42 AM.png

Process Name Role Description
Postmaster (postgres) Main PostgreSQL server process, coordinating other processes, handling client connections.
Checkpointer (postgres: checkpointer) Writes dirty pages from shared buffer pool to disk periodically to minimize crash recovery work.
Background Writer (postgres: background writer) Writes dirty pages from shared buffer pool to disk in the background to free buffer space.
WAL Writer (postgres: walwriter) Writes WAL (Write-Ahead Logging) data from WAL buffers to disk to ensure transaction durability.
Autovacuum Launcher (postgres: autovacuum launcher) Manages the autovacuum process, cleaning up dead tuples to reclaim storage and maintain performance.
Stats Collector (postgres: stats collector) Collects and maintains statistical data for query planning and performance tuning.
Logical Replication Launcher (postgres: logical replication launcher) Manages logical replication, streaming changes from one database to another in real-time.

Directory structre of PG_DATA

Screenshot 2024-06-15 at 10.26.31 AM.png

Name Description
base Directory containing subdirectories for each database in the cluster, each containing the actual table data.
global Directory containing cluster-wide tables such as user and database tables.
pg_commit_ts Directory storing commit timestamp data for transactions.
pg_dynshmem Directory used for dynamic shared memory management.
pg_hba.conf Configuration file for client authentication (Host-Based Authentication).
pg_ident.conf Configuration file for user name mapping.
pg_logical Directory containing logical replication information.
pg_multixact Directory storing multi-transaction status data.
pg_notify Directory used for storing NOTIFY/LISTEN information.
pg_replslot Directory containing replication slot data for streaming replication.
pg_serial Directory storing information about serialized transactions.
pg_snapshots Directory containing exported snapshot information.
pg_stat Directory containing statistics data.
pg_stat_tmp Directory for temporary statistics data.
pg_subtrans Directory storing subtransaction status data.
pg_tblspc Directory containing symbolic links to tablespaces.
pg_twophase Directory storing data for two-phase commits.
pg_wal Directory containing Write-Ahead Log (WAL) files.
pg_xact Directory storing transaction status data.
PG_VERSION File containing the PostgreSQL version of the database cluster.
postgresql.auto.conf Configuration file for settings applied with ALTER SYSTEM command.
postgresql.conf Main configuration file for PostgreSQL server settings.
postmaster.opts File containing the command-line options passed to the postmaster process.
postmaster.pid File containing the process ID (PID) of the running postmaster process.

Schema

Schema are namespace that store all objects of a database.

public is the default schema for user objects unless other settings are specified.

pg_catalog is used for system catalog tables.

information_schema providesanalternativeviewforthesystemcatalogasdefined by the standard.

pg_toast is used for objects related to.

pg_temp comprises temporary tables. Although different users create temporary tables in different schemas called pg_temp_N, everyone refers to their objects using the pg_temp alias.

<aside> <img src="/icons/fireworks_blue.svg" alt="/icons/fireworks_blue.svg" width="40px" /> Each schema is confined to a particular database, and all database objects belong to this or that schema.

</aside>

Tablespace

A tablespace is a storage location where the data files containing database objects (such as tables and indexes) are stored. Tablespaces allow database administrators to control the physical storage of data by assigning different parts of a database to different storage locations.