0% found this document useful (0 votes)
3 views3 pages

PG Install

The document provides a comprehensive tutorial on the architecture of PostgreSQL 16, focusing on its memory structure, background processes, and physical file organization on CentOS 9/Rocky Linux 9. It details key components such as shared memory segments, background processes, and the structure of the data/base directory, along with tools like oid2name and pg_database for database inspection. The tutorial aims to enhance understanding of PostgreSQL's architecture for better performance optimization and troubleshooting.

Uploaded by

Stephen Efange
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

PG Install

The document provides a comprehensive tutorial on the architecture of PostgreSQL 16, focusing on its memory structure, background processes, and physical file organization on CentOS 9/Rocky Linux 9. It details key components such as shared memory segments, background processes, and the structure of the data/base directory, along with tools like oid2name and pg_database for database inspection. The tutorial aims to enhance understanding of PostgreSQL's architecture for better performance optimization and troubleshooting.

Uploaded by

Stephen Efange
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

PG Install

Source Install on Centos 9/Rocky Linux 9


Binary Install on Centos 9/Rocky Linux 9

Source Install on Ubuntu 22.04


Binary Install on Ubuntu 22.04

Binary Install on Windows 11


Binary Install on MacOS

______________________________architecture topics

Create a detailed tutorial on Structure


the main components of the PostgreSQL - Focus on 16 on centos
architecture and review some details about their internal functionality.
● Memory architecture
● Background processes
● Physical files
The binary files
The documents
The manuals
The libraries
The data
The representation of the data in the databases on disk and how its stored on disk
The data/base directory and its contents and details
Making use of oid2name and pg_database and any other tools to identify databases
and their contents.

PostgreSQL 16 Architecture on CentOS: A Detailed Tutorial


This tutorial provides an in-depth review of PostgreSQL 16's architecture, focusing
on its memory structure, background processes, and physical file organization on
disk. We will also explore how PostgreSQL stores data, the structure of the
data/base directory, and tools like oid2name and pg_database to inspect databases
and their contents.

1. PostgreSQL Memory Architecture


PostgreSQL uses a shared memory model divided into several key components:

1.1 Shared Memory Segments


Shared Buffers: Caches frequently accessed data blocks to reduce disk I/O
(configurable via shared_buffers in postgresql.conf).

WAL Buffers: Stores Write-Ahead Log (WAL) records before they are written to disk
(wal_buffers).

Commit Log (CLOG): Tracks transaction commit status (committed/aborted).

Lock Space: Manages locks for concurrent transactions.

1.2 Process-Specific Memory


Work Memory (work_mem): Used for sorting and hash operations.

Maintenance Work Memory (maintenance_work_mem): Used for maintenance tasks like


VACUUM.

Temp Buffers (temp_buffers): Stores temporary tables and data.


2. PostgreSQL Background Processes
PostgreSQL runs multiple background processes (visible in ps -ef | grep postgres):

Process Description
Postmaster Main parent process; manages startup/shutdown.
Checkpointer Periodically writes dirty buffers to disk.
Background Writer Writes modified buffers to disk to reduce checkpoint load.
WAL Writer Flushes WAL buffers to disk for crash recovery.
Autovacuum Automatically runs VACUUM and ANALYZE to reclaim space.
Stats Collector Gathers statistics for query optimization.
Logger (syslogger) Handles PostgreSQL log files.
Archiver Archives WAL logs if archive_mode = on.
3. PostgreSQL Physical Files
PostgreSQL stores data in the PGDATA directory (default: /var/lib/pgsql/16/data).

3.1 Key Directories & Files


Path Description
PGDATA/base/ Contains subdirectories for each database (indexed by OID).
PGDATA/global/ Stores cluster-wide tables (e.g., pg_database, pg_authid).
PGDATA/pg_wal/ Contains WAL (Write-Ahead Log) files.
PGDATA/pg_xact/ Transaction commit logs (CLOG).
PGDATA/postgresql.conf Main configuration file.
PGDATA/pg_hba.conf Client authentication rules.
PGDATA/pg_ident.conf User name mappings.
3.2 Binary Files & Libraries
PostgreSQL binaries (/usr/pgsql-16/bin/):

postgres (main server binary)

psql (client utility)

pg_ctl (control utility)

pg_dump (backup tool)

Libraries (/usr/pgsql-16/lib/):

Shared libraries (libpq.so, extensions).

4. Data Storage on Disk


4.1 Database File Structure
Each database has a subdirectory in PGDATA/base/ named by its OID (Object
Identifier).

Tables and indexes are stored as files (relfilenode), with extensions:

.1, .2 (fork files for TOAST tables, FSM, etc.)

4.2 How Data is Stored


Heap Files: Tables are stored as heap files (unordered).

TOAST (The Oversized-Attribute Storage Technique): Large values (> 2KB) are
compressed and stored separately.

Free Space Map (FSM): Tracks free space in heap files.

Visibility Map (VM): Tracks dead tuples for VACUUM.

5. Exploring Databases with oid2name and pg_database


5.1 Using oid2name
This utility maps OIDs to database names:

bash
oid2name -d postgres -U postgres
Example output:

All databases:
Oid Database Name Tablespace
----------------------------------
16384 postgres pg_default
16385 template1 pg_default
5.2 Querying pg_database
sql
SELECT oid, datname FROM pg_database;
Example output:

oid | datname
-------+-----------
16384 | postgres
16385 | template1
16386 | template0
5.3 Listing Tables in a Database
sql
SELECT relname, relfilenode FROM pg_class WHERE relkind = 'r';
relfilenode corresponds to the file name in PGDATA/base/<OID>/.

6. Summary
Memory: Shared buffers, WAL buffers, and process-specific memory optimize
performance.

Processes: Background workers handle checkpoints, WAL writing, and autovacuum.

Files: Data is stored in PGDATA/base/ with OID-based directories.

Tools: oid2name and pg_database help inspect database structures.

By understanding PostgreSQL's architecture, you can optimize performance,


troubleshoot issues, and manage storage efficiently.

Further Reading
PostgreSQL 16 Documentation

man postgres (for process details)

pg_config --pkglibdir (to find library paths)

You might also like