PostgreSQL 14 New Features With Examples (GA) - PostgreSQL14GA - New - Features - en - 20211001-1
PostgreSQL 14 New Features With Examples (GA) - PostgreSQL14GA - New - Features - en - 20211001-1
1.1 Purpose
The purpose of this document is to provide information about the major new features of open-source
RDBMS PostgreSQL 14 (14.0) GA.
1.2 Audience
This document is written for engineers who already know PostgreSQL, such as installation, basic
management, etc.
1.3 Scope
This document describes the major difference between PostgreSQL 13 (13.4) and PostgreSQL 14
(14.0). As a general rule, this document examines the features of behavior change. This document does
not describe and verify all new features. In particular, the following new features are not included.
• Bugfix
• Performance improvement by changing internal behavior
• Improvement of regression test
• Operability improvement by psql command tab input
• Improvement of pgbench command
• Improvement of documentation, modify typo in the source code
• Refactoring without a change in behavior
Table 1 Version
Software Version
PostgreSQL PostgreSQL 13.4 (for comparison)
PostgreSQL 14 (14.0) (Sep 27, 2021 21:02:15)
1.6 Notation
This document contains examples of the execution of the command or SQL statement. Execution
examples are described according to the following rules:
□ LZ4 compression
LZ4 compression is now available for TOAST columns.
□ BRIN index
Bloom filters are now available.
2.5. Incompatibility
In PostgreSQL 14, the following specifications have been changed from PostgreSQL 13.
2.5.1. Functions
The following functions have been changed.
□ LEAD / LAG
The data type of some function return values has been changed from anyelement type to
anycompatible type.
□ VAR_SAMP, STDDEV_SAMP
The return value specified as a NaN value of type numeric has changed from NaN to NULL.
□ Removed operator
The factorial operator (! and !!) has been removed.
□ Removed function
The numeric_fac function has been removed.
2.5.4. Operators
The deprecated operators @ and ~ have been removed from the Contrib modules cube, hstore,
intarray and seg.
2.5.5. Manuals
The Default Roles in the manual and the program source have been changed to Predefined Roles.
2.5.9. Protocol
The version 2 client-backend communication protocol has been removed. This protocol has been
used since PostgreSQL 7.4.
2.5.14. Findoidjoins
The findoidjoins command has been removed.
2.5.15. Intarray
Prevent the containment operators (<@ and @>) for intarray module from using GiST
indexes.
2.5.17. Pg_standby
The pg_standby command has been removed.
2.5.18. Tablefunc
Negative values can no longer be specified for the first parameter of the normal_rand function.
3.1. Architecture
Among the modified system catalogs, the details of the major catalogs are described below.
□ Pg_stat_progress_copy
This view will output the execution status of the COPY statement.
□ Pg_stat_replication_slots
This view outputs the state of the logical replication slot. To reset the contents of the view, run the
pg_stat_reset_replication_slot function.
□ Pg_stat_wal
Only one tuple of WAL output status is output to the pg_stat_wal view. The value of this view can
be reset by pg_stat_reset_shared function with 'wal' specified. The values of the wal_write_time and
wal_sync_time columns are output only when the track_wal_io_timing parameter to 'on'.
□ Binary transfer
Traditional logical replication has converted data into text and transfers it. Binary transfer is possible
by setting the attribute binary of SUBSCRIPTION to 'on'. This can be expected to reduce the amount
of network transfer. If no attribute is specified, it will be transferred in text format as before.
□ Wait Events
The following wait events can now be confirmed.
□ Add Messages
The output plugin accepts a new parameter 'Messages' that controls if logical decoding messages are
written into the replication stream.
CREATE TABLE
Table "public.compress1"
--------+---------+-----------+----------+---------+----------+-------------+ …
c1 | integer | | | | plain | | …
ALTER TABLE
Table "public.compress1"
--------+---------+-----------+----------+---------+----------+-------------+ …
c1 | integer | | | | plain | | …
In the CREATE TABLE (LIKE) statement, specify the "LIKE table name INCLUDING
COMPRESSION" clause to copy the table definition up to the compressed definition. Compression
attribute of each column can be found in the attcompression column of pg_attribute catalog. 'p' is pglz
compression and 'l' is LZ4 compression. To check the compression method of the column, execute the
pg_column_compression function with the column name.
□ Asynchronous execution
Asynchronous processing can now be executed in ForeignScan processing. Improve performance by
running ForeignScan in parallel when accessing data on remote servers. To use this feature, set the
async_capable option to 'on' in the postgres_fdw module (default value is 'off').
It is displayed as Async Foreign Scan in the execution plan. In the example below, the partitions
part1v1 and part1v2 contained in the partition table part1 are implemented as FOREIGN TABLE
respectively.
QUERY PLAN
---------------------------------------------------------------------------
(3 rows)
□ Memoize
The new executor node type named Memoize has been added. The planner can include this node type
in the plan to have the executor cache the results from inside the parameterized nested loop join. The
use of this execution plan can be controlled by the parameter enable_memoize. The default value is
'on'. Currently, this execution plan is considered for regular joins and LATERAL type joins.
QUERY PLAN
---------------------------------------------------------------------------
Aggregate (cost=450.10..450.11 rows=1 width=40)
□ Multirange type
A data type has been provided that indicates multiple ranges that do not overlap. The specific data
types are as follows.
□ Jsonb type
The access method by subscript for jsonb type has been enhanced.
□ Point type
The operators (<<|, >>|) that get strictly below/above can now be used for point types.
□ Bloom Filter
The operator classes "{data type}_bloom_ops" that use Bloom filters have been added. The following
attributes can be specified for this operator class.
Syntax
int SPI_execute_extended(const char *src, const SPIExecuteOptions
*options)
□ SPI_cursor_parse_open
Set up a cursor using a query string and parameters.
Syntax
Portal SPI_cursor_parse_open(const char *name, const char *src,
const SPIParseOpenOptions *options)
□ SPI_scroll_cursor_fetch
Fetch some rows from a cursor
Syntax
void SPI_scroll_cursor_fetch(Portal portal, FetchDirection
direction, long count)
□ Pipeline mode
The libpq pipeline mode allows applications to avoid FE/BE protocol synchronization messages
implicitly included in the old libpq API after each query. The following functions have been added.
□ Debug log
The PQsetTraceFlags function has been added.
3.1.13. ECPG
DECLARE STATEMENT statement can now be specified for ECPG.
int main()
{
EXEC SQL CONNECT TO postgres USER postgres;
3.1.14. Roles
The following roles have been added.
□ Pg_database_owner
The pg_database_owner role has been added. Members of this role implicitly consist of the database
owner. It is usually expected to be used in a template database.
□ Pg_read_all_data / pg_write_all_data
Added pg_read_all_data role, which allows reading all objects in the database, and
pg_write_all_data role, which allows writing.
□ Log_autovacuum_min_duration
Detailed information for each index is now output to the automatic VACUUM log
(log_autovacuum_min_duration).
□ Log_connection
Additional information about authentication is output to the connection log (log_connection).
□ WAL Receiver
The status is now output to the process name of the wal receiver process.
□ WAL sender
The replication command name is now output to the process name of the WAL sender process for
logical replication.
$ cd src/test/modules/plsample
$ ls -l
total 24
drwxrwxr-x. 2 postgres postgres 26 Sep 28 06:00 expected
-rw-r--r--. 1 postgres postgres 440 Sep 28 05:57 Makefile
-rw-r--r--. 1 postgres postgres 469 Sep 28 05:57 plsample--1.0.sql
-rw-r--r--. 1 postgres postgres 5046 Sep 28 05:57 plsample.c
-rw-r--r--. 1 postgres postgres 177 Sep 28 05:57 plsample.control
-rw-r--r--. 1 postgres postgres 228 Sep 28 05:57 README
drwxrwxr-x. 2 postgres postgres 26 Sep 28 06:00 sql
3.1.21. LLVM
Now supports LLVM 12.
Syntax
ALTER SUBSCRIPTION subscription_name [ ADD | DROP ] PUBLICATION
publication_name
□ OUT clause
It is now possible to specify the OUT clause as a parameter of PROCEDURE.
□ LANGUAGE SQL
When the LANGUAGE SQL clause is specified in the CREATE FUNCTION statement and
CREATE PROCEDURE statement, it is not necessary to enclose it in character literals, and SQL
standard-compliant syntax is supported. The source for FUNCTION / PROCEDURE created with this
syntax is stored in the prosqlbody column of the pg_proc catalog.
Syntax
CREATE TYPE name AS RANGE (
SUBTYPE = subtype
[ , MULTIRANGE_TYPE_NAME = multirange_type_name ]
)
Syntax
CREATE TYPE name (
INPUT = input_function,
OUTPUT = output_function
[ , SUBSCRIPT = subscript_function ]
)
Syntax
GRANT role_name [, …] TO role_specification
[ WITH ADMIN OPTION ] [ GRANTED BY role_specification ]
3.2.11. INSERT
The following enhancements have been implemented in the INSERT statement.
□ ON CONFLICT clause
It is now possible to qualify a table name for a column specification in the WHERE clause in the ON
CONFLICT clause.
□ Partitioned table
It is now possible to specify a partitioned table for the REINDEX statement.
3.2.13. VACUUM
The following enhancements have been implemented in VACUUM.
□ TOAST table
The PROCESS_TOAST option can now be specified in the VACUUM statement. This option
performs VACUUM processing on the TOAST table. This parameter is enabled by default. To disable
processing of the TOAST table, specify the PROCESS_TOAST FALSE option.
3.2.14. SELECT
The following enhancements have been implemented to the SELECT statement.
□ USING AS clause
It is now possible to use aliases for columns specified in the JOIN USING clause. Aliases are also
available in the SELECT clause for the columns specified in the JOIN. This is a feature defined in
SQL:2016 feature F404 "Range variable for common column names".
3.2.15. TRUNCATE
TRUNCATE statements can now be executed in FOREIGN TABLE if supported by FOREIGN
DATA WRAPPER. The postgres_fdw module now supports the TRUNCATE statement.
3.2.16. Functions
The following functions have been added / extended.
□ Bit_count
Outputs the number of bits that are turned on in the specified bit string or bytea type.
Syntax
bigint BIT_COUNT(bit | bytea)
Syntax
integer | bit BIT_XOR(bigint | bit | integer | smallint)
□ Date_bin
Truncates the entered timestamp at the specified interval. It is similar to the date_trunc function, but
can be truncated at any interval.
Syntax
timestamp with time zone DATE_BIN(stride interval, source
timestamp with time zone, origin timestamp with time zone)
□ Make_timestamp / make_timestamptz
These functions can now specify a negative value indicating the BC to the specified year.
□ Split_part
It is now possible to specify a negative value for the third parameter of the split_part function. If a
negative value is specified, the part from the right side of the string specified in the first parameter can
be cut off.
□ Substring
It now conforms to the syntax formulated in the SQL standard, SQL:2003.
Syntax
text SUBSTRING(search_text text SIMILAR pattern text ESCAPE escape
text)
The execution result is the same as SUBSTRING(text FROM pattern FOR escape).
□ Trim_array
The function trim_array has been added to remove the end of an array.
Syntax
anyarray TRIM_ARRAY(array anyarray, n integer)
□ Unistr
The unistr function evaluates the specified Unicode escaped string.
□ String_to_table
The string_to_table function separates the string with the specified separator and converts it to a table.
Syntax
setoff STRING_TO_TABLE(string text, delimiter text [, null_string
text])
□ Pg_get_wal_pause_state
Returns the paused state of recovery. Returns "not paused" if no pause was requested, "pause
requested" if pause was requested but recovery is not paused, and "paused" if recovery is paused. In
PostgreSQL 14, recovery is now paused if the required parameter values are missing.
Syntax
text PG_GET_WAL_REPLAY_PAUSE_STATE()
(1 row)
□ Pg_log_backend_memory_contexts
The pg_log_backend_memory_contexts function outputs the memory status of the process with the
specified ID as a LOG level message.
□ Pg_terminate_backend
The pg_terminate_backend function now has a parameter to specify a timeout. The function will
return true if the session exits within the timeout.
Syntax
boolean PG_TERMINATE_BACKEND(pid integer,
timeout bigint DEFAULT 0)
□ Pg_xact_commit_timestamp_origin
This function outputs the time stamp and replication origin for the transaction ID. There is a need to
specify 'on' the track_commit_timestamp the execution of this function.
Syntax
record PG_XACT_COMMITTED_TIMESTAMP_ORIGIN(xid xid, OUT timestamp
timestamp with time zone, OUT roident oid)
□ Pg_last_committed_xact
The function now outputs a roident column indicating the replication origin in the execution result.
Syntax
record PG_LAST_COMMITTED_XACT()
□ Pg_get_catalog_foreign_keys
Added pg_get_catalog_foreign_keys function to retrieve information about foreign keys defined in
a system catalog. This function can be run by general users.
□ Pg_create_logical_replication_slot
The parameter twophase has been added to support two-phase commit.
-[ RECORD 1 ]-------+-------------------------------------------------------
Schema | pg_catalog
Name | pg_create_logical_replication_slot
□ Idle_session_timeout
Specifies the timeout value in milliseconds for forcibly terminating idle sessions. The default value
is 0, which means that no timeout will occur. During transaction execution,
idle_in_transaction_session_timeout is used and idle_session_timeout is ignored.
□ Log_recovery_conflict_waits
In an environment where the log_recovery_conflict_waits parameter is enabled on the standby
instance, conflict information is output to the log when a conflict occurs when deadlock_timeout is
exceeded. Also, if the conflict is resolved, it will be output to the log. The following is the output
conflict information.
3.4.1. Configure
The following options have been added to the 'configure' command.
3.4.2. Initdb
The following options have been added to the initdb command.
□ --no-instructions option
When this option is specified, a message indicating the instance start-up method will not be output.
□ --data-checksums option
In the message output when the --help option is specified, the --data-checksums option that specifies
the checksum has been promoted from "Less commonly used options:" to the commonly used option
"Options:".
Usage:
Options:
-A, --auth=METHOD default authentication method for local connections
3.4.3. Pg_amcheck
The pg_amcheck command has been added. This command makes it easy to check the structure of
tables and indexes against a database with the Contrib module amcheck installed. In the following
example, it can be seen that the damaged part of data2 table.
Many options can be specified for the pg_amcheck command other than the above example.
3.4.4. Pg_dump
The pg_dump command has been following enhancements are implemented.
□ Restore partitions
It is now possible to restore a single partition from the partitioned table as a table.
3.4.5. Pg_dumpall
The pg_dumpall command now has an option --no-toast-compression that does not dump the
compression settings for TOAST data.
3.4.6. Pg_rewind
It is now possible to specify a standby instance of streaming replication as the connection destination.
3.4.7. Psql
The following features have been added to the psql command.
--------+------------+-------+-------+-------+-------------+-------------+ …
public | idx1_data1 | index | demo | data1 | permanent | btree | …
--------+---------+-------------------+-------+-------------+-----------+ …-
public | data1 | table | demo | permanent | heap | …
public | data2 | table | demo | permanent | heap | …
(2 rows)
□ \dX command
Outputs a list of extended statistics.
ANALYZE
postgres=> \dX
List of extended statistics
Schema | Name | Definition | Ndistinct | Dependencies | MCV
--------+-------------+-------------------+-----------+--------------+------
public | stat1_data1 | c1, c2 FROM data1 | defined | defined | defined
(1 row)
Table "public.compress1"
--------+---------+-----------+----------+---------+----------+------------+ …
c1 | integer | | | | plain | | …
Table "public.compress1"
--------+---------+-----------+----------+---------+----------+--------------+ …
c1 | integer | | | | plain | | …
c2 | text | | | | extended | | …
List of operators
Schema | Name | Left arg type | Right arg type | Result type | Description
------------+------+---------------+----------------+-------------+-----------
(1 row)
List of functions
------------+------+------------------+---------------------+------
(1 row)
□ \dT command
The \dT command now accepts alias names for data types.
3.4.8. Reindexdb
The --tablespace option has been added to the reindexdb command. It is now possible to specify the
tablespace in which to store the indexes to be recreated.
3.4.9. Vacuumdb
The following options have been added to the vacuumdb command.
□ --force-index-cleanup option
Always remove index entries pointing to dead tuples.
□ --no-index-cleanup option
Do not delete unnecessary tuples in the index.
□ --no-truncate option
Do not truncate the free pages at the end of the table.
□ --no-process-toast option
Do not perform VACUUM processing on the TOAST table.
Usage:
Options:
-a, --all vacuum all databases
dead tuples
vacuum
tuples
--no-process-toast skip the TOAST table associated with the
table to vacuum
--no-truncate don't truncate empty pages at the end of the
table
-P, --parallel=PARALLEL_WORKERS use this many background workers for vacuum,
if available
…
3.5.1. Amcheck
The verify_heapam function has been added to check the structure of the table.
3.5.2. Btree_gist
All functions provided by the btree_gist module is now parallel-safe.
3.5.3. Cube
The cube type now supports binary I/O.
3.5.5. Old_snapshot
This is a newly added Contrib module. This module defines the pg_old_snapshot_time_mapping
function. When the parameter old_snapshot_threshold is set to something other than -1, the mapping
between XIDs and timestamps can be displayed.
3.5.6. Pageinspect
The following functions for GiST indexes have been added.
3.5.8. Pgstattuple
The pgstattuple_approx function can now be executed on TOAST tables.
3.5.9. Pg_stat_statements
The following features have been extended to the pg_stat_statements module. When using
pg_stat_statements, compute_query_id parameter must be specified as 'on' or 'auto'.
□ Pg_stat_statements view
The following columns have been added.
□ Pg_stat_statements_info view
The pg_stat_statements_info view has been added. This view can be used to check the operational
status of the pg_stat_statements module. Currently, the pg_stat_statements view only provides a
dealloc column showing the number of SQL statements deleted and a stats_reset column showing the
date and time the statistics were reset. The 'dealloc' column is used to validate the
pg_stat_statements.max parameter.
3.5.11. Pg_surgery
A new Contrib module, pg_surgery, has been added. It provides a function heap_force_freeze to force
a tuple to freeze, and a function heap_force_kill to force it to be deleted.
(1 row)
postgres=# SELECT xmin, ctid, c1 FROM data1 ;
xmin | ctid | c1
------+-------+-----
2 | (0,1) | 100
(1 row)
postgres=# SELECT heap_force_kill('data1'::regclass,
ARRAY['(0, 1)']::tid[]) ;
heap_force_kill
-----------------
(1 row)
postgres=# SELECT xmin, ctid, c1 FROM data1 ;
xmin | ctid | c1
------+------+----
(0 rows)
3.5.12. Postgres_fdw
The following enhancements have been implemented for the postgres_fdw module.
□ Functions
The following functions have been added to control the active session.
□ TRUNCATE statement
The TRUNCATE statement can now be executed on an foreign table.
c2 | character varying(10) | | | |
Server: svr1
FDW options: (batch_size '1000')
The following interfaces have been added to the Foreign Data Wrapper for the bulk insert feature.
□ keep_connections option
The option keep_connections controls remote connections after a transaction completes. The default
value is 'on', which keeps the connection after the transaction is completed. Setting this option to 'off'
closes the connection when the transaction completes.
□ Reconnect
If the session with the remote instance is found to be broken, it will now be reconnected.
□ Release Notes
https://www.postgresql.org/docs/14/release-14.html
□ Commitfests
https://commitfest.postgresql.org/
□ PostgreSQL 14 Manual
https://www.postgresql.org/docs/14/index.html
□ Git
git://git.postgresql.org/git/postgresql.git
□ GitHub
https://github.com/postgres/postgres
□ Announce of PostgreSQL 14 GA
https://www.postgresql.org/about/news/postgresql-14-released-2318/
□ Postgres Professional
https://habr.com/ru/company/postgrespro/blog/541252/
□ PostgreSQL 14 Open Items
https://wiki.postgresql.org/wiki/PostgreSQL_14_Open_Items
□ Qiita (Nuko@Yokohama)
http://qiita.com/nuko_yokohama
□ pgsql-hackers Mailing list
https://www.postgresql.org/list/pgsql-hackers/
□ PostgreSQL Developer Information
https://wiki.postgresql.org/wiki/Development_information
□ pgPedia
https://pgpedia.info/postgresql-versions/postgresql-14.html
□ SQL Notes
https://sql-info.de/postgresql/postgresql-14/articles-about-new-features-in-postgresql-14.html
□ Slack - postgresql-jp
https://postgresql-jp.slack.com/