Skip to content

7 Contrib Modules

Changes to contrib extensions and the modules covered by the source document.
GASource pages: PDF 90-106Original PDF on GitHub

PDF page 90

Describes new features related to the Contrib modules.

3.5.1 Amcheck

The function gin_index_check, which checks the GIN index, has been added. [14ffaec]

Example 117 Checking the GIN index
postgres=# CREATE INDEX idx1_gin1 ON gin1 USING GIN
(to_tsvector('english', title1)) ;
CREATE INDEX
postgres=# SELECT gin_index_check('idx1_gin1') ;
 gin_index_check
-----------------
(1 row)

3.5.2 Bloom

Bloom index usage is now stored in the pg_stat_*_index view. [93063e2]

PDF page 91

Example 118 Bloom Index Usage
postgres=> CREATE INDEX idx1_bloom ON data1 USING bloom (col1) ;
CREATE INDEX
postgres=> EXPLAIN ANALYZE SELECT * FROM data1 WHERE col1=10000 ;
                                 QUERY PLAN
------------------------------------------------------------------------------
 Bitmap Heap Scan on data1  (cost=15348.00..15352.01 rows=1 width=10) …
   Recheck Cond: (col1 = 10000)
   Rows Removed by Index Recheck: 350
   Heap Blocks: exact=341
   ->  Bitmap Index Scan on idx1_bloom  (cost=0.00..15348.00 rows=1 width=0)…
         Index Cond: (col1 = 10000)
 Planning Time: 0.101 ms
 Execution Time: 3.602 ms
(8 rows)
postgres=> SELECT indexrelname, idx_scan, idx_tup_read FROM
 pg_stat_user_indexes ;
 indexrelname | idx_scan | idx_tup_read
--------------+----------+--------------
 idx1_bloom   |        1 |          351
(1 row)

The option use_scram_passthrough has been added to the foreign data wrapper dblink_fdw to pass through SCRAM authentication. [3642df2]

Example 119 Pass-through of SCRAM authentication credentials
postgres=# CREATE SERVER link1 FOREIGN DATA WRAPPER dblink_fdw OPTIONS
(host 'dbsvr1', port '5432', dbname 'demodb', use_scram_passthrough 'true') ;
CREATE SERVER

PDF page 92

3.5.4 File_fdw

The following options have been added. These options can have the same values as the options in the COPY statement. [a1c4c8a, 6c8f670]

Option nameDescription
on_errorDetermines the action to be taken when a minor error occurs. The possible values are as follows
• default: Stop execution (default value)
• ignore: Continue execution of the process
log_verbosityThis parameter determines the level of log output. The following values can be specified
• default: Output the number of errors (default value)
• verbose: Output more detailed logs
• silent: No log output
reject_limitSpecifies the number of data type conversion error records to allow, with the on_error=ignore option
Table 29 Added options

PDF page 93

Example 120 Additional options for file_fdw module (option on_error = 'ignore')
postgres=# \! cat /tmp/fs1.csv
100,data1
ABC,data2
300,data3
postgres=# CREATE EXTENSION file_fdw ;
CREATE EXTENSION
postgres=# CREATE SERVER fs FOREIGN DATA WRAPPER file_fdw ;
CREATE SERVER
postgres=# CREATE FOREIGN TABLE fs1 (id INT, val TEXT) SERVER fs
OPTIONS (filename '/tmp/fs1.csv', FORMAT 'csv',
ON_ERROR 'ignore', REJECT_LIMIT '1') ;
CREATE FOREIGN TABLE
postgres=# SELECT * FROM fs1 ;
NOTICE:  1 row was skipped due to data type incompatibility
 id  |  val
-----+-------
 100 | data1
 300 | data3
(2 rows)
Example 121 Additional options for file_fdw module (option log_verbosity = ‘verbose’)
postgres=# CREATE FOREIGN TABLE fs2 (id INT, val TEXT) SERVER fs
  OPTIONS (filename '/tmp/fs1.csv', FORMAT 'csv', ON_ERROR 'ignore',
REJECT_LIMIT '1', LOG_VERBOSITY 'verbose') ;
CREATE FOREIGN TABLE
postgres=# SELECT * FROM fs2 ;
NOTICE:  skipping row due to data type incompatibility at line 2 for column
"id": "ABC"
NOTICE:  1 row was skipped due to data type incompatibility
 id  |  val
-----+-------
 100 | data1
 300 | data3
(2 rows)

PDF page 94

3.5.5 Injection_points

The following new features have been added to the injection_points module

Additional custom parameter

The parameter injection_points.stats has been added. This parameter determines whether cumulative statistics are enabled in the module. By default, statistics are disabled (off). [2e35c67]

Add callbacks

The callback to initialize the shared memory of the module specified in the shared_preload_libraries parameter has been added. [b2b023a]

3.5.6 Isn

The isn.weak parameter has been added to the isn module. Previous versions used the isn_weak function, which has been retained for compatibility but is now set to VOLATILE. [4489044]

3.5.7 Passwordcheck

The parameter passwordcheck.min_password_length, which indicates the minimum password length, has been added to the passwordcheck module. The default value for this parameter is 8. [f7e1b38]

Example 122 Minimum password length setting
postgres=# SET passwordcheck.min_password_length = 12 ;
SET
postgres=# ALTER ROLE demo PASSWORD 'ABCDEFGHIJK' ;
ERROR:  password is too short
DETAIL:  password must be at least "passwordcheck.min_password_length" (12)
bytes long

PDF page 95

3.5.8 Pgcrypto

The following enhancements have been added to the pgcrypto module

Addition of the fips_mode function

The fips_mode function has been added to indicate whether OpenSSL has FIPS enabled. [924d89a]

Syntax 19 - Fips_mode function

boolean fips_mode()
Example 123 Execution of the fips_mode function
postgres=> SELECT fips_mode() ;
 fips_mode
-----------
 f
(1 row)
Control of built-in crypto functions

When OpenSSL is used in FIPS mode, cryptographic implementations that are not FIPS certified should not be used. The parameter pgcrypto.built-in_crypto_enabled has been added to disable builtin functions for this purpose. Only SUPERUSER can change this parameter. [035f99c]

Example 124 Disable built-in functions
postgres=# SET pgcrypto.builtin_crypto_enabled = off ;
SET
postgres=# SELECT gen_salt('des') ;
ERROR:  use of built-in crypto functions is disabled
postgres=# SELECT crypt('data1', 'salt1') ;
ERROR:  use of built-in crypto functions is disabled
CFB Mode Added to AES Encryption Functions

CFB (Cipher-FeedBack mode) has been added to the AES encryption mode. [9ad1b3d]

PDF page 96

Example 125 Added CFB mode
postgres=> SELECT encrypt('foo', '0123456789', 'aes-cfb') ;
 encrypt
----------
 \x6f8ced
(1 row)
postgres=> SELECT encode(decrypt(encrypt('foo', '0123456', 'aes-cfb'),
'0123456', 'aes-cfb'), 'escape') ;
 encode
--------
 foo
(1 row)
SHA-2-based hashing and encryption
  SHA-2 based hash algorithms sha256crypt and sha512crypt are now available. [749a9e2]

PDF page 97

Example 126 SHA-256 / SHA-512 hashing and encryption
postgres=> SELECT gen_salt('sha256crypt') ;
            gen_salt
---------------------------------
 $5$rounds=5000$yTxNtev7NxPXhErT
(1 row)
postgres=> SELECT gen_salt('sha512crypt') ;
            gen_salt
---------------------------------
 $6$rounds=5000$NoKe0.dTtV9RHhBN
(1 row)
postgres=> SELECT crypt('test', gen_salt('sha512crypt')) ;
                                                         crypt
---------------------------------------------------------------------------…
$6$rounds=5000$B6qwrNDTAV6Zq5ZX$D8mfxoa3IO2BUjZWG4fMCs52wcb9wLigkDwfA4ZZ6CE3yW
Mwy5sIZ0xLCZI/dctvxQP9Grx7sk.ooQu5GI7hf1
(1 row)

3.5.9 Pg_buffercacahe

The following new features have been added to the pg_buffercache module

Added the pg_buffercache_numa view

New view pg_buffercache_numa with the following columns has been added. [ba2a3c2]

Column nameData typeDescription
bufferidintegerBuffer ID
os_page_numbigintOS page number
numa_nodeintegerNUMA node number
Table 30 Column structure of the pg_buffercache_numa view
Added functions

The following functions have been added. [dcf7e16]

PDF page 98

Function nameDescription
pg_buffercache_evict_relationRemove specific table information from buffer cache
pg_buffercache_evict_allRemove all information from buffer cache
Table 31 Added functions
Example 127 Execution of the pg_buffercache_evict_relation function
postgres=# SELECT * FROM pg_buffercache_evict_relation('data1') ;
 buffers_evicted | buffers_flushed | buffers_skipped
-----------------+-----------------+-----------------
            5410 |            5406 |               0
(1 row)

3.5.10 Pg_logicalinspect

The pg_logicalinspect module has been added to PostgreSQL 18. This contrib module provides functions to inspect logical decoding components. The added function specifies a snapshot file of the logical decoding. [7cdfeee]

Syntax 20 - Pg_get_logical_snapshot / Pg_get_logical_snapshot_info functions

record pg_get_logical_snapshot_meta(filename text)
record pg_get_logical_snapshot_info(filename text)
Example 128 Execution of the pg_get_logical_snapshot_meta function
postgres=# SELECT * FROM pg_get_logical_snapshot_meta('0-57004740.snap') ;
-[ RECORD 1 ]--------
magic    | 1369563137
checksum | 1831531145
version  | 6

PDF page 99

Example 129 Execution of the pg_get_logical_snapshot_info function
 postgres=# SELECT * FROM pg_get_logical_snapshot_info('0-57004740.snap') ;
-[ RECORD 1 ]------------+-----------
state                    | consistent
xmin                     | 767
xmax                     | 766
start_decoding_at        | 0/570043B8
two_phase_at             | 0/0
initial_xmin_horizon     | 0
building_full_snapshot   | f
in_slot_creation         | f
last_serialized_snapshot | 0/57004708
next_phase_at            | 0
committed_count          | 0
committed_xip            |
catchange_count          | 0
catchange_xip

3.5.11 Pg_overexplain

The pg_overexplain module has been added to PostgreSQL 18. When loaded, this module allows the addition of the DEBUG option to the EXPLAIN statement, which can be used to debug the output of an EXPLAIN statement. [8d5ceb1, 9f0c36a]

PDF page 100

Example 130 Execution of the EXPLAIN (DEBUG) statement
postgres=# LOAD 'pg_overexplain' ;
LOAD
postgres=# EXPLAIN (DEBUG) SELECT * FROM data1 WHERE col1=1000 ;
                               QUERY PLAN
-------------------------------------------------------------------------
 Index Scan using data1_pkey on data1  (cost=0.42..8.44 rows=1 width=10)
   Index Cond: (col1 = 1000)
   Disabled Nodes: 0
   Parallel Safe: true
   Plan Node ID: 0
 PlannedStmt:
   Command Type: select
   Flags: canSetTag
   Subplans Needing Rewind: none
   Relation OIDs: 16389
   Executor Parameter Types: none
   Parse Location: 16 for 33 bytes
(12 rows)

3.5.12 Pg_stat_statements

The following features have been added to the pg_stat_statements module.

Retrieving Internal SQL

The query ID can now also be calculated for internal SQL statements used for CREATE TABLE AS and DECLARE CURSOR statements. This allows the execution time of internal SQL to be retrieved in environments where the pg_stat_statements.track option is set to ‘all’. [6b652e6]

PDF page 101

Example 131 Capture internal SQL statements
postgres=> SHOW pg_stat_statements.track ;
 pg_stat_statements.track
--------------------------
 all
(1 row)
postgres=> CREATE TABLE data2 AS SELECT * FROM data1 WHERE col1=1000 ;
SELECT 1
postgres=>  SELECT queryid, toplevel, query FROM pg_stat_statements WHERE query
LIKE '%data2%' ;
       queryid        | toplevel |                     query
----------------------+----------+--------------------------------------------
  3120039891713996032 | f        | CREATE TABLE data6 AS SELECT * FROM …
 -9061638578758616641 | t        | CREATE TABLE data6 AS SELECT * FROM …
(2 rows)
SET Statements as Constants

The SET statement settings are stored as constants with parameter symbols in the pg_stat_statements table. Previously, statements with different specified values were stored separately. If the constants DEFAULT or FROM CURRENT are used, they are not subject to constant conversion. [dc68515]

Example 132 SET statement constant
postgres=> SET work_mem = '8MB' ;
SET
postgres=> SET work_mem = '16MB' ;
SET
postgres=> SET work_mem = DEFAULT ;
SET
postgres=> SELECT query, calls FROM pg_stat_statements WHERE query LIKE 'SET%' ;
         query          | calls
------------------------+-------
 SET work_mem = DEFAULT |     1
 SET work_mem = $1      |     2
(2 rows)

PDF page 102

Additional Columns

The following columns have been added to the pg_stat_statements view. The columns added are parallel query execution information and the number of times the WAL buffer was full. [cf54a2c, ce5bcc4]

Column nameData typeDescription
parallel_workers_to_launchbigintNumber of parallel workers scheduled to execute
parallel_workers_launchedbigintNumber of parallel workers executed
wal_buffers_fullbigintNumber of times the WAL buffer has been full
Table 32 Added columns
Example 133 Verify additional columns (parallel query information)
postgres=> SELECT COUNT(*) FROM data1 ;
-[ RECORD 1 ]--
count | 1000000
postgres=> SELECT query, parallel_workers_to_launch, parallel_workers_launched
FROM pg_stat_statements WHERE userid=16384 ;
-[ RECORD 1 ]--------------+---------------------------
query                      | SELECT COUNT(*) FROM data1
parallel_workers_to_launch | 4
parallel_workers_launched  | 4
Compression of Constant Lists

When the number of IN lists in a WHERE clause is variable, previous versions allocated separate Query IDs. PostgreSQL 18 compresses the constant list and assigns a single Query ID. [62d712e, 9fbd53d] For example, execute the following SQL statement and check it in the pg_stat_statements view.

Example 134 SQL statements to execute
SELECT * FROM data1 WHERE col1 IN (10, 20) ;
SELECT * FROM data1 WHERE col1 IN (10, 20, 30, 40, 50) ;

PDF page 103

Example 135 PostgreSQL 17 behavior
postgres=> SELECT calls, query FROM pg_stat_statements WHERE query LIKE
'%data1%' ;
 calls |                          query
-------+----------------------------------------------------------
     1 | SELECT * FROM data1 WHERE col1 IN ($1, $2)
     1 | SELECT * FROM data1 WHERE col1 IN ($1, $2, $3)
(2 rows)
Example 136 PostgreSQL 18 behavior
postgres=> SELECT calls, query FROM pg_stat_statements WHERE query LIKE
'%data1%' ;
 calls |                      query
-------+---------------------------------------------------
     2 | SELECT * FROM data1 WHERE col1 IN ($1 /*, ... */)
(1 row)

3.5.13 Pgstattuple / pageinspect

Each function in the Contrib module now also supports sequences. [05036a3]

Example 137 Pageinspect module
postgres=# CREATE EXTENSION pageinspect ;
CREATE EXTENSION
postgres=# SELECT tuple_data_split('seq1'::regclass, t_data, t_infomask,
t_infomask2, t_bits) FROM heap_page_items(get_raw_page('seq1', 0)) ;
-[ RECORD 1 ]----+------------------------------------------------------
tuple_data_split | {"\\x0100000000000000","\\x0000000000000000","\\x00"}

PDF page 104

Example 138 Pgstattuple module
postgres=# CREATE SEQUENCE seq1 ;
CREATE SEQUENCE
postgres=# CREATE EXTENSION pgstattuple ;
CREATE EXTENSION
postgres=# SELECT * FROM pgstattuple('seq1') ;
-[ RECORD 1 ]------+------
table_len          | 8192
tuple_count        | 1
tuple_len          | 41
tuple_percent      | 0.5
dead_tuple_count   | 0
dead_tuple_len     | 0
dead_tuple_percent | 0
free_space         | 8108
free_percent       | 98.97

3.5.14 Postgres_fdw

The following features have been added to the postgres_fdw module.

SCRAM Authentication Pass-through

The option USE_SCRAM_PASSThrough has been added to perform authentication by automatically sending SCRAM authentication information. This option can be specified as an attribute of SERVER or USER MAPPING. [761c795]

Example 139 Pass-through settings for SCRAM authentication
postgres=# CREATE SERVER remsvr1 FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host 'dbsvr1', port '5432', dbname 'postgres') ;
CREATE SERVER
postgres=# CREATE USER MAPPING FOR demo SERVER remsvr1
OPTIONS (user 'demo', use_scram_passthrough 'true') ;
CREATE USER MAPPING

PDF page 105

Enhancements to the postgres_fdw_get_connections function

The used_in_xact and closed columns have been added to the return value of the postgres_fdw_get_connections function. Also, a check_conn parameter (default false) has been added to the function’s parameters to check for connections. [c297a47, 857df3c, 4f08ab5]

Column nameData typeDescription
user_nametextConnection mapping username (or public)
used_in_xactbooleanIs a transaction in progress?
closedbooleanIs the session closed?
Table 33 Added return column
Example 140 Execution of the postgres_fdw_get_connections function
postgres=> BEGIN ;
BEGIN
postgres=*> INSERT INTO data1 VALUES (100, 'data1') ;
INSERT 0 1
postgres=*> SELECT * FROM postgres_fdw_get_connections(true) ;
 server_name | user_name | valid | used_in_xact | closed | remote_backend_pid
-------------+-----------+-------+--------------+--------+--------------------
 remsvr1     | public    | t     | t            | f      |             309160
(1 row)
postgres=*> COMMIT ;
COMMIT
postgres=> SELECT * FROM postgres_fdw_get_connections(true) ;
 server_name | user_name | valid | used_in_xact | closed | remote_backend_pid
-------------+-----------+-------+--------------+--------+--------------------
 remsvr1     | public    | t     | f            | f      |             309160
(1 row)
Function postgres_fdw_get_connections

The remote_backend_pid column (type int4), which indicates the backend process ID of the remote server, has been added to the return value of the postgres_fdw_get_connections function. [fe186bd]

PDF page 106

Example 141 Execution of the postgres_fdw_get_connections function
postgres=> CREATE FOREIGN TABLE data1(col1 INT, col2 VARCHAR(10))
SERVER remsvr1 ;
CREATE FOREIGN TABLE
postgres=> SELECT * FROM data1 ;
 col1 | col2
------+------
(0 rows)
postgres=> SELECT * FROM postgres_fdw_get_connections() ;
 server_name | user_name | valid | used_in_xact | closed | remote_backend_pid
-------------+-----------+-------+--------------+--------+--------------------
 remsvr1     | demo      | t     | f            |        |             370760
(1 row)

3.5.15 Miscellaneous

In addition to those described above, the following test extension modules have been added under the src/test/modules directory. [93bc3d7, b3f0be7, b85a9d0]

Module nameDescription
oauth_validatorOAUTHBeare/SASL Validator
test_aioAsynchronous I/O Testing
typecacheType cache Testing
Table 34 Added modules