Skip to content

3 Architecture

Architecture, catalogs, replication, execution, I/O, roles, and server internals.
GASource pages: PDF 16-34Original PDF on GitHub

PDF page 16

3.1.1 Modified System catalogs

The following catalogs have been changed.

View nameDescription
pg_ident_file_mappingsProvides a summary of the contents of the client user name mapping configuration file.
pg_parameter_aclProvides ACL information that allows the execution of the ALTER SYSTEM SET statement.
pg_publication_namespaceStores the mapping between the schema and the PUBLICATION.
pg_stat_recovery_prefetchProvides prefetch status during recovery.
pg_stat_subscription_statsStores initial data synchronization failure information that is performed when the subscription is created.
Table 5 Added system catalogs and views
View nameAdded columnData typeDescription
pg_collationcolliculocaletextICU Collation name
pg_constraintconfdelsetcolssmallint[]Column with ON DELETE clause for foreign key
pg_databasedaticulocaletextICU Locale name
datlocprovidercharICU Collation Provider name
datcollversionbooleanCollation version
pg_indexindnullsnotdistinctbooleanIndicates the nullable setting of the unique index
pg_publication_relPrqualpg_node_treeTuple conditions for replication
prattrsint2vectorColumn number to replicate
pg_statistic_ext_datastxdinheritbooleanIf true, the stats include inheritance child columns
pg_stats_extinheritedbooleanIf true, the stats include inheritance child columns
pg_stats_ext_exprsinheritedbooleanIf true, the stats include inheritance child columns
pg_subscriptionsubskiplsnpg_lsnSkipped LSN
subtwophasestatecharIndicates the state of Two-Phase mode
subdisableonerrbooleanDisable subscription on error occurs
information_schema.table_constraintsnulls_distinctinformation s _ chema.yes_or_noIndicates the nullable setting of the unique index
Table 6 System catalogs/views with additional columns

PDF page 17

Catalog nameColumn nameDescription
pg_databasedatlastsysoidRemoved because not used
Table 7 System catalogs/views with columns removed
View nameDescription
pg_typeAdded ‘Z’ to the typcategory column to indicate internal use.
pg_collationThe data type of collcollate and collctype columns has changed from ’name’ to ’text’.
pg_databaseThe data type of the datcollate and datctype columns has changed from ’name’ to ’text'.
pg_backend_memory_cInformation on the memory area for statistical data (PgStat *) is now
ontextsoutput.
pg_shmem_allocationsAdded Shared Memory Stats, XLOG Recovery Ctl, and XLogPrefetchStats tuples.
Table 8 System catalogs/views with modified output

Among the modified system catalogs, the details of the major catalogs are described below.

Pg_ident_file_mappings catalog

This is a view for searching the contents of the pg_ident.conf file from SQL statements.

PDF page 18

Column nameData typeDescription
line_numberintegerLine number in the pg_ident.conf file
map_nametextMap name
sys_nametextSystem name
pg_usernametextPostgreSQL user name
errortextError message
Table 9 Pg_ident_file_mappings catalog
Example 12 Reference to pg_ident_file_mapping view.
postgres=# SELECT * FROM pg_ident_file_mapping ORDER BY 1 ;
line_number | map_name | sys_name | pg_username | error
-------------+----------+----------+-------------+-------
          43 | map1     | sysname1 | pgname1     |
          44 | map2     | sysname2 | pgname2     |
(2 rows)
Pg_parameter_acl catalog

The catalog records configuration parameters for which privileges have been granted to one or more roles.

Column nameData typeDescription
oidoidObject ID
parnametextThe parameter name to allow change
paraclaclitem[]Role information to allow changes
Table 10 Pg_parameter_acl catalog
Pg_publication_namespace

Information is stored when the FOR TABLE IN SCHEMA clause is specified in the CREATE PUBLICATION statement. Provides a mapping between PUBLICATION and SCHEMA.

Column nameData typeDescription
oidoidRow identifier
pnpubidoidReference to PUBLICATION
pnnspidoidReference to SCHEMA
Table 11 Pg_publication_namespace catalog

PDF page 19

Example 13 Reference to pg_publication_namespace catalog
postgres=> SELECT * FROM pg_publication_namespace ;
  oid  | pnpubid | pnnspid |
-------+---------+---------+
 16411 |   16410 |    2200 |
(1 row)
Pg_stat_recovery_prefetch view

Provides prefetched block statistics during recovery. It is also possible to check the status of replication processing in the standby instance of the streaming replication environment.

Column nameData typeDescription
stats_resettimestamp with time zoneDate time when the view was reset
prefetchbigintNumber of blocks prefetched because they were not in the buffer pool
hitbigintNumber of blocks not prefetched because they were already in the buffer pool
skip_initbigintNumber of blocks not prefetched because they would be zeroinitialized
skip_newbigintNumber of blocks not prefetched because they didn’t exist yet
skip_fpwbigintNumber of blocks not prefetched because a full-page image was included in the WAL
skip_repbigintNumber of blocks not prefetched because they were already recently prefetched
wal_distanceintegerHow many bytes ahead the prefetcher is looking
block_distanceintegerHow many blocks ahead the prefetcher is looking
io_depthintegerHow many prefetches have been initiated but are not yet known to have been completed
Table 12 Pg_stat_recovery_prefetch view
Pg_stat_subscription_stats view

The pg_stat_subscription_stats view contains error information about logical replication subscription workers.

PDF page 20

Column nameData typeDescription
subidoidOID of the subscription
subnamenameName of the subscription
apply_error_countbigintNumber of times an error occurred while applying changes
sync_error_countbigintNumber of times an error occurred during the initial table synchronization
stats_resettimestamp with time zoneTime at which these statistics were last reset
Table 13 Pg_stat_subscription_stats view
Example 14 Reference to pg_stat_subscription_stats view
postgres=# SELECT * FROM pg_stat_subscription_stats ;
-[ RECORD 1 ]-----+------
subid             | 16395
subname           | sub1
apply_error_count | 0
sync_error_count  | 23
stats_reset       |

The pg_backend_memory_contexts view and pg_shmem_allocations view can now be referenced not only by users with the SUPERUSER attribute but also by users belonging to the pg_read_all_stats role.

Example 15 Grant pg_read_all_stats role
postgres=# GRANT pg_read_all_stats TO demo ;
GRANT ROLE
postgres=# \connect postgres demo
You are now connected to database "postgres" as user "demo".
postgres=> SELECT COUNT(*) FROM pg_backend_memory_contexts ;
 count
-------
   122
(1 row)

PDF page 21

3.1.2 Logical Replication Enhancements

The following features have been added to Logical Replication.

Column-specific replication

It is now possible to replicate only specific columns in a table. Specify a column list for the table name in the CREATE PUBLICATION or ALTER PUBLICATION statement. The target column number is stored in the prattrs column of the pg_publication_rel catalog.

Example 16 Column specific replication
postgres=> CREATE TABLE repl1(c1 INT PRIMARY KEY, c2 INT, c3 VARCHAR(10)) ;
CREATE TABLE
postgres=> CREATE PUBLICATION pub1 FOR TABLE repl1(c1, c2) ;
CREATE PUBLICATION
postgres=> SELECT oid, prpubid, prrelid, prattrs FROM pg_publication_rel ;
-[ RECORD 1 ]--
oid     | 16394
prpubid | 16393
prrelid | 16388
prattrs | 1 2
When executing an UPDATE or DELETE statement, the column specification must include all
replica identities (primary key, etc.). In the example below, the UPDATE statement is in error by
specifying a column that does not include the primary key in the publication.
Example 17 UPDATE statement failure
postgres=> CREATE TABLE repl2(c1 INT PRIMARY KEY, c2 VARCHAR(10)) ;
CREATE TABLE
postgres=> CREATE PUBLICATION pub2 FOR TABLE repl2(c2) ;
CREATE PUBLICATION
postgres=> UPDATE repl2 SET c2='update' WHERE c1=100 ;
ERROR:  cannot update table "repl2"
DETAIL:  Column list used by the publication does not cover the replica
identity.
Row filtered replication

By specifying the WHERE clause in the CREATE PUBLICATION statement or the ALTER

PDF page 22

PUBLICATION statement, the tuples in the table can be limited and replicated. Replication conditions are specified for each table. The WHERE clause description must be enclosed in parentheses.

Example 18 Specify WHERE clause
postgres=> ALTER PUBLICATION pub1 SET TABLE repl1 WHERE (c1 < 1000) ;
ALTER PUBLICATION
In order to execute UPDATE or DELETE statements on the table to be replicated, the WHERE clause
must include a part of the replica identity (primary key, etc.).
Example 19 WHERE clause without replica identity
postgres=> CREATE TABLE repl3(c1 INT PRIMARY KEY, c2 VARCHAR(10)) ;
CREATE TABLE
postgres=> CREATE PUBLICATION pub3 FOR TABLE repl3 WHERE (c2='update') ;
CREATE PUBLICATION
postgres=> UPDATE repl3 SET c2='modify' WHERE c1=1000 ;
ERROR:  cannot update table "repl3"
DETAIL:  Column used in the publication WHERE expression is not part of the
replica identity.
postgres=> DELETE FROM repl3 WHERE c1=1000 ;
ERROR:  cannot delete from table "repl3"
DETAIL:  Column used in the publication WHERE expression is not part of the
replica identity.
The conditional statement that can be specified in the WHERE clause must be statically determined.
Therefore, user-defined functions and MUTABLE-specified functions cannot be specified.
Example 20 Specify the MUTABLE function
postgres=> CREATE PUBLICATION pub4 FOR TABLE repl1 WHERE (c1 = random()) ;
ERROR:  invalid publication WHERE expression
LINE 1: ...EATE PUBLICATION pub4 FOR TABLE repl1 WHERE (c1 = random());
                                                             ^
DETAIL:  User-defined or built-in mutable functions are not allowed.

PDF page 23

The conditions specified in the WHERE clause are converted and stored in the prqual column of the pg_publication_rel catalog. The psql command can be checked with the \d command or the \dRp+ command.

Example 21 \d command
postgres=> \d repl1
                      Table "public.repl1"
 Column |         Type          | Collation | Nullable | Default
--------+-----------------------+-----------+----------+---------
 c1     | integer               |           | not null |
 c2     | character varying(10) |           |          |
Indexes:
    "repl1_pkey" PRIMARY KEY, btree (c1)
Publications:
    "pub1" WHERE (c1 < 1000)
Specify all tables in the schema

The syntax is now available to register all tables in a particular schema with a PUBLICATION object. Specify the FOR TABLES IN SCHEMA clause and schema name in the CREATE PUBLICATION statement (or ALTER PUBLICATION statement). This syntax can only be executed by users with the SUPERUSER attribute. In the case of the FOR ALL TABLE clause that was available in the past, tables of all schemas were registered. Syntax

CREATE PUBLICATION publication_name FOR TABLES IN SCHEMA schema_name
ALTER PUBLICATION publication_name ADD TABLES IN SCHEMA schema_name

PDF page 24

Example 22 Specify IN SCHEMA clause
postgres=# CREATE PUBLICATION pub5 FOR TABLES IN SCHEMA schema1 ;
CREATE PUBLICATION
postgres=# \dRp
                               List of publications
 Name |  Owner   | All tables | Inserts | Updates | Deletes | Truncates | …
------+----------+------------+---------+---------+---------+-----------+-…
pub5 | postgres | f          | t       | t       | t       | t         | f
(1 row)
The pg_publication_namespace catalog has been added with this implementation.
Skip LSN

It is now possible to specify the SKIP clause in the ALTER SUBSCRIPTION statement. Specify LSN in the SKIP clause. Execution of this statement allows the SUBSCRIPTION side of logical replication to skip transactions that caused synchronization errors. Syntax

ALTER SUBSCRIPTION subscription_name SKIP (LSN='lsn_value')

The skipped LSN can be obtained in the subskiplsn column of the pg_subscription catalog. The psql command added a Skip LSN entry to the output of the \dRs + command.

Example 23 Specify the SKIP clause
postgres=# ALTER SUBSCRIPTION sub1 SKIP (LSN = '0/30B51E0') ;
ALTER SUBSCRIPTION
postgres=# SELECT subskiplsn FROM pg_subscription ;
 subskiplsn
------------
 0/30B51E0
(1 row)

PDF page 25

Disable SUBSCRIPTION when an error occurs

The option disable_on_error can now be specified to disable SUBSCRIPTION if a replication error occurs. The default is false and no disabling is performed. The column subdisableonerr has been added to the pg_subscription catalog to indicate this option value.

Example 24 Execute CREATE SUBSCRIPTION statement
postgres=# CREATE SUBSCRIPTION sub1 CONNECTION 'host=remsvr1, dbname=postgres'
PUBLICATION pub1 WITH (disable_on_error=true, two_phase=true) ;
NOTICE: created replication slot "sub1" on publisher
CREATE SUBSCRIPTION
TWO_PHASE option

The replication protocol command CREATE_REPILICATION_SLOT has been expanded and the TWO_PHASE option has been added. This makes it possible to decode PREPARE TRANSACTION, COMMIT PREPARED, ROLLBACK PREPARED, etc.

3.1.3 Parallel Query Enhancements

The SELECT DISTINCT statement can now work with parallel queries.

Example 25 Parallel query for SELECT DISTINCT
postgres=> EXPLAIN SELECT DISTINCT c2 FROM data1 ;
                                 QUERY PLAN
------------------------------------------------------------------------------
 Unique  (cost=11614.55..11614.56 rows=1 width=6)
   ->  Sort  (cost=11614.55..11614.56 rows=2 width=6)
         Sort Key: c2
         ->  Gather  (cost=11614.33..11614.54 rows=2 width=6)
               Workers Planned: 2
               ->  HashAggregate  (cost=10614.33..10614.34 rows=1 width=6)
                     Group Key: c2
                     ->  Parallel Seq Scan on data1  (cost=0.00..9572.67 ro…
(8 rows)

PDF page 26

3.1.4 WAL compression

It is now possible to specify LZ4 and Zstandard as the compression method for the full-page image output to WAL. Change the parameter wal_compression to perform WAL compression. The setting value on, which is the conventional compression method, is an alias for the setting value pglz. The default value remains off without any change.

Example 26 WAL compression settings
postgres=# SELECT name, setting, vartype, enumvals FROM pg_settings
WHERE name='wal_compression' ;
-[ RECORD 1 ]---------------
name     | wal_compression
setting  | off
vartype  | enum
enumvals | {pglz,lz4,zstd,on,off}
To use value lz4 or zstd, it must be compiled with --with-lz4 and --with-zstd specified when executing
'configure' command.

3.1.5 Archive Library

It is now possible to use a shared library in addition to the traditional command (archive_command parameter) as a way to create an archive of WAL files. The archive_library parameter has been added to specify the archive library name. If archive_library is not set, the archive_command parameter can still be used. The Contrib module basic_archive has been added as a standard archive library. This Contrib module does not require the execution of the CREATE EXTENSION statement. The basic_archive.archive_directory parameter can be specified as the archive destination directory.

PDF page 27

Example 27 Specify the Archive Library
postgres=# SELECT * FROM pg_settings WHERE name LIKE 'archive_library' ;
-[ RECORD 1 ]---+-------------------------------------------------------------
name            | archive_library
setting         | basic_archive
unit            |
category        | Write-Ahead Log / Archiving
short_desc      | Sets the library that will be called to archive a WAL file.
extra_desc     | An empty string indicates that "archive_command" should be
used.
context         | sighup
vartype         | string
source          | configuration file
min_val         |
max_val         |
enumvals        |
boot_val        |
reset_val       | basic_archive
sourcefile      | /home/postgres/data/postgresql.conf
sourceline      | 255
pending_restart | f
postgres=# SHOW basic_archive.archive_directory ;
-[ RECORD 1 ]-------------------+----------------------
basic_archive.archive_directory | /home/postgres/arch
If both archive_library and archive_command are specified, archive_library is used.

3.1.6 Global Locale Provider

It is now possible to specify an ICU as the global locale provider. Allows ICU to be used as the default locale provider for the entire database cluster or database. You must use a binary compiled with the –with-icu option to use this feature. The –locale-provider option that specifies the locale provider name can be specified for the initdb command and createdb command. Specify libc or icu for this option. The –icu-locale option allows you to specify the ICU locale name.

PDF page 28

Example 28 Execute initdb command
$ initdb --locale-provider=icu --icu-locale=en --encoding=utf8 -D data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with this locale configuration:
  provider:    icu
  ICU locale:  en
  LC_COLLATE:  en_US.utf8
  LC_CTYPE:    en_US.utf8
  LC_MESSAGES: en_US.utf8
  LC_MONETARY: en_US.utf8
  LC_NUMERIC:  en_US.utf8
  LC_TIME:     en_US.utf8
The default text search configuration will be set to "english".
…
Added LOCALE_PROVIDER to specify the locale provider and ICU_LOCALE to specify the locale
name to the options of the CREATE DATABASE statement.
Example 29 Execute CREATE DATABASE statement
postgres=# CREATE DATABASE icudb1 LOCALE_PROVIDER=icu ICU_LOCALE=en
TEMPLATE=template0 ;
CREATE DATABASE
postgres=# SELECT datname, daticulocale FROM pg_database
WHERE datname='icudb1' ;
 datname | daticulocale
---------+--------------
 icudb1  | en
(1 row)
The psql command outputs ICU Locale and Locale Provider in the output of the \l command.

PDF page 29

Example 30 List databases
postgres=> \l
                                                List of databases
   Name    |  Owner   | Encoding |  Collate   |   Ctype    | ICU Locale | Locale Provider…
-----------+----------+----------+------------+------------+------------+--------------- …
postgres  | postgres | UTF8     | en_US.utf8 | en_US.utf8 | en         | icu             …
template0 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | en         | icu             …
template1 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | en         | icu             …
(3 rows)

3.1.7 Statistics Information

In previous versions, the stats collector process received UDP protocol packets and periodically wrote them to temporary files. PostgreSQL 15 now stores statistics in shared memory. Information on the shared memory area for statistics can be obtained by searching the pg_shmem_allocations view and pg_backend_memory_contexts view. The stats collector process has been deprecated as a result of this specification change.

Example 31 Shared memory for Statistics information
postgres=# SELECT * FROM pg_shmem_allocations WHERE name LIKE 'Shared%Stats' ;
        name         |    off    |  size  | allocated_size
---------------------+-----------+--------+----------------
 Shared Memory Stats | 147331584 | 263312 |         263424
(1 row)
postgres=# SELECT name, total_bytes, free_bytes, used_bytes FROM
pg_backend_memory_contexts WHERE name LIKE 'PgStat%' ;
          name          | total_bytes | free_bytes | used_bytes
------------------------+-------------+------------+------------
 PgStat Shared Ref Hash |        7224 |        680 |       6544
 PgStat Shared Ref      |        4096 |       1432 |       2664
 PgStat Pending         |        4096 |       2168 |       1928
(3 rows)

PDF page 30

3.1.8 GiST Index

The following enhancements have been implemented to the GiST index:

Index statistics

Access to the SP-GiST index is now counted in the pg_stat_ * views.

BOOL type

It is now possible to create an index for a Boolean type.

Example 32 GiST index creation for BOOK type
postgres=> CREATE EXTENSION btree_gist ;
CREATE EXTENSION
postgres=> CREATE TABLE gist1(c1 INT, c2 BOOL, c3 VARCHAR(10)) ;
CREATE TABLE
postgres=> CREATE INDEX idx1_gist1 ON gist1 USING gist (c2) ;
CREATE INDEX

3.1.9 Wait Events

The following wait events have been added.

Wait Event nameTypeDescription
ArchiveCleanupCommandIPCWaiting for the archive_cleanup_command command to complete
ArchiveCommandIPCWaiting for the archive_command command to complete
BaseBackupSyncIOWaiting for storage synchronization of base backup
BaseBackupWriteIOWaiting for base backup write
RecoveryEndCommandIPCWaiting for the recovery_end_command command to complete
RestoreCommandIPCWaiting for the restore_command command to complete
VersionFileWriteIOWaiting for the version file to be written while creating a database.
VacuumTruncateTimeoutWaiting to acquire an exclusive lock to truncate off any empty pages
Table 14 Added Wait Events

PDF page 31

The wait events PgStatMain, LogicalChangesRead, LogicalChangesWrite, LogicalSubxactRead, and LogicalSubxactWrite have been removed.

3.1.10 Role

The predefined role pg_checkpoint has been added. This role holder can execute the CHECKPOINT statement.

Example 33 Grant pg_checkpoint role
postgres=# CREATE USER check1 PASSWORD 'check1' ;
CREATE ROLE
postgres=# \connect postgres check1
You are now connected to database "postgres" as user "check1".
postgres=> CHECKPOINT ;
ERROR:  must be superuser or have privileges of pg_checkpoint to do CHECKPOINT
postgres=> \connect postgres postgres
You are now connected to database "postgres" as user "postgres".
postgres=# GRANT pg_checkpoint TO check1 ;
GRANT ROLE
postgres=# \connect postgres check1
You are now connected to database "postgres" as user "check1".
postgres=> CHECKPOINT ;
CHECKPOINT

3.1.11 Libpq

The following enhancements have been implemented in the Libpq API:

Environment variable PG_COLORS

It is now possible to specify ’note’ in the color specification item of the terminal output.

PQsslAttribute

The PQsslAttribute(NULL, “library”) function can now be executed to obtain the name of the library in use.

PDF page 32

PQcancel

The connection string tcp_user_timeout and keepalives are now available for executing the PQcancel API.

Allow root-owned SSL private keys in libpq

Libpq applies the same private key file ownership and permission checks as used on the backend. The private key can be owned by either the current user or the root

3.1.12 Custom WAL resource manager

The custom WAL resource managers can now be registered for the shared_preload_libraries parameter. The pg_get_wal_resource_managers function has been added to check the current WAL resource managers.

Example 34 Check WAL resource manager
postgres=# SELECT * FROM pg_get_wal_resource_managers() ;
 rm_id |      rm_name      | rm_builtin
-------+-------------------+------------
     0 | XLOG              | t
     1 | Transaction       | t
     2 | Storage           | t
     3 | CLOG              | t
…

3.1.13 Hook

The following hooks have been added.

String object access

Added an access hook for string objects. Executed when accessing the GUC string.

PDF page 33

Example 35 Hook definition (src/include/catalog/objectaccess.h)
typedef void (*object_access_hook_type_str) (ObjectAccessType access,
                                        Oid classId,
                                        const char *objectStr,
                                        int subId,
                                        void *arg);
extern PGDLLIMPORT object_access_hook_type_str object_access_hook_str;
Shared memory request

It must be specified from within the _PG_init function when the extension module gets the shared memory.

Example 36 Hook definition (src/include/miscadmin.h)
typedef void (*shmem_request_hook_type) (void);
extern PGDLLIMPORT shmem_request_hook_type shmem_request_hook;
extern PGDLLIMPORT bool process_shmem_requests_in_progress;
Object access hook

Execution of the ALTER TABLE SET {LOGGED, UNLOGGED, ACCESS METHOD} statement now executes an object access hook.

3.1.14 Custom scan providers

The custom scan providers can now choose to support projection. In previous versions, all custom scan providers needed projection support. Control is performed by the CUSTOMPATH_SUPPORT_PROJECTION macro.

3.1.15 Build target

The target name of Makefile to be specified when building from source code has been added. The following targets do not build or install documentation.

  • world-bin

  • install-world-bin

PDF page 34

This specification will also be backported to older versions.

3.1.16 Dynamic Shared Memory

Dynamic Shared Memory (DSM) is now also available in single user mode.