Skip to content

PostgreSQL 13 New Features

GA source edition · 81 pages · 2020-09-27

WITH EXAMPLES · ENGLISH SOURCE EDITION

Explore the features, SQL examples, and compatibility changes documented by Noriyoshi Shinoda.

GA2020-09-2781 PDF pages9 chapters

Contents

Reference indexes

The opening chapter includes the first numbered table, Table 1. The indexes below collect the book’s other native numbered components.

Tables
  1. Table 1 — Version
  2. Table 2 — Examples notation
  3. Table 3 — Syntax rules
  4. Table 4 — Changing default settings
  5. Table 5 — Added system catalogs
  6. Table 6 — Dropped catalog
  7. Table 7 — Dropped views in information_schema schema
  8. Table 8 — System catalogs with columns added
  9. Table 9 — System catalogs with columns dropped
  10. Table 10 — System catalog with changed output tuples
  11. Table 11 — pg_shmem_allocations catalog
  12. Table 12 — pg_stat_progress_analyze catalog
  13. Table 13 — pg_stat_progress_basebackup catalog
  14. Table 14 — pg_stat_slru catalog
  15. Table 15 — Functions that use 64-bit transaction IDs
  16. Table 16 — Added abstract data types
  17. Table 17 — Added wait events
  18. Table 18 — Wait event that has been renamed
  19. Table 19 — channel_binding parameter values
  20. Table 20 — Attributes that can be changed
  21. Table 21 — Added format pattern
  22. Table 22 — null_value_treatment parameter value
  23. Table 23 — Added parameters
  24. Table 24 — Changed parameters
  25. Table 25 — Parameters that default value has been changed
  26. Table 26 — pg_verifybackup command option
  27. Table 27 — Added command
  28. Table 28 — Added columns
  29. Table 29 — Added columns
  30. Table 30 — Modified columns
Examples
  1. Example 1 — CSV log (part)
  2. Example 2 — Default prompt
  3. Example 3 — Execute the to_date function
  4. Example 4 — Partition key with pseudo-types
  5. Example 5 — PostgreSQL 12 behavior
  6. Example 6 — PostgreSQL 13 behavior
  7. Example 7 — Refer pg_shmem_allocations catalog
  8. Example 8 — Refer pg_stat_progress_analyze catalog
  9. Example 9 — Refer pg_stat_progress_basebackup catalog
  10. Example 10 — Refer pg_stat_slru catalog
  11. Example 11 — Execute to_regcollation function
  12. Example 12 — Disk-based hash aggregation
  13. Example 13 — Incremental sort
  14. Example 14 — backup_manifest file
  15. Example 15 — Manifest file for backup in tar file format
  16. Example 16 — pg_verifybackup command
  17. Example 17 — Add partitioned table to PUBLICATION
  18. Example 18 — Non-partitioned table on SUBSCRIPTION side
  19. Example 19 — CREATE TRIGGER statement for a partitioned table
  20. Example 20 — Partitiond column expression
  21. Example 21 — Log output for Autovacuum
  22. Example 22 — Shared memory key-value
  23. Example 23 — plpgsql.control file contents
  24. Example 24 — CREATE EXTENSION statement executed by a general user
  25. Example 25 — Information on automatically created replication slots
  26. Example 26 — Text search languages
  27. Example 27 — ALTER NO DEPENDS ON statement
  28. Example 28 — ALTER STATISTICS SET STATISTICS statement
  29. Example 29 — ALTER TABLE DROP EXPRESSION statement
  30. Example 30 — ALTER TABLE SET STORAGE statement
  31. Example 31 — ALTER TYPE SET statement
  32. Example 32 — Rename view column name
  33. Example 33 — Specify LOCALE clause
  34. Example 34 — B-Tree index deduplication
  35. Example 35 — Effect of index deduplication
  36. Example 36 — Specifying additional attributes for tables
  37. Example 37 — Specify maintenance_io_concurrency attribute
  38. Example 38 — DROP DATABASE statement
  39. Example 39 — EXPLAIN (ANALYZE, BUFFERS) statement
  40. Example 40 — EXPLAIN (BUFFERS) statement
  41. Example 41 — Output of the EXPLAIN ANALYZE statement (JIT)
  42. Example 42 — Output of the EXPLAIN ANALYZE statement (Sort)
  43. Example 43 — EXPLAIN (ANALYZE, WAL) statement
  44. Example 44 — INSERT OVERRIDING USER VALUE statement
  45. Example 45 — datetime method
  46. Example 46 — MAX(pg_lsn) function
  47. Example 47 — Extracting values from ROW expressions
  48. Example 48 — SELECT FETCH FIRST WITH TIES statement
  49. Example 49 — PARALLEL specification of VACUUM statement
  50. Example 50 — Operator <->
  51. Example 51 — gen_random_uuid function
  52. Example 52 — Date format
  53. Example 53 — min_scale, trim_scale function
  54. Example 54 — jsonb_set_lax function
  55. Example 55 — gcd, lcm function
  56. Example 56 — is normalized syntax
  57. Example 57 — is normalized syntax
  58. Example 58 — backtrace_functions parameter
  59. Example 59 — dropdb --force option
  60. Example 60 — pg_basebackup ---no-estimate-size option
  61. Example 61 — pg_dump --include-foreign-data option
  62. Example 62 — ALTER DEPENDS ON EXTENSION statement
  63. Example 63 — pg_rewind command
  64. Example 64 — pg_verifybackup command
  65. Example 65 — pg_verifybackup command with error
  66. Example 66 — pg_verifybackup command with error
  67. Example 67 — \dAc command
  68. Example 68 — \g command
  69. Example 69 — \warn command
  70. Example 70 — \e command
  71. Example 71 — \d command
  72. Example 72 — PROMPT2 variable value
  73. Example 73 — reindexdb --jobs option
  74. Example 74 — vacuumdb --parallel option
  75. Example 75 — --help option
  76. Example 76 — pg_file_sync function
  77. Example 77 — log_wal parameter
  78. Example 78 — ABSVAL attribute
  79. Example 79 — information on the ltree data type
  80. Example 80 — heap_tuple_infomask_flags function
  81. Example 81 — Output of bt_metap function
  82. Example 82 — Output of bt_page_items function
  83. Example 83 — Refer the pg_stat_statements view
  84. Example 84 — Create USER MAPPING object without a password
  85. Example 85 — Creation of external table by general user and error
  86. Example 86 — Setting to allow password omission
  87. Example 87 — bool_plperl extension
Figures

Source edition

The source chapter order, wording, examples, and publication credits are retained. PDF page markers link the reading edition to the original document. Source identity and coverage · About the collection

1 About This Document

Purpose, audience, scope, software versions, notation, and responsibility statement.
GASource pages: PDF 5-6Original PDF on GitHub

PDF page 5

1.1 Purpose

The purpose of this document is to provide information about the major new features of PostgreSQL 13 (13.0).

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 12 (12.4) and PostgreSQL 13 Beta 1 (13.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

1.4 Software Version

The contents of this document have been verified for the following versions and platforms.

SoftwareVersion
PostgreSQLPostgreSQL 12.4 (for comparison) PostgreSQL 13 (13.0) GA (Sep 21, 2020 20:51:14)
Operating SystemRed Hat Enterprise Linux 7 Update 5 (x86-64)
Configure option–with-llvm –with-openssl –with-perl –with-python
Table 1 Version

PDF page 6

1.5 The Question, comment, and Responsibility

The contents of this document are not an official opinion of Hewlett Packard Enterprise Japan Co, Ltd. The author and affiliation company do not take any responsibility for the problem caused by the mistake of contents. If you have any comments for this document, please contact Noriyoshi Shinoda (noriyoshi.shinoda@hpe.com) Hewlett Packard Enterprise Japan Co, Ltd.

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:

NotationDescription
#Shell prompt for Linux root user.
$Shell prompt for Linux general user.
BoldThe user input string.
postgres=#psql command prompt for PostgreSQL administrator.
postgres=>psql command prompt for PostgreSQL general user.
UnderlineImportant output items.
Underline «PASSWORD»Important output items. Replaced by password string.
Table 2 Examples notation

The syntax is described in the following rules:

NotationDescription
ItalicReplaced by the name of the object which users use, or the other syntax.
[ ]Indicate that it can be omitted.
{ A | B }Indicate that it is possible to select A or B.
…General syntax. It is the same as the previous version.
Table 3 Syntax rules

2 New Features Summary

The source document’s overview of the release, benefits, and incompatibilities.
GASource pages: PDF 7-14Original PDF on GitHub

PDF page 7

More than 200 new features have been added to PostgreSQL 13. Here are some major new features and benefits.

2.1 Improve analytic query performance

  The following features have been added that can be applied to large scale environments:

Enhancement of Parallel operations

If more than one of the indexes has been created in the table, now VACUUM processing is performed in parallel.

Deduplication of B-Tree index

Deduplication is now executed by default for B-Tree indexes. Storage capacity and I/O can be reduced.

Reduce WAL output

The statement that suppresses WAL output when the wal_level parameter is set to ‘minimal’ has been increased.

2.2 Improve reliability

PostgreSQL 13 implements the following enhancements to improve reliability.

Improve backup reliability

Backup consistency can now be checked. Base backups, such as the pg_basebackup command, take the size and checksum of each file and save it to the backup destination. The consistency of the obtained backup can be checked with the pg_verifybackup command.

Dynamic configuration changes for streaming replication

Various parameters used on the standby instance of streaming replication can now be changed dynamically. This new feature eliminates the need to restart the standby instance if the primary instance fails.

PDF page 8

2.3 Improved maintainability

The following features that can improve operability have been added.

Disk-based Hash Aggregation

Operations that manipulate hash tables now are performed on storage when the memory usage limit is exceeded. Previously, there was no upper limit on memory usage, which sometimes led to OOM Killer.

Logical replication of partitioned tables

Partitioned tables can now be used in logical replication environments.

Enhanced monitoring features

Catalogs that can check the execution status of the ANALYZE statement or pg_basebackup command in real-time have been added. Also, the cache hit ratio and I/O status can be checked.

Execution plan creation and WAL output tracking

The amount of WAL output can now be tracked when creating an execution plan or executing an SQL statement. It can be checked by the pg_stat_statements module and EXPLAIN statement.

More wait events

Several wait events have been added that can be monitored. Wait events can be checked in the pg_stat_activity catalog.

2.4 Preparing for future new features

PostgreSQL 13 is now ready for features that will be provided in future versions.

Supports 64-bit transaction ID

The xid8 data type that indicates a 64-bit transaction ID and various functions that handle this data type has been added.

Lock contention

Page locks and extended locks can now conflict between parallel worker processes. With this implementation, it is now possible to implement parallelization such as COPY, INSERT, VACUUM, etc.

PDF page 9

Enhancement of PUBLICATION

It is now ready to add non-table objects to PUBLICATION.

PDF page 10

2.5 Incompatibility

In PostgreSQL 13, the following specifications have been changed from PostgreSQL 12.

2.5.1 configure

The –disable-float4-byval option has been removed from the ‘configure’ command. Also, the pkgconfig command is now used to search for the libxml2 library.

2.5.2 createuser

The –adduser and –no-adduser options have been removed from the createuser command.

2.5.3 CSV log format

Backend type is added at the end of CSV format log (log_destination = ‘csvlog’).

Example 1 CSV log (part)
2020-09-24 23:27:12.495 JST,,,30744,,5ec6194a.7818,1,,2020-05-21
15:01:46 JST,,0,LOG,00000,"database system was shut down at 2020-
05-21 15:01:29 JST",,,,,,,,,"","startup"
2020-09-24 23:27:12.495 JST,,,30734,,5ec61949.780e,6,,2020-05-21
15:01:45 JST,,0,LOG,00000,"database system is ready to accept
connections",,,,,,,,,"","postmaster"
2020-09-24
23:27:12.495
JST,"postgres","postgres",30753,"[local]",5ec61953.7821,1,"SELECT"
,2020-05-21 15:01:55 JST,3/2,0,ERROR,42P01,"relation ""notexists""
does not exist",,,,,,"SELECT * FROM notexists;",15,,"psql","client
backend"

2.5.4 Extension

Remove support for upgrading “unpackaged” extensions.

PDF page 11

2.5.5 opaque

The opaque pseudo-data type has been removed. This data type was used for compatibility from PostgreSQL 7.3 and earlier.

2.5.6 Require version of OpenSSL

OpenSSL 1.0.0 and below are no longer supported. OpenSSL 1.0.1 or higher is required. With this fix, the minimum value of the parameter ssl_min_protocol_version has been changed from TLSv1 to TLSv1.2.

2.5.7 pg_regress

The –load-language option has been removed from the pg_regress command.

2.5.8 psql default prompt

The default prompt settings PROMPT1 and PROMPT2 of the psql command now include %x to indicate the status of the transaction.

Variable namePostgreSQL 12PostgreSQL 13Note
PROMPT1“%/%R%# "“%/%R%x%# "
PROMPT2“%/%R%# "“%/%R%x%# "
PROMPT3“» "“» "no change
Table 4 Changing default settings
Example 2 Default prompt
postgres=> BEGIN ;
BEGIN
postgres=*> -- In the active transaction
postgres=*> ERROR ;
ERROR: syntax error at or near "ERROR"
LINE 1: ERROR
        ^
postgres=!> -- In the failed transaction
postgres=!> ROLLBACK ;
ROLLBACK

PDF page 12

2.5.9 to_date/to_timestamp

The output contents of the format string TM change according to the locale. Previously, it was ignored.

Example 3 Execute the to_date function
postgres=> SET lc_time='ru_RU' ;
SET
postgres=> SELECT to_date('01 фев 2020', 'DD TMMON YYYY') ;
  to_date
------------
 2020-02-01
(1 row)

2.5.10 Promotion during recovery

Previously, if a promotion was made while the recovery was paused, the paused state would continue. In PostgreSQL 13, if a promotion is performed while recovery is paused, the promotion takes precedence.

2.5.11 Partition key

Disallow partition key expressions that return pseudo-types. This specification has been backported to PostgreSQL 12.2 and later.

Example 4 Partition key with pseudo-types
postgres=> CREATE TABLE part1 (c1 INT, c2 INT)
PARTITION BY RANGE(((c1, c2))) ;
ERROR:  partition key column 1 has pseudo-type record

2.5.12 Wait Event

Many wait events have been renamed. The event_name column in the pg_stat_activity catalog and the output string in the locktype column in the pg_locks catalog has been changed1.

1 See 3.1.8 Wait events

PDF page 13

2.5.13 SIMILAR TO ESCAPE

SIMILAR TO… ESCAPE NULL clause returns NULL. In previous versions, the ESCAPE NULL clause was ignored.

Example 5 PostgreSQL 12 behavior
postgres=> SELECT 'ABC' SIMILAR TO 'ABC' ESCAPE NULL ;
 ?column?
----------
 t
(1 row)
Example 6 PostgreSQL 13 behavior
postgres=> \pset null null
Null display is "null".
postgres=> SELECT 'ABC' SIMILAR TO 'ABC' ESCAPE NULL ;
?column?
----------
 null
(1 row)

PDF page 14

3 Architecture

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

PDF page 14

3.1.1 Modified catalogs

The following catalogs have been changed.

Catalog nameDescription
pg_shmem_allocationsView the breakdown of shared memory.
pg_stat_progress_analyzeTracking the progress of the ANALYZE statement.
pg_stat_progress_basebackupTracking the progress of the base backup.
pg_stat_slruTracking SLRU cache statistics.
Table 5 Added system catalogs
Catalog nameDescription
pg_pltemplateProcedural language templates.
Table 6 Dropped catalog
Catalog nameDescription
sql_languagesSQL statement standards compliance levels, options, and dialects.
sql_packagesList of standard packages.
sql_sizing_profilesList of defined size information.
Table 7 Dropped views in information_schema schema

PDF page 15

Catalog nameAdded columnData typeDescription
pg_available_extension_versionstrustedbooleanThe extension can be installed by nonsuperusers.
pg_publicationpubviarootbooleanConvert partition updates to route tables.
pg_replication_slotswal_statustextWAL file status.
safe_wal_sizebigintA number of bytes that can be written to WAL for the state “lost”.
pg_stat_activityleader_pidintegerLeader PID for the parallel query.
pg_stat_{all|sys|user}_tablesn_ins_since_vacuumbigintThe Number of tuples inserted since the last VACUUM.
pg_stat_wal_receiverwritten_lsnpg_lsnThe last WAL location for already received and written to disk, but not flushed.
flushed_lsnpg_lsnThe last WAL location already received and flushed to disk.
pg_statistic_extstxstattargetintegerSET STATISTIC value.
pg_triggertgparentidoidOID of parent trigger.
Table 8 System catalogs with columns added
Catalog nameDropped columnDescription
pg_stat_wal_receiverreceived_lsnSplit into written_lsn and flushed_lsn.
Table 9 System catalogs with columns dropped
CatalognameDescription
pg_locksThe value ‘speculative token’ output in the locktype column has changed to ‘spectoken’.
pg_stat_sslProcess information other than client connection has been removed.
pg_stat_gssapiProcess information other than client connection has been removed.
Table 10 System catalog with changed output tuples

Catalog name Description

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

PDF page 16

Pg_shmem_allocations catalog

The pg_shmem_allocations catalog allows you to see the breakdown in shared memory. However, it does not include the area of dynamic shared memory. Only users with the SUPERUSER attribute can see this catalog.

Column nameData typeDescription
nametextThe name of the memory area, ’null’ is an unused area.
offbigintOffset from the start position.
sizebigintReserved bytes.
allocated_sizebigintReserved bytes including padding.
Table 11 pg_shmem_allocations catalog
Example 7 Refer pg_shmem_allocations catalog
postgres=# SELECT * FROM pg_shmem_allocations ;
                name                 |    off    |   size    | allocated_size
-------------------------------------+-----------+-----------+-------------
Buffer IO Locks                     | 140660096 |    524288 |         524288
 Buffer Descriptors                  |   5393792 |   1048576 |        1048576
 Backend SSL Status Buffer           | 146585088 |     42312 |          42368
 Async Queue Control                 | 147119360 |      2492 |           2560
 Wal Sender Ctl                      | 147112832 |      1280 |           1280
 AutoVacuum Data                     | 147104384 |      5368 |           5376
 PROCLOCK hash                       | 143136000 |      2904 |           2944
 FinishedSerializableTransactions    | 146097664 |        16 |            128
 XLOG Ctl                            |     53504 |   4208272 |        4208384
 Shared MultiXact State              |   5392640 |      1028 |           1152
…
Pg_stat_progress_analyze catalog

The pg_stat_progress_analyze catalog allows you to check the execution status of the ANALYZE statement. This catalog can be viewed by ordinary users, but ordinary users cannot see the status of other users’ command execution.

PDF page 17

Column nameData typeDescription
pidintegerBackend process ID.
datidoidOID of the connection database.
datnamenameConnection database name.
relidoidTable OID executing ANALYZE statement.
phasetextExecution phase.
sample_blks_totalbigintTotal number of blocks sampled.
sample_blks_scannedbigintNumber of sampled blocks.
ext_stats_totalbigintExtended statistics.
ext_stats_computedbigintNumber of extended statistics computed.
child_tables_totalbigintNumber of child tables.
child_tables_donebigintNumber of child tables for ANALYZE are done.
current_child_table_relidoidANALYZE executing child table OID.
Table 12 pg_stat_progress_analyze catalog
Example 8 Refer pg_stat_progress_analyze catalog
postgres=# SELECT * FROM pg_stat_progress_analyze ;
-[ RECORD 1 ]-------------+---------------------
pid                       | 30932
datid                     | 13578
datname                   | postgres
relid                     | 16388
phase                     | computing statistics
sample_blks_total         | 54055
sample_blks_scanned       | 54055
ext_stats_total           | 0
ext_stats_computed        | 0
child_tables_total        | 0
child_tables_done         | 0
current_child_table_relid | 0
Pg_stat_progress_basebackup catalog

The pg_stat_progress_basebackup catalog allows you to check the status of the backups performed by tools such as the pg_basebackup command. This catalog can be viewed by non-superuser users, but only the ‘pid’ column can be viewed by non-connected users.

PDF page 18

Column nameData typeDescription
pidintegerWAL sender process ID.
phasetextThe string indicating the execution phase.
backup_totalbigintTotal backup size.
backup_streamedbigintStreaming data volume.
tablespaces_totalbigintNumber of total tablespaces.
tablespaces_streamedbigintNumber of streaming tablespaces.
Table 13 pg_stat_progress_basebackup catalog
Example 9 Refer pg_stat_progress_basebackup catalog
postgres=# SELECT * FROM pg_stat_progress_basebackup ;
-[ RECORD 1 ]--------+-------------------------
pid                  | 31080
phase                | streaming database files
backup_total         | 467913216
backup_streamed      | 302026752
tablespaces_total    | 1
tablespaces_streamed | 0
Pg_stat_slru catalog

Pg_stat_slru catalog can check the usage status of the SLRU cache. Displays statistics on accesses to cached pages for each SLRU cache area.

Column nameData typeDescription
nametextSLRU name.
blks_zeroedbigintNumber of blocks initialized to zero.
blks_hitbigintNumber of blocks that hit the cache.
blks_readbigintNumber of blocks read.
blks_writtenbigintNumber of blocks written.
blks_existsbigintNumber of blocks checked for existence in the cache.
flushesbigintNumber of dirty blocks flushed.
truncatesbigintNumber of blocks truncated.
stats_resettimestamp with time zoneDate and time when statistics were reset.
Table 14 pg_stat_slru catalog

PDF page 19

The counter values in this view will persist across instance reboots. Execute pg_stat_reset_slru function2 to reset the counter value.

Example 10 Refer pg_stat_slru catalog
postgres=# SELECT name, blks_hit, blks_read, blks_written
FROM pg_stat_slru ;
      name       | blks_hit | blks_read | blks_written
-----------------+----------+-----------+--------------
 CommitTs        |        0 |         0 |            0
 MultiXactMember |        0 |         0 |            0
 MultiXactOffset |        0 |         0 |            0
 Notify          |        0 |         0 |            0
 Serial          |        0 |         0 |            0
 Subtrans        |        0 |         0 |            0
 Xact            |       14 |         0 |            0
 other           |        0 |         0 |            0
(8 rows)

3.1.2 Data types

The following data types have been added:

Regcollation

The regcollation type that indicates the Collation name has been added. A to_regcollation function has been added to convert from text type to regcollation type.

Example 11 Execute to_regcollation function
postgres=> SELECT to_regcollation('"POSIX"') ;
 to_regcollation
-----------------
 "POSIX"
(1 row)
2 See 3.2.19 Functions

PDF page 20

Xid8

The xid8 type that indicates a 64-bit transaction ID has been added. Functions that use the xid8 type have been added. The functions that return the conventional 32-bit transaction ID are kept for compatibility. However, they may be removed in the future.

function namefunction name
txid_currentpg_current_xact_id
txid_current_if_assignedpg_current_xact_id_if_assigned
txid_current_snapshotpg_current_snapshot
txid_snapshot_xippg_snapshot_xip
txid_snapshot_xmaxpg_snapshot_xmax
txid_snapshot_xminpg_snapshot_xmin
txid_visible_in_snapshotpg_visible_in_snapshot
txid_statuspg_xact_status
Table 15 Functions that use 64-bit transaction IDs
Pg_snapshot

The pg_snapshot type stores information about the transaction ID visibility (xmin, xmax, xip_list) at a specific point in time.

Other abstract data types

In addition, the following abstract data types have been added.

Data type nameDescription
anycompatibleThe function accepts any data type and is automatically promoted.
anycompatiblearrayThe function accepts any array type and is automatically promoted.
anycompatiblenonarrayThe function accepts an non-array type and is automatically promoted.
anycompatiblerangeThe function accepts any range type and is automatically promoted.
table_am_handlerTable access method handler.
Table 16 Added abstract data types

3.1.3 Disk-based hash aggregation

A hash table may be created in memory when executing a GROUP BY or DISTINCT clause. PostgreSQL 13 performs storage-based hash aggregation if the hash table cannot be stored in work memory. In previous versions, work memory was created on the assumption that it could be stored in

PDF page 21

memory, which could lead to unexpected increases in memory usage.

Example 12 Disk-based hash aggregation
postgres=> EXPLAIN ANALYZE SELECT COUNT(*) FROM data1 GROUP BY c1 ;
                               QUERY PLAN
-----------------------------------------------------------------
HashAggregate
(cost=4304055.00..5029055.00
rows=10000000
width=14) (actual time=2703.993..16089.774 rows=10000000 loops=1)
   Group Key: c1
   Planned Partitions: 4  Batches: 87381  Memory Usage: 109kB  Disk
Usage: 268256kB
   ->  Seq Scan on data1  (cost=0.00..154055.00 rows=10000000
width=6) (actual time=0.025..606.455 rows=10000000 loops=1)
 Planning Time: 0.039 ms
 Execution Time: 16407.060 ms
(6 rows)

3.1.4 Incremental sort

Incremental sorting is a way to reduce the resources used for multi-column sorting. It is used when another column needs to be sorted in addition to the already sorted column. This feature can be controlled by the enable_incremental_sort parameter. The default value is ‘on’.

PDF page 22

Example 13 Incremental sort
postgres=> EXPLAIN ANALYZE SELECT * FROM (SELECT * FROM data1 ORDER
BY c1) t ORDER BY c1, c2;
                                   QUERY PLAN
-----------------------------------------------------------------
Incremental Sort  (cost=0.49..853808.44 rows=10000000 width=12)
(actual time=0.063..2253.672 rows=10000000 loops=1)
   Sort Key: data1.c1, data1.c2
   Presorted Key: data1.c1
   Full-sort Groups: 312500  Sort Method: quicksort  Average
Memory: 26kB  Peak Memory: 26kB
   ->
Index
Only
Scan
using
idx1_data1
on
data1
(cost=0.43..303808.43
rows=10000000
width=12)
(actual
time=0.045..891.341 rows=10000000 loo
ps=1)
         Heap Fetches: 0
 Planning Time: 0.258 ms
 Execution Time: 2495.751 ms
(8 rows)

3.1.5 Backup manifests

Consistency checks can now be executed on base backups created with the pg_basebackup command, etc. The size and checksum are calculated for each file in the database cluster.

Checksum

The checksum calculation method can be selected from SHA224, SHA256, SHA384, SHA512, and CRC32C. CRC32C is the default value.

Manifest file

The backup manifest is stored as backup_manifest in the backup directory. It is a file in JSON format.

PDF page 23

Example 14 backup_manifest file
$ pg_basebackup -D back
$ cat back/backup_manifest
{ "PostgreSQL-Backup-Manifest-Version": 1,
"Files": [
{ "Path": "backup_label", "Size": 226, "Last-Modified": "2020-09-
24 06:20:15 GMT", "Checksum-Algorithm": "CRC32C", "Checksum":
"0e45028a" },
{ "Path": "global/1262", "Size": 8192, "Last-Modified": "2020-09-
24 05:50:10 GMT", "Checksum-Algorithm": "CRC32C", "Checksum":
"6a2131f8" },
…
"WAL-Ranges": [
{
"Timeline":
1,
"Start-LSN":
"0/2D000028",
"End-LSN":
"0/2D0001E8" }
],
"Manifest-Checksum":
"8832de70e00fd7612125364088a945ff5cacca3befb4004eea255e2b498a0ca6
"}
If the backup is performed in tar format, the manifest file is not included in the tar file.
Example 15 Manifest file for backup in tar file format
$ pg_basebackup --format=tar -D back
$ ls back
backup_manifest  base.tar  pg_wal.tar
$
Check consistency

The pg_verifybackup command is provided to recheck the integrity of the obtained backup. Specify the backup destination directory name to the pg_verifybackup command3.

3 See 3.4.6 pg_verifybackup

PDF page 24

Example 16 pg_verifybackup command
$ pg_verifybackup back
backup successfully verified

3.1.6 Partitioned table

The following features have been added to the partitioned table.

Logical replication support

The partitioned tables can now be added to PUBLICATION in a logical replication environment. In the previous version, the CREATE PUBLICATION statement in the example below failed. In order for replication to succeed, a table with the same structure is required on the SUBSCRIPTION side.

Example 17 Add partitioned table to PUBLICATION
postgres=> CREATE TABLE part1(c1 NUMERIC PRIMARY KEY, c2 VARCHAR(10))
PARTITION BY RANGE(c1) ;
CREATE TABLE
postgres=> CREATE TABLE part1v1 PARTITION OF part1 FOR VALUES
FROM (0) TO (100000) ;
CREATE TABLE
postgres=> CREATE TABLE part1v2 PARTITION OF part1 FOR VALUES
FROM (100000) TO (200000) ;
CREATE TABLE
postgres=> CREATE PUBLICATION pub1 FOR TABLE part1 ;
CREATE PUBLICATION
postgres=> \dRp+ pub1
                            Publication pub1
 Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
-------+------------+---------+---------+---------+-----------+----------
 demo  | f            | t        | t         | t        | t           | f
Tables:
    "public.part1"

PDF page 25

By default, PUBLICATION sends updates to the partition to SUBSCRIPTION without converting them to updates to the partition table. When replicating to a non-partitioned table on the SUBSCRIPTION side, set the PUBLICATION attribute publish_via_partition_root to ‘off’.

Example 18 Non-partitioned table on SUBSCRIPTION side
postgres=> ALTER PUBLICATION pub1 SET (publish_via_partition_root = on) ;
ALTER PUBLICATION
postgres=> \dRp+ pub1
                            Publication pub1
 Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
-------+------------+---------+---------+---------+-----------+----------
 demo  | f            | t         | t        | t        | t           | t
Tables:
    "public.part1"
# SUBSCRIPTION side
postgres=> CREATE TABLE part1(c1 NUMERIC PRIMARY KEY, c2 VARCHAR(10)) ;
CREATE TABLE
postgres=# CREATE SUBSCRIPTION sub1 CONNECTION 'host=remhost1 dbname=postgres
user=postgres password=<<PASSWORD>>' PUBLICATION pub1 ;
NOTICE:  created replication slot "sub1" on publisher
CREATE SUBSCRIPTION
postgres=#
BEFORE INSERT trigger

ROW level BEFORE INSERT triggers can now be set. However, a tuple is not possible to change the partition to be stored.

PDF page 26

Example 19 CREATE TRIGGER statement for a partitioned table
postgres=> CREATE TABLE part1 (c1 INT, c2 INT, c3 VARCHAR(10))
PARTITION BY LIST(c1) ;
CREATE TABLE
postgres=> CREATE TABLE part1v1 PARTITION OF part1 FOR VALUES IN
(10) ;
CREATE TABLE
postgres=> CREATE OR REPLACE FUNCTION fnc1_part1() RETURNS TRIGGER
LANGUAGE plpgsql AS $$
   BEGIN
     NEW.c3 = 'TRIGGER';
     RETURN NEW;
 END; $$ ;
CREATE FUNCTION
postgres=> CREATE TRIGGER trg1_part1 BEFORE INSERT ON part1
FOR EACH ROW EXECUTE FUNCTION fnc1_part1() ;
CREATE TRIGGER
postgres=> INSERT INTO part1(c1, c2) VALUES (10, 20) ;
INSERT 0 1
postgres=> SELECT * FROM part1 ;
 c1 | c2 |   c3
----+----+---------
 10 | 20 | TRIGGER
(1 row)
Allow partition wise join in more case

Partition-wise join can now be performed even if the partition structures are not the same. This feature does not work with hash partitioned tables.

Partitioned column using the entire table

It is now possible to specify an entire column to the definition of the partitioning columns.

PDF page 27

Example 20 Partitiond column expression
postgres=> CREATE TABLE part2(c1 INT, c2 INT) PARTITION
BY LIST((part2)) ;
CREATE TABLE
postgres=> CREATE TABLE part2v1 PARTITION OF part2 FOR VALUES
IN ('(1, 2)') ;
CREATE TABLE
postgres=> CREATE TABLE part2v2 PARTITION OF part2 FOR VALUES
IN ('(2, 4)') ;
CREATE TABLE

3.1.7 Log output for Autovacuum

WAL statistics are now output to the automatic VACUUM log.

Example 21 Log output for Autovacuum
2020-09-24 15:59:21.872 JST [31752] LOG:  automatic vacuum of table
"postgres.public.data1": index scans: 1
        pages: 0 removed, 54055 remain, 0 skipped due to pins, 0
skipped frozen
        tuples: 10000000 removed, 0 remain, 0 are dead but not yet
removable, oldest xmin: 514
        buffer usage: 234548 hits, 119331 misses, 130854 dirtied
        avg read rate: 2.780 MB/s, avg write rate: 3.048 MB/s
        system usage: CPU: user: 3.24 s, system: 4.13 s, elapsed:
335.39 s
        WAL usage: 244232 records, 93518 full page images, 303298890
bytes

3.1.8 Wait events

Wait events that are output to the wait_event column of the pg_stat_activity catalog had the following changes.

PDF page 28

Wait event nameDescription
BackupWaitWalArchiveWaiting for archive creation.
RecoveryConflictSnapshotWaiting for recovery conflict resolution during VACUUM cleanup.
RecoveryConflictTablespaceWaiting for resolution of recovery conflict when deleting table space.
RecoveryPauseWaiting for the promotion of standby instance.
VacuumDelayCost-based VACUUM delay.
ProcSignalBarrierWaiting for a barrier event to be processed by all backends.
Table 17 Added wait events
Wait event name (PostgreSQL 12)Wait event name (PostgreSQL 13)
AsyncCtlLockNotifySLRU
AsyncQueueLockNotifyQueue
CLogControlLockXactSLRU
ClogGroupUpdateXactGroupUpdate
CommitTsControlLockCommitTsSLRU
Hash/Batch/AllocatingHashBatchAllocate
Hash/Batch/ElectingHashBatchElect
Hash/Batch/LoadingHashBatchLoad
Hash/Build/AllocatingHashBuildAllocate
Hash/Build/ElectingHashBuildElect
Hash/Build/HashingInnerHashBuildHashInner
Hash/Build/HashingOuterHashBuildHashOuter
Hash/GrowBatches/AllocatingHashGrowBatchesAllocate
Hash/GrowBatches/DecidingHashGrowBatchesDecide
Hash/GrowBatches/ElectingHashGrowBatchesElect
Hash/GrowBatches/FinishingHashGrowBatchesFinish
Hash/GrowBatches/RepartitioningHashGrowBatchesRepartition
Hash/GrowBuckets/AllocatingHashGrowBucketsAllocate
Hash/GrowBuckets/ElectingHashGrowBucketsElect
Hash/GrowBuckets/ReinsertingHashGrowBucketsReinsert
MultiXactOffsetControlLockMultiXactOffsetSLRU
MultiXactMemberControlLockMultiXactMemberSLRU
OldSerXidLockSerialSLRU
RecoveryWalAllRecoveryWalStream
RecoveryWalStreamRecoveryRetrieveRetryInterval
SerializablePredicateLockListLockSerializablePredicateList
SubtransControlLockSubtransSLRU
speculative tokenspectoken
Table 18 Wait event that has been renamed

PDF page 29

There are many event name changes other than the above table, such as deleting ‘Lock’ from the end of the event name.

3.1.9 libpq connection string

The following libpq connection strings have been added/changed.

Channel_binding parameter

The channel_binding parameter has been added to the client connection string to control channel binding. The values that can be specified are as follows.

ValueDescription
requireRequired.
preferClient selection.
disableDisable.
Table 19 channel_binding parameter values

‘Prefer’ is the default value when SSL is enabled. ‘Disable’ is the default value if SSL is disabled. The environment variable PGCHANNELBINDING can specify the same value as this parameter.

Sslkey parameter

ASN.1 DER format files can now be specified for the sslkey parameter.

Ssl_min_protocol_version, ssl_max_protocol_version parameter

Specify the minimum version (ssl_min_protocol_version) and maximum version (ssl_max_protocol_version) of the SSL / TLS protocol. Possible values are TLSv1, TLSv1.1, TLSv1.2, and TLSv1.3. The default value of ssl_min_protocol_version is TLSv1.2. if the value of ssl_max_protocol_version is not specified, the backend value is used. It is also possible to use the environment variables PGSSLMINPROTOCOLVERSION and PGSSLMAXPROTOCOLVERSION

PDF page 30

instead of using parameters.

Sslpassword parameter

Specify the password of the private key specified by the sslkey parameter.

3.1.10 libpq functions

  The following libpq functions have been added.
  • BufferUsageAccumDiff

  • TupleHashTableHash

  • LookupTupleHashEntryHash

  • PQsetSSLKeyPassHook_OpenSSL

  • LogicalTapeSetExtend

3.1.11 Hook

The following hook functions have been provided.

TLS initialization hook

The TLS initialization hook was provided. Specify the callback function in openssl_tls_init_hook.

TRUNCATE hook

The hook is executed to allow mandatory access control (MAC) for the TRUNCATE statement. Contrib module sepgsql can control access to the TRUNCATE statement.

3.1.12 Column trigger

In a logical replication environment, column triggers are now executed on the subscription side.

3.1.13 Local connection key

Conventionally, the key information of the shared memory used by the instance was determined based on the connection waiting port number (parameter ‘port’). PostgreSQL 13 now uses the i-node number of the database cluster.

PDF page 31

Example 22 Shared memory key-value
$ ls -lid data
33832487 drwx------. 20 postgres postgres 4096 Sep 24 08:11 data
$ ipcs -m
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x02043e27 196610     postgres   600        56         6
In the above example, the i-node number is 33,832,487, which is 0x02043e27 when converted to
hexadecimal.

3.1.14 Trusted Extension

The ’trusted’ attribute described in the extension control file ({extension}.control) file has been added. The default value for this attribute is ‘off’. Extensions with this attribute value set to ‘on’ can execute the CREATE EXTENSION statement even if the user does not have the SUPERUSER attribute. Users must have CREATE privilege on the database.

Example 23 plpgsql.control file contents
$ cat plpgsql.control
# plpgsql extension
comment = 'PL/pgSQL procedural language'
default_version = '1.0'
module_pathname = '$libdir/plpgsql'
relocatable = false
schema = pg_catalog
superuser = true
trusted = true

PDF page 32

Example 24 CREATE EXTENSION statement executed by a general user
postgres=# CREATE USER demo PASSWORD '<<PASSWORD>>' ;
CREATE ROLE
postgres=# GRANT CREATE ON DATABASE postgres TO demo ;
GRANT
postgres=# \connect postgres demo
You are now connected to database "postgres" as user "demo".
postgres=> CREATE EXTENSION hstore ;
CREATE EXTENSION
The following extensions have the trusted setting set to 'on'.
• bool_plperl
• btree_gin
• btree_gist
• citext
• cube
• dict_int
• fuzzystrmatch
• hstore
• intarray.
• isn
• jsonb_plperl
• lo
• ltree
• pgcrypto
• pg_trgm
• plperl
• plpgsql
• seg
• tablefunc
• tcn
• tsm_system_rows
• tsm_system_time
• unaccent

PDF page 33

3.1.15 Replication slot

If the parameter primary_slot_name is not specified on the standby instance in a streaming replication environment, a temporary replication slot can be created on the primary instance. The standby instance parameter wal_receiver_create_temp_slot must be ‘on’ (default ‘off’).

Example 25 Information on automatically created replication slots
postgres=# SELECT * FROM pg_replication_slots ;
-[ RECORD 1 ]-------+--------------------
slot_name           | pg_walreceiver_4273
plugin              |
slot_type           | physical
datoid              |
database            |
temporary           | t
active              | t
active_pid          | 4273
xmin                |
catalog_xmin        |
restart_lsn         | 0/390005A0
confirmed_flush_lsn |
wal_status          | reserved
safe_wal_size       |

Languages for text search have been increased. In PostgreSQL 12, there were 22 languages, but in PostgreSQL 13, Greek has been added.

PDF page 34

Example 26 Text search languages
postgres=> \dF
               List of text search configurations
   Schema   |    Name    |              Description
------------+------------+---------------------------------------
 pg_catalog | arabic     | configuration for arabic language
 pg_catalog | danish     | configuration for danish language
 pg_catalog | dutch      | configuration for dutch language
 pg_catalog | english    | configuration for english language
 pg_catalog | finnish    | configuration for finnish language
 pg_catalog | french     | configuration for french language
 pg_catalog | german     | configuration for german language
 pg_catalog | greek      | configuration for greek language << new
 pg_catalog | hungarian  | configuration for hungarian language
…

4 SQL Statements

SQL syntax, data types, functions, optimizer behavior, and worked examples.
GASource pages: PDF 35-54Original PDF on GitHub

PDF page 35

This section explains new features related to SQL statements.

3.2.1 ALTER NO DEPENDS ON

ALTER statements for functions, indexes, materialized views, and triggers can now remove dependency settings for extensions. Syntax

ALTER object_name NO DEPENDS ON EXTENSION extension_name
Example 27 ALTER NO DEPENDS ON statement
postgres=> ALTER FUNCTION func1 DEPENDS ON EXTENSION cube ;
ALTER FUNCTION
postgres=> ALTER FUNCTION func1 NO DEPENDS ON EXTENSION cube ;
ALTER FUNCTION

3.2.2 ALTER STATISTICS SET STATISTICS

Specify the statistics collection target when executing ANALYZE. The value that can be set is from 0 to 10,000. If you specify 10,000 or more, it is assumed to be 10,000. Specify -1 to reset to the default value. Syntax

ALTER STATISTICS statistic_name SET STATISTICS new_target

The specified value can be checked in the stxstattarget column of the pg_statistic_ext catalog or with the command “\d” in the psql utility.

PDF page 36

Example 28 ALTER STATISTICS SET STATISTICS statement
postgres=> CREATE TABLE data1(c1 INT, c2 INT, c3 VARCHAR(10)) ;
CREATE TABLE
postgres=> CREATE STATISTICS stat1 ON c1, c2 FROM data1 ;
CREATE STATISTICS
postgres=> ALTER STATISTICS stat1 SET STATISTICS 10000 ;
ALTER STATISTICS
postgres=> SELECT stxname, stxstattarget FROM pg_statistic_ext
WHERE stxname='stat1' ;
 stxname | stxstattarget
---------+---------------
 stat1   |         10000
(1 row)
postgres=> \d data1
                      Table "public.data1"
 Column |         Type          | Collation | Nullable | Default
--------+--------------------+-----------+----------+---------
 c1     | integer               |             |          |
 c2     | integer               |             |          |
 c3     | character varying(10) |          |          |
Statistics objects:
    "public"."stat1" (ndistinct, dependencies, mcv) ON c1, c2 FROM
data1; STATISTICS 10000

3.2.3 ALTER TABLE

The following enhancements have been added to the ALTER TABLE statement.

ALTER TABLE ALTER COLUMN DROP EXPRESSION

By executing the ALTER TABLE ALTER COLUMN DROP EXPRESSION statement, it is now possible to drop an auto-created definition from a column specified with the GENERATED ALWAYS clause. Simply drop the calculation information and the column values will remain. IF EXISTS clause can be specified.

PDF page 37

Syntax

ALTER TABLE  table_name ALTER COLUMN  column_name DROP EXPRESSION
[IF EXISTS]
Example 29 ALTER TABLE DROP EXPRESSION statement
postgres=> CREATE TABLE gen1(c1 INT, c2 INT, c3 INT
GENERATED ALWAYS AS (c1 + c2) STORED) ;
CREATE TABLE
postgres=> \d gen1
                              Table "public.gen1"
 Column |  Type   | Collation | Nullable |               Default
--------+---------+-----------+----------+--------------------------
c1     | integer |           |          |
 c2     | integer |           |          |
 c3     | integer |           |          | generated always as (c1 + c2)
stored
postgres=> INSERT INTO gen1(c1, c2) VALUES (100, 200) ;
INSERT 0 1
postgres=> ALTER TABLE gen1 ALTER COLUMN c3
DROP EXPRESSION IF EXISTS ;
ALTER TABLE
postgres=> \d gen1
                Table "public.gen1"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 c1     | integer |           |          |
 c2     | integer |           |          |
 c3     | integer |           |          |
postgres=> SELECT * FROM gen1 ;
 c1  | c2  | c3
-----+-----+-----
 100 | 200 | 300
(1 row)

PDF page 38

ALTER TABLE ALTER COLUMN SET STORAGE

Alters to a column’s STORAGE attribute are now propagated to the index. This feature has been backported to the latest versions of PostgreSQL 12 and PostgreSQL 11.

Example 30 ALTER TABLE SET STORAGE statement
postgres=> CREATE TABLE attr1(c1 CHAR(10)) ;
CREATE TABLE
postgres=> \d+ attr1
                                      Table "public.attr1"
 Column |     Type      | Collation | Nullable | Default | Storage  | …
--------+-------------+-----------+----------+---------+----------+ …
 c1     | character(10) |            |            |           | extended | …
Access method: heap
postgres=> CREATE INDEX idx1_attr1 ON attr1(c1) ;
CREATE INDEX
postgres=> ALTER TABLE attr1 ALTER COLUMN c1 SET STORAGE EXTERNAL ;
ALTER TABLE
postgres=> \d+ idx1_attr1
                      Index "public.idx1_attr1"
 Column |     Type      | Key? | Definition | Storage  | Stats target
--------+-------------+------+------------+----------+--------------
 c1     | character(10) | yes | c1           | external |
btree, for table "public.attr1"

3.2.4 ALTER TYPE

In the ALTER TYPE statement, attributes can be changed using the SET clause. Syntax

ALTER TYPE type_name SET (attribute = value)

The attributes that can be changed are as follows. Part of the attributes that can be specified in the CREATE TYPE statement.

PDF page 39

Attribute nameDescription
RECEIVEThe function that converts external representation into an internal representation.
SENDThe function to convert from the internal representation to binary.
TYPMOD_INModifier support function.
TYPMOD_OUTModifier support function.
ANALYZEStatistics collection function.
STORAGEThe function that determines how to store variable-length data.
Table 20 Attributes that can be changed
Example 31 ALTER TYPE SET statement
postgres=# ALTER TYPE box SET (SEND = myboxsend) ;
ALTER TYPE

3.2.5 ALTER VIEW

Column names in views can now be changed. Execute an ALTER VIEW RENAME COLUMN statement. Syntax

ALTER VIEW view_name RENAME COLUMN old_name TO new_name

PDF page 40

Example 32 Rename view column name
postgres=> CREATE VIEW customer_name AS SELECT c_customer_id,
c_first_name || ',' || c_last_name c_full_name FROM customer ;
CREATE VIEW
postgres=> \d customer_name
                  View "public.customer_name"
    Column     |     Type      | Collation | Nullable | Default
---------------+---------------+-----------+----------+---------
 c_customer_id | character(16) |           |          |
 c_full_name   | text          |           |          |
postgres=> ALTER VIEW customer_name RENAME COLUMN c_full_name TO full_name ;
ALTER VIEW
postgres=> \d customer_name
                  View "public.customer_name"
    Column     |     Type      | Collation | Nullable | Default
---------------+---------------+-----------+----------+---------
 c_customer_id | character(16) |           |          |
 full_name     | text          |           |          |

3.2.6 CREATE DATABASE

The LOCALE clause can now be specified as an option in the CREATE DATABASE statement. It cannot be specified at the same time as LC_CTYPE clause or LC_COLLATE clause. Syntax

CREATE DATABASE database_name [[WITH] LOCALE [=] 'locale_name']

PDF page 41

Example 33 Specify LOCALE clause
postgres=# CREATE DATABASE localedb1 WITH LOCALE='ja_JP.eucjp' ENCODING='eucjp'
TEMPLATE=template0 ;
CREATE DATABASE
postgres=# \l localedb1
                                List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    | Access privileges
-----------+----------+----------+-------------+-------------+-----------------
 localedb1 | postgres | EUC_JP   | ja_JP.eucjp | ja_JP.eucjp |
(1 row)

3.2.7 CREATE INDEX

In-page deduplication has been added to the B-Tree index. This feature is enabled by default. To disable this feature, set the deduplicate_items attribute to ‘off’.

Example 34 B-Tree index deduplication
postgres=> CREATE TABLE data1(c1 INT, c2 VARCHAR(10), c3 VARCHAR(10)) ;
CREATE TABLE
postgres=> INSERT INTO data1 VALUES (generate_series(1, 1000000),
'data1', 'data1') ;
INSERT 0 1000000
postgres=> CREATE INDEX idx1_dup ON data1(c2)
WITH (deduplicate_items = off) ;
CREATE INDEX
postgres=> CREATE INDEX idx2_dedup ON data1(c3)
WITH (deduplicate_items = on) ;
CREATE INDEX
postgres=> \d+ idx1_dup
                           Index "public.idx1_dup"
 Column |         Type          | Key? | Definition | Storage  | Stats target
--------+-----------------------+------+------------+----------+--
 c2     | character varying(10) | yes  | c2         | extended |
btree, for table "public.data1"
Options: deduplicate_items=off

PDF page 42

Example 35 Effect of index deduplication
postgres=> SELECT pg_size_pretty(pg_relation_size('idx1_dup')) ;
 pg_size_pretty
----------------
 21 MB
(1 row)
postgres=> SELECT pg_size_pretty(pg_relation_size('idx2_dedup')) ;
 pg_size_pretty
----------------
 6792 kB
(1 row)

3.2.8 CREATE TABLE

Some attributes4 can be specified in the CREATE TABLE/ALTER TABLE statement.

Example 36 Specifying additional attributes for tables
postgres=> CREATE TABLE data1(c1 NUMERIC, c2 VARCHAR(10)) ;
CREATE TABLE
postgres=> ALTER TABLE data1 SET (toast.vacuum_index_cleanup = off) ;
ALTER TABLE
postgres=> ALTER TABLE data1 SET (autovacuum_vacuum_insert_threshold = 10000) ;
ALTER TABLE
postgres=> ALTER TABLE data1 SET (autovacuum_vacuum_insert_scale_factor =
0.1) ;
ALTER TABLE

3.2.9 CREATE TABLESPACE

Maintenance_io_concurrency5 can now be specified for tablespace attributes.

4 See 3.3.1 Added parameters 5 See 3.3.1 Added parameters

PDF page 43

Example 37 Specify maintenance_io_concurrency attribute
postgres=# CREATE TABLESPACE ts1 LOCATION '/home/postgres/ts1'
WITH (maintenance_io_concurrency = 20) ;
CREATE TABLESPACE
postgres=# ALTER TABLESPACE ts1 SET (maintenance_io_concurrency = 30) ;
ALTER TABLESPACE
postgres=# \db+ ts1
                                                List of tablespaces
 Name |  Owner   |      Location      | Access privileges |             Options
|  Size   | Description
------+----------+--------------------+-------------------+--------------
-------------------+---------+-------------
 ts1  | postgres | /home/postgres/ts1 |                   |
{maintenance_io_concurrency=30} | 0 bytes |
(1 row)

3.2.10 DROP DATABASE FORCE

The database can now be forcibly dropped even if there are connected session exists. The connected session is forcibly closed. The database to which the session issuing the DROP DATABASE statement is connected cannot be dropped. Syntax

DROP DATABASE database_name [[WITH] (FORCE)]
Example 38 DROP DATABASE statement
postgres=# DROP DATABASE demodb WITH (FORCE) ;
DROP DATABASE
postgres=# DROP DATABASE postgres WITH (FORCE) ;
ERROR:  cannot drop the currently open database

3.2.11 EXPLAIN ANALYZE

The following extensions have been implemented in the EXPLAIN ANALYZE statement.

PDF page 44

The output of cache information

By specifying BUFFERS, the status of the shared buffer when creating an execution plan is now output.

Example 39 EXPLAIN (ANALYZE, BUFFERS) statement
postgres=> EXPLAIN (ANALYZE, BUFFERS) SELECT * FROM data1 WHERE c1
= 10000 ;
                                   QUERY PLAN
-----------------------------------------------------------------
Index Scan using idx1_data1 on data1  (cost=0.42..8.44 rows=1
width=16) (actual time=0.029..0.030 rows=1 loops=1)
   Index Cond: (c1 = 10000)
   Buffers: shared hit=1 read=3
 Planning:
   Buffers: shared hit=17 read=1
 Planning Time: 1.380 ms
 Execution Time: 0.044 ms
(7 rows)
If ANALYZE clause is not specified, the planner's buffer usage is output.
Example 40 EXPLAIN (BUFFERS) statement
postgres=> EXPLAIN (BUFFERS) SELECT * FROM data1 WHERE c1=100 ;
                                QUERY PLAN
-----------------------------------------------------------------
 Index Scan using idx1_data1 on data1  (cost=0.43..19.68 rows=4
width=16)
   Index Cond: (c1 = 100)
 Planning:
   Buffers: shared hit=93 read=3
(4 rows)
Output sort information

The output of the EXPLAIN ANALYZE statement when executing a parallel query has changed. JIT function information is now output for each worker. Also, the output of sort information has changed.

PDF page 45

Example 41 Output of the EXPLAIN ANALYZE statement (JIT)
postgres=> EXPLAIN (ANALYZE, VERBOSE) SELECT * FROM data1 WHERE c1 < 10000 ;
                                                             QUERY PLAN
-----------------------------------------------------------------------------
 Gather
(cost=0.00..107056.40
rows=9188
width=12)
(actual
time=12.326..410.535 rows=9999 loops=1)
   Output: c1, c2
   Workers Planned: 2
   Workers Launched: 2
   ->  Parallel Seq Scan on public.data1  (cost=0.00..106137.60 rows=3828
width=12) (actual time=228.802..360.446 rows=3333 loops=3)
         Output: c1, c2
         Filter: (data1.c1 < '10000'::numeric)
         Rows Removed by Filter: 3330000
         Worker 0:  actual time=330.989..330.989 rows=0 loops=1
           JIT:
             Functions: 2
             Options: Inlining false, Optimization false, Expressions true,
Deforming true
             Timing: Generation 2.370 ms, Inlining 0.000 ms, Optimization 1.562
ms, Emission 25.957 ms, Total 29.889 ms
         Worker 1:  actual time=343.317..343.317 rows=0 loops=1
           JIT:
             Functions: 2
             Options: Inlining false, Optimization false, Expressions true,
Deforming true
             Timing: Generation 1.655 ms, Inlining 0.000 ms, Optimization 1.265
ms, Emission 18.974 ms, Total 21.894 ms
…

PDF page 46

Example 42 Output of the EXPLAIN ANALYZE statement (Sort)
postgres=> EXPLAIN (ANALYZE, VERBOSE) SELECT * FROM data1 ORDER BY c1 ;
                                                                  QUERY PLAN
----------------------------------------------------------------------------
Gather Merge  (cost=752323.83..1726047.95 rows=8345624 width=12) (actual
time=1471.139..4003.430 rows=10000000 loops=1)
   Output: c1, c2
   Workers Planned: 2
   Workers Launched: 2
   ->  Sort  (cost=751323.81..761755.84 rows=4172812 width=12) (actual
time=1328.103..1849.320 rows=3333333 loops=3)
         Output: c1, c2
         Sort Key: data1.c1
         Sort Method: external merge  Disk: 74864kB
         Worker 0:  actual time=1466.829..1989.939 rows=3335746 loops=1
           Sort Method: external merge  Disk: 75096kB
         Worker 1:  actual time=1360.627..1885.937 rows=3338879 loops=1
           Sort Method: external merge  Disk: 75168kB
         ->  Parallel Seq Scan on public.data1  (cost=0.00..149837.12
rows=4172812 width=12) (actual time=60.222..279.624 rows=3333333 loops=3)
               Output: c1, c2
               Worker 0:  actual time=58.974..280.404 rows=3335746 loops=1
               Worker 1:  actual time=58.948..277.968 rows=3338879 loops=1
 Planning Time: 0.056 ms
 Execution Time: 4261.051 ms
(18 rows)
The output of WAL information

If the WAL option is specified in the EXPLAIN ANALYZE statement, the generated WAL information will be output.

PDF page 47

Example 43 EXPLAIN (ANALYZE, WAL) statement
postgres=> EXPLAIN (ANALYZE, WAL) DELETE FROM data1 WHERE c1 = 20000 ;
                                                QUERY PLAN
--------------------------------------------------------------------
Delete on data1  (cost=0.00..17906.00 rows=1 width=6) (actual
time=56.817..56.818 rows=0 loops=1)
   WAL: records=2 fpi=1 bytes=8237
   ->  Seq Scan on data1  (cost=0.00..17906.00 rows=1 width=6) (actual
time=1.269..56.800 rows=1 loops=1)
         Filter: (c1 = 20001)
         Rows Removed by Filter: 999998
         WAL: records=1 fpi=1 bytes=8183
 Planning Time: 0.085 ms
 Execution Time: 56.843 ms
(8 rows)

3.2.12 INSERT

Specifying a value using the INSERT OVERRIDING USER VALUE statement for an IDENTITY column with the GENERATED ALWAYS clause specified is now allowed. However, the value specified for the IDENTITY column is ignored.

Example 44 INSERT OVERRIDING USER VALUE statement
postgres=> CREATE TABLE gen1(c1 INT GENERATED ALWAYS AS IDENTITY,
c2 VARCHAR(10)) ;
CREATE TABLE
postgres=> INSERT INTO gen1 OVERRIDING USER VALUE VALUES
(100, 'data1') ;
INSERT 0 1
postgres=> SELECT * FROM gen1 ;
 c1 |  c2
----+-------
  1 | data1
(1 row)

PDF page 48

3.2.13 JSON

The following JSON related features have been added.

Allow Unicode escape

Unicode escapes are now allowed for character literals and identifiers, even if the server’s character encoding is not UTF-8.

Datetime method of jsonpath

The datetime method that converts a character string to a date/time type has been added.

Example 45 datetime method
postgres=> SELECT
jsonb_path_query('"27-09-2020"', '$.datetime("dd-mm-yyyy")') ;
 jsonb_path_query
------------------
 "2020-09-27"
(1 row)

3.2.14 MAX/MIN pg_lsn

MAX / MIN function can be used for pg_lsn data type.

Example 46 MAX(pg_lsn) function
postgres=# SELECT MIN(flush_lsn), MAX(flush_lsn)
FROM pg_stat_replication ;
    min    |    max
-----------+-----------
 0/94FD1E0 | 0/94FD1E0
(1 row)

3.2.15 ROW

ROW can now be directly extracted fields in some data types from the expressions.

PDF page 49

Example 47 Extracting values from ROW expressions
postgres=> SELECT (ROW(2, 3.1)).f1, (ROW(4, 5.1)).f2 ;
f1 | f2
----+-----
  2 | 5.1
(1 row)

3.2.16 SELECT FETCH FIRST WITH TIES

The WITH TIES clause can be specified in the SELECT FETCH FIRST statement. It outputs the same number of tuples as the number of tuples specified in the ROWS clause.

Example 48 SELECT FETCH FIRST WITH TIES statement
postgres=> SELECT * FROM data1 WHERE c1 < 4 ORDER BY c1
FETCH FIRST 2 ROWS ONLY ;
 c1 |  c2
----+-------
  1 | data1
  1 | data1
(2 rows)
postgres=> SELECT * FROM data1 WHERE c1 < 4 ORDER BY c1
FETCH FIRST 2 ROWS WITH TIES ;
 c1 |  c2
----+-------
  1 | data1
  1 | data1
  1 | data1
(3 rows)

3.2.17 VACUUM PARALLEL

VACUUM statements for indexes can now be parallelized. Parallelism works by default, and the degree of parallelism is determined by the number of indexes created on the table. To specify the degree of parallelism, specify a value between 0 and 1024 in the PARALLEL clause. This feature does not work with automatic VACUUM.

PDF page 50

Example 49 PARALLEL specification of VACUUM statement
postgres=> VACUUM (PARALLEL 4, VERBOSE) data1 ;
INFO:  vacuuming "public.data1"
INFO:  launched 2 parallel vacuum workers for index vacuuming (planned: 2)
INFO:  scanned index "idx3_data1" to remove 1000 row versions by parallel
vacuum worker
DETAIL:  CPU: user: 0.39 s, system: 0.11 s, elapsed: 12.45 s
INFO:  scanned index "idx2_data1" to remove 1000 row versions by parallel
vacuum worker
DETAIL:  CPU: user: 0.39 s, system: 0.12 s, elapsed: 12.56 s
INFO:  scanned index "idx1_data1" to remove 1000 row versions
DETAIL:  CPU: user: 0.47 s, system: 0.17 s, elapsed: 53.26 s
INFO:  "data1": removed 1000 row versions in 1000 pages
…

3.2.18 Operator <->

Distance operators (<->) can now be used between several data types. GiST index and SP-GiST index can be used in box_ops operator class.

Example 50 Operator &lt;-&gt;
postgres=> CREATE TABLE point_tbl(f1 point) ;
CREATE TABLE
postgres=> CREATE TABLE box_tbl(f1 box) ;
CREATE TABLE
postgres=> SELECT p.f1, b.f1, p.f1 <-> b.f1 AS dist_pb,
b.f1 <-> p.f1 AS dist_bp FROM point_tbl p, box_tbl b ;
f1 | f1 | dist_pb | dist_bp
----+----+---------+---------
(0 rows)

3.2.19 Functions

The following functions have been added/enhanced.

PDF page 51

Gen_random_uuid

The gen_random_uuid function has been provided to generate a random UUID.

Example 51 gen_random_uuid function
postgres=> SELECT gen_random_uuid() ;
           gen_random_uuid
--------------------------------------
 3759712a-e7f6-4348-b62c-85535c831e7e
(1 row)
Date format

FF1 to FF6 format patterns defined in SQL Standard 2016 have been added to the date format.

Example 52 Date format
postgres=> SELECT TO_CHAR(current_timestamp, 'HH:MI:SS.FF6') ;
     to_char
-----------------
 01:39:56.077670
(1 row)
PatternOutput valueNote
FF11/10th of a second.
FF21/100 second.
FF3Millisecond .
FF41/10 ms.
FF51/100 ms.
FF6Microsecond .
Table 21 Added format pattern

The pattern SSSSS is now an alias for SSSS.

Min_scale, trim_scale

The min_scale function obtains the minimum number of digits from the NUMERIC type, excluding trailing zeros after the decimal point. The trim_scale function gets the value of the NUMERIC type excluding trailing zeros after the decimal point.

PDF page 52

Example 53 min_scale, trim_scale function
postgres=> SELECT trim_scale(1.234000::numeric),
min_scale(1.234000::numeric) ;
 trim_scale | min_scale
------------+-----------
      1.234 |         3
(1 row)
Jsonb_set_lax

The jsonb_set_lax function is the same as the jsonb_set function except that a null_value_treatment parameter (text type) has been added. The following values can be specified for this parameter.

ValueDescriptionNote
use_json_nullraise_exceptiondelete_keyreturn_targetReturn NULL. Raise exception. Delete key. Return target.default value
Table 22 null_value_treatment parameter value
Example 54 jsonb_set_lax function
postgres=> SELECT
jsonb_set_lax('[{"f1":1,"f2":null},2,null,3]',
'{0,f1}', null) ;
             jsonb_set_lax
----------------------------------------
 [{"f1": null, "f2": null}, 2, null, 3]
(1 row)
Gcd, lcm

The lcm function, which returns the least common multiple, and the gcd function, which returns the greatest common divisor, have been added. Specify two numbers of the same type in the parameter. If both parameters are 0, these functions return 0.

PDF page 53

Example 55 gcd, lcm function
postgres=> SELECT gcd(1071, 462), lcm(1071, 46) ;
 gcd |  lcm
-----+-------
  21 | 49266
(1 row)
Get_bit / set_bit

The offset parameter of the get_bit / set_bit function that specifies the bytea type has been changed from integer type to bigint type.

Unicode normalization

The normalize function that performs UNICODE normalization and the ‘is_normalized’ function that checks whether it is normalized has been implemented. You can also use the ‘is normalized’ syntax to check the specified text. Syntax

text is [not] [form] normalized

In the [form] part, NFC (default), NFD, NFKC, or NFKD can be specified.

Example 56 is normalized syntax
postgres=> SELECT '㋿' IS NFKD NORMALIZED ;
 is_normalized
---------------
 f
(1 row)
postgres=> SELECT normalize('㋿', NFKD) ;
 normalize
-----------
 令和
(1 row)

PDF page 54

Pg_stat_reset_slru

This function resets the counter value in the pg_stat_slru catalog. If NULL is specified for the parameter of this function, all counters will be reset. By specifying the counter name (’name’ column of pg_stat_slru catalog) to this function, the specified counter is reset.

Example 57 is normalized syntax
postgres=# SELECT pg_stat_reset_slru('subtrans') ;
pg_stat_reset_slru
--------------------
(1 row)

5 Configuration Parameters

Added, modified, removed, and default-value changes for configuration parameters.
GASource pages: PDF 55-58Original PDF on GitHub

PDF page 55

In PostgreSQL 13 the following parameters have been changed.

3.3.1 Added parameters

The following parameters have been added.

Parameter nameDescription (context)Default Val
autovacuum_vacuum_Percentage of INSERT records for which automatic0.2
insert_scale_factorVACUUM is executed (sighup).
autovacuum_vacuum_insert_thresholdNumber of INSERT records for which automatic VACUUM is executed (sighup).1000
backtrace_functionsList of function names that output backtrace when an error occurs (superuser).''
enable_incremental_sortEnable incremental sorting (user).on
hash_mem_multiplierUsed to compute the maximum amount of memory that hash-based operations can use (user).1
ignore_invalid_pagesIgnore invalid page references during recovery (postmaster) .off
log_min_duration_sampleTime to output SQL statement log by sampling (superuser) .-1
log_parameter_max_lengthBind parameter value in the non-error statement logging messages are trimmed to setting value (superuser).-1
log_parameter_max_length_on_errorBind parameter value in the error statement logging messages are trimmed to setting value (user).0
log_statement_sample_rateSQL statement log output rate by sampling (superuser)1.0
logical_decoding_work_memWork memory for decoding for the logical replication environment (user).64MB
maintenance_io_concurrencyNumber of I/O concurrent executions used for maintenance (user).10
max_slot_wal_keep_sizeThe maximum MB size of WAL is held by the replication slot (sighup).-1
wal_receiver_create_temp_slotWhether the wal receiver process creates a temporary replication slot (sighup).off
wal_skip_thresholdWrite the interval at which fsync is executed when wal_level is ‘minimal’ (user).2MB
Table 23 Added parameters

PDF page 56

Output backtrace

In the parameter backtrace_functions, specify the name of the function that performs trace output when an error occurs. The specified function is not the SQL function, but the function name in the source code.

PDF page 57

Example 58 backtrace_functions parameter
postgres=# SET backtrace_functions = 'pg_strtoint32' ;
SET
postgres=# SELECT int 'foobar' ;
ERROR:  invalid input syntax for type integer: "foobar"
LINE 1: SELECT int 'foobar' ;
postgres=# \q
$ tail data/log/postgresql.log
2020-09-24 18:36:42.452 JST [2532] BACKTRACE:
        postgres: postgres postgres [local] SELECT() [0x807d2e]
        postgres: postgres postgres [local] SELECT(int4in+0xd) [0x7d27ad]
        postgres: postgres postgres [local] SELECT(InputFunctionCall+0x67)
[0x884d27]
        postgres: postgres postgres [local] SELECT(OidInputFunctionCall+0x31)
[0x884f31]
        postgres:
postgres
postgres
[local]
SELECT(coerce_type+0x361)
[0x5785f1]
        postgres: postgres postgres [local] SELECT(coerce_to_target_type+0x9b)
[0x577d8b]
…
        postgres:
postgres
postgres
[local]
SELECT(parse_analyze+0x4f)
[0x55874f]
        postgres:
postgres
postgres
[local]
SELECT(pg_analyze_and_rewrite+0x13) [0x76ffa3]
        postgres: postgres postgres [local] SELECT() [0x770483]
        postgres:
postgres
postgres
[local]
SELECT(PostgresMain+0x1037)
[0x7718f7]
        postgres: postgres postgres [local] SELECT() [0x483e46]
        postgres:
postgres
postgres
[local]
SELECT(PostmasterMain+0xe88)
[0x6ff668]
        postgres: postgres postgres [local] SELECT(main+0x46a) [0x484a9a]
        /lib64/libc.so.6(__libc_start_main+0xf5) [0x7f19383693d5]
        postgres: postgres postgres [local] SELECT() [0x484b01]
2020-09-24 18:36:42.452 JST [2532] STATEMENT:  SELECT int 'foobar' ;

PDF page 58

3.3.2 Changed parameters

The setting range and options were changed for the following configuration parameters.

Parameter nameChanges
allow_system_table_modsThe context changed from postmaster to superuser.
effective_io_concurrencyChanged to use directly specified value instead of using calculated value by the internal logic.
log_line_prefixBackend type (%b) has been added.
log_min_duration_statementThe short_desc column value in the pg_settings view has changed.
max_files_per_processThe minimum value has been changed from 25 to 64.
primary_conninfoContext changed from postmaster to sighup.
primary_slot_nameContext changed from postmaster to sighup.
ssl_passphrase_commandOnly SUPERUSER can be referenced.
track_activity_query_sizeThe maximum value has been changed from 102,400 to 1,048,576.
wal_keep_sizeChanged name from wal_keep_segments. Units have been changed from number of the files to size.
Table 24 Changed parameters

3.3.3 Parameters with default values changed

The following parameters have changed default values.

ParameternamePostgreSQL12PostgreSQL13Note
server_version12.413.0
server_version_num120004130000
ssl_min_protocol_versionTLSv1TLSv1.2
Table 25 Parameters that default value has been changed

6 Utilities

Changes to configure, initdb, backup, restore, upgrade, psql, and maintenance tools.
GASource pages: PDF 59-69Original PDF on GitHub

PDF page 59

Describes the major enhancements of utility commands.

3.4.1 dropdb

The –force option (or -f option) has been added. Forces database deletion even if a connection session exists. The connected session will be closed.

Example 59 dropdb --force option
$ dropdb --force --echo demodb
SELECT pg_catalog.set_config('search_path', '', false);
DROP DATABASE demodb WITH (FORCE);

3.4.2 pg_basebackup

The following enhancements have been implemented in the pg_basebackup command.

–manifest-checksums option

Specify the algorithm for creating the checksum. The options that can be specified are CRC32C, SHA224, SHA256, SHA384, SHA512, or NONE. The default value is CRC32C. If NONE is specified, the manifest will not include the checksum.

–manifest-force-encode option

Outputs the file name to be written to the manifest in hexadecimal. By default, only non-UTF-8 file names are represented in hexadecimal.

–no-estimate-size option

The pg_basebackup command has been changed to estimate the data size without specifying the -progress option. Specify the option –no-estimate-size when not calculating the data amount estimate. This option cannot be used with –progress.

PDF page 60

Example 60 pg_basebackup ---no-estimate-size option
$ pg_basebackup --verbose --no-estimate-size -D back
pg_basebackup: initiating base backup, waiting for checkpoint to complete
pg_basebackup: checkpoint completed
pg_basebackup: write-ahead log start point: 1/44000028 on timeline 1
pg_basebackup: starting background WAL receiver
pg_basebackup: created temporary replication slot "pg_basebackup_3822"
pg_basebackup: write-ahead log end point: 1/44000138
pg_basebackup: waiting for background process to finish streaming ...
pg_basebackup: syncing data to disk ...
pg_basebackup: renaming backup_manifest.tmp to backup_manifest
pg_basebackup: base backup completed
–no-manifest option

Disables generation of a backup manifest.

–no-verify-checksums option

Do not verify checksums.

3.4.3 pg_dump

The following enhancements have been implemented in the pg_dump command.

–include-foreign-data option

Added –include-foreign-data option to dump FOREIGN SERVER data. This option specifies the FOREIGN SERVER name pattern. This option can be specified more than once.

PDF page 61

Example 61 pg_dump --include-foreign-data option
$ pg_dump -d demodb --include-foreign-data=svr1
--
-- PostgreSQL database dump
…
CREATE FOREIGN TABLE public.foreign1 (
    c1 numeric,
    c2 character varying(10)
)
SERVER svr1;
…
--
-- Data for Name: data1; Type: TABLE DATA; Schema: public; Owner:
demo
--
COPY public.foreign1 (c1, c2) FROM stdin;
100     data1
\.
…
Output ALTER DEPEND ON EXTENSION statement

ALTER object DEPENDS ON EXTENSION statement is now output.

Example 62 ALTER DEPENDS ON EXTENSION statement
$ pg_dump -d demodb | grep EXTENSION
-- Name: cube; Type: EXTENSION; Schema: -; Owner: -
CREATE EXTENSION IF NOT EXISTS cube WITH SCHEMA public;
-- Name: EXTENSION cube; Type: COMMENT; Schema: -; Owner:
COMMENT ON EXTENSION cube IS 'data type for multidimensional
cubes';
ALTER FUNCTION public.func1() DEPENDS ON EXTENSION cube;
$

PDF page 62

3.4.4 pg_rewind

The following three options have been added to the pg_rewind command.

–no-ensure-shutdown option

The pg_rewind will start in single-user mode if it detects a database cluster that has not shut down properly. Specify the –no-ensure-shutdown command and do not perform startup processing.

–write-recovery-conf option

The –write-recovery-conf option (or -R option) configures replication-related settings. This option must be specified with the –source-server option.

–restore-target-wal option

The –restore-target-wal option (or -c option) gets the restore_command parameter value from the target cluster and restores the required WAL segments from the archive.

PDF page 63

Example 63 pg_rewind command
$ pg_rewind --help
pg_rewind resynchronizes a PostgreSQL cluster with another copy of the
cluster.
Usage:
  pg_rewind [OPTION]...
Options:
  -c, --restore-target-wal       use restore_command in target
configuration to
                                 retrieve WAL files from archives
  -D, --target-pgdata=DIRECTORY  existing data directory to modify
      --source-pgdata=DIRECTORY  source data directory to synchronize with
      --source-server=CONNSTR    source server to synchronize with
  -n, --dry-run                  stop before modifying anything
  -N, --no-sync                  do not wait for changes to be written
                                 safely to disk
  -P, --progress                 write progress messages
  -R, --write-recovery-conf      write configuration for replication
                                 (requires --source-server)
      --debug                    write a lot of debug messages
      --no-ensure-shutdown       do not automatically fix unclean shutdown
  -V, --version                  output version information, then exit
  -?, --help                     show this help, then exit
Report bugs to <pgsql-bugs@lists.postgresql.org>.
PostgreSQL home page: <https://www.postgresql.org/>

3.4.5 pg_verifybackup

The pg_verifybackup command checks consistency by comparing the contents of the backup and the manifest. This command performs the following checks:

  • Manifest file version

  • The checksum of the manifest file itself

  • File size

PDF page 64

  • File checksum

  • WAL file integrity Syntax

pg_verifybackup [options] directory
Long OptionShort OptionDescription
–exit-on-error-eExit immediately on error.
–ignore=PATH-iIgnore the indicated path.
–manifest-path=PATH-mUse a specified path for the manifest.
–no-parse-wal-nDo not try to parse WAL files.
–quiet-qDo not print any output, except for errors.
–skip-checksums-sSkip checksum verification.
–wal-directory=PATH-wUse the specified path for WAL files.
–version-VOutput version information.
–help-?Output usage information.
Table 26 pg_verifybackup command option
Example 64 pg_verifybackup command
$ pg_basebackup -D back
$ pg_verifybackup back
backup successfully verified
$ echo $?
0
Validation error

The pg_verifybackup command outputs an error message if the size or content of the file has changed.

PDF page 65

Example 65 pg_verifybackup command with error
$ pg_basebackup -D back
$ vi back/postgresql.conf
$ vi back/pg_hba.conf
$ pg_verifybackup back
pg_verifybackup: error: "pg_hba.conf" has size 4761 on disk but
size 4760 in the manifest
pg_verifybackup:
error:
checksum
mismatch
for
file
"postgresql.conf"
$
Execution error

An error occurs when executing a backup for which a manifest has not been created or a backup created in tar format.

Example 66 pg_verifybackup command with error
$ pg_basebackup -D back --no-manifest
$ pg_verifybackup back
pg_verifybackup:
fatal:
could
not
open
file
"back/backup_manifest": No such file or directory
$ rm -r back
$ pg_basebackup -D back -Ft
$ pg_verifybackup back
pg_verifybackup: error: "base.tar" is present on disk but not in
the manifest
pg_verifybackup: error: "pg_wal.tar" is present on disk but not in
the manifest
pg_verifybackup: error: "base/13577/3433" is present in the
manifest but not on disk
…
Try "pg_waldump --help" for more information.
pg_verifybackup: error: WAL parsing failed for timeline 1
$

PDF page 66

3.4.6 pg_waldump

The –quiet option (or -q option) has been added to the pg_waldump command. This option suppresses non-error screen output.

3.4.7 psql

The following features have been added to the psql command.

\dAc, \dAf, \dAo, \dAp commands

Commands for outputting operator information have been added.

CommandOutput contentsNote
\dAcAM, Input type, Storage type, Operator class, Default?.
\aAfAM, Operator family, Applicable types
\dAoAM, Operator family, Operator, Strategy, Purpose
\dApAM, Operator family, Registered left type, Registered right type, Number, Function
Table 27 Added command
Example 67 \dAc command
postgres=> \dAc
                                List of operator classes
   AM   |         Input type          | Storage type |     Operator class     | Default?
--------+-----------------------------+--------------+------------------------+------
 brin   | "char"                      |              | char_minmax_ops        | yes
 brin   | anyrange                    |              | range_inclusion_ops    | yes
 brin   | bigint                      |              | int8_minmax_ops        | yes
 brin   | bit                         |              | bit_minmax_ops         | yes
 brin   | bit varying                 |              | varbit_minmax_ops      | yes
 brin   | box                         |              | box_inclusion_ops      | yes
 brin   | bytea                       |              | bytea_minmax_ops       | yes
 brin   | character                   |              | bpchar_minmax_ops      | yes
 brin   | date                        |              | date_minmax_ops        | yes
 brin   | double precision            |              | float8_minmax_ops      | yes
…

PDF page 67

\g, \gx commands

The feature has been added to the \g and \gx commands to temporarily change variables specified by the \pset command.

Example 68 \g command
postgres=> SELECT * FROM data1 WHERE c1=10 ;
 c1 |  c2
----+-------
 10 | data1
 10 | data1
10 | data1
(3 rows)
postgres=> \g (format=csv)
c1,c2
10,data1
10,data1
10,data1
\warn command

The \warn command that outputs a message to standard error has been added.

Example 69 \warn command
postgres=> \warn `date`
Thu Sep 24 21:10:09 JST 2020
\e command

After closing the editor, the edited SQL statement is now displayed.

Example 70 \e command
postgres=> \e
postgres=> SELECT * FROM data1
postgres->

PDF page 68

\d+ command

The table type is now output as a ‘Persistence’ column.

Example 71 \d command
postgres=> \d+
                                     List of relations
  Schema   |        Name        | Type  |  Owner   | Persistence |    Size    | Description
-----------+--------------------+-------+----------+-------------+------------+------
 pg_temp_3 | temp1              | table | demo     | temporary   | 8192 bytes |
 public    | data1              | table | demo     | permanent   | 42 MB      |
public    | unlogged1          | table | demo     | unlogged    | 16 kB      |
(3 rows)
PROMPT2 value

Variable PROMPT2 now a %w can be specified. If this value is specified, it will be converted to a space of the same length as PROMPT1.

Example 72 PROMPT2 variable value
postgres=> \set PROMPT2 '>%w'
postgres=> CREATE TABLE data1(c1 INT, c2 VARCHAR(10))
>           TABLESPACE pg_default ;
CREATE TABLE
I/O error detection

Errors when outputting files can now be detected.

The default value of PROMPT1/PROMPT2
The default prompt now includes %x to indicate transaction status.6。

3.4.8 reindexdb

The –jobs option to execute parallel processing has been added to the reindexdb command. The default value is 1 and no parallel processing is performed.

6 Refer 2.5.7 Psql default prompt psql

PDF page 69

Example 73 reindexdb --jobs option
$ reindexdb --concurrently --jobs 2 postgres
reindexdb: warning: cannot reindex system catalogs concurrently,
skipping all

3.4.9 vacuumdb

The –parallel option (or -P option) has been added. Specify the degree of parallelism (0 to 1024) in the option. This option cannot be specified together with the –full or –analyze-only option.

Example 74 vacuumdb --parallel option
$ vacuumdb --parallel=4 postgres
vacuumdb: vacuuming database "postgres"

3.4.10 Other

The URL to www.postgresql.org has been added to the output of the –help option for many commands.

Example 75 --help option
$ pg_controldata --help
pg_controldata displays control information of a PostgreSQL database cluster.
Usage:
  pg_controldata [OPTION] [DATADIR]
Options:
 [-D, --pgdata=]DATADIR  data directory
  -V, --version          output version information, then exit
  -?, --help             show this help, then exit
If no data directory (DATADIR) is specified, the environment variable PGDATA
is used.
Report bugs to <pgsql-bugs@lists.postgresql.org>.
PostgreSQL home page: <https://www.postgresql.org/>

7 Contrib Modules

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

PDF page 70

Describe new features related to the Contrib modules.

3.5.1 adminpack

The pg_file_sync function has been added to the extension adminpack. This function guarantees a reliable write to the specified file or directory.

Example 76 pg_file_sync function
postgres=# CREATE EXTENSION adminpack ;
CREATE EXTENSION
postgres=# SELECT
pg_file_sync('postgresql-2020-09-24_120622.log') ;
 pg_file_sync
--------------
(1 row)

3.5.2 auto_explain

The log_wal parameter to output WAL information has been added to the extension auto_explain. The default value is ‘off’, and WAL information is not output. If this parameter is set to ‘on’, auto_explain.log_analyze must also be set to ‘on’.

PDF page 71

Example 77 log_wal parameter
postgres=# LOAD 'auto_explain' ;
LOAD
postgres=# SET auto_explain.log_wal = on ;
SET
postgres=# SET auto_explain.log_analyze = on ;
SET
postgres=# SET auto_explain.log_min_duration = 0 ;
SET
postgres=# DELETE FROM data1 WHERE c1=100 ;
DELETE 1
postgres=# \! tail -7 log/postgres.log
2020-09-24 21:16:28.707 JST [4731] LOG:  duration: 0.064 ms  plan:
        Query Text: DELETE FROM data1 WHERE c1=100 ;
        Delete on data1  (cost=0.00..4.50 rows=2 width=6) (actual
time=0.063..0.063 rows=0 loops=1)
          WAL: records=2 fpi=2 bytes=8966
          ->  Seq Scan on data1  (cost=0.00..4.50 rows=2 width=6) (actual
time=0.018..0.026 rows=2 loops=1)
                Filter: (c1 = '100'::numeric)
                Rows Removed by Filter: 198

3.5.3 dict_int

The dict_int extension now has an ABSVAL attribute. If this attribute is specified, the sign specified for the integer value will be ignored.

PDF page 72

Example 78 ABSVAL attribute
postgres=# CREATE EXTENSION dict_int ;
CREATE EXTENSION
postgres=# ALTER TEXT SEARCH DICTIONARY intdict (ABSVAL = true) ;
ALTER TEXT SEARCH DICTIONARY
postgres=# \dFd+ intdict
                            List of text search dictionaries
 Schema |  Name   |        Template         |  Init options   |       Description
--------+---------+-------------------------+-----------------+-------------
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=806eb92c018102da9514443ad19160
 public | intdict | public.intdict_template | absval = 'true' | dictionary
c7b1841062
for integers
(1 row)

3.5.4 ltree

The ltree, lquery, and ltxtquery types now support binary I/O.

Example 79 information on the ltree data type
postgres=> SELECT typreceive, typsend FROM pg_type WHERE typname='ltree' ;
-[ RECORD 1 ]----------
typreceive | ltree_recv
typsend    | ltree_send

3.5.5 pageinspect

The following enhancements have been implemented in pageinspect extension.

Heap_tuple_infomask_flags function

This function converts the values of t_infomask, t_infomask2 into a human-readable form.

PDF page 73

Example 80 heap_tuple_infomask_flags function
postgres=# SELECT t_infomask, t_infomask2, raw_flags, combined_flags
               FROM heap_page_items(get_raw_page('data1', 0)),
               LATERAL heap_tuple_infomask_flags(t_infomask, t_infomask2)
               m(raw_flags, combined_flags) ;
-[ RECORD 1 ]--+---------------------------------------------------------
t_infomask     | 2306
t_infomask2    | 2
raw_flags      | {HEAP_HASVARWIDTH,HEAP_XMIN_COMMITTED,HEAP_XMAX_INVALID}
combined_flags | {}
Bt_metap function

An allequalimage column has been added to the output of the bt_metap function to indicate the status of duplicate data in the index.

Example 81 Output of bt_metap function
postgres=# SELECT * FROM bt_metap('idx1_data1') ;
-[ RECORD 1 ]-----------+-------
magic                   | 340322
version                 | 4
root                    | 3
level                   | 1
fastroot                | 3
fastlevel               | 1
oldest_xact             | 0
last_cleanup_num_tuples | -1
allequalimage           | t
Bt_page_items function

The dead, htid, and tids columns have been added to the output of the bt_page_items function.

PDF page 74

Example 82 Output of bt_page_items function
postgres=# SELECT * FROM bt_page_items('idx1_data1', 1) ;
-[ RECORD 1 ]-----------------------
itemoffset | 1
ctid       | (0,1)
itemlen    | 16
nulls      | f
vars       | t
data       | 0b 00 80 01 00 00 00 00
dead       | f
htid       | (0,101)
tids       |
Column nameDescription
deadA boolean value indicating the value of the LP_DEAD bit.
htidIndicates a single heap TID value for each tuple.
tidsAn array of TID.
Table 28 Added columns

3.5.6 pg_stat_statements

The features to output execution plan and WAL information have been added to the pg_stat_statements extension.

Track_planning parameter

This parameter specifies whether to track the execution plan. The default value is ‘off’. If this parameter is specified, information about the execution plan will be added to the pg_stat_statements view.

Pg_stat_statements view

The following columns have been added to the pg_stat_statements view:

PDF page 75

Column nameData typeDescription
plansbigintNumber of times the statement was planned.
total_plan_timedouble precisionTotal time spent planning the statement.
min_plan_timedouble precisionMinimum time spent planning the statement, in milliseconds.
max_plan_timedouble precisionMaximum time spent planning the statement, in milliseconds.
mean_plan_timedouble precisionMeantime spent planning the statement, in milliseconds.
stddev_plan_timedouble precisionPopulation standard deviation of time spent planning the statement, in milliseconds.
wal_recordsbigintTotal count of WAL records.
wal_fpibigintTotal number of WAL full-page writes.
wal_bytesnumericTotal amount of WAL bytes.
Table 29 Added columns

The column names in the pg_stat_statements view have been changed as follows.

PostgreSQL 12PostgreSQL 13Description
total_timetotal_exec_timeTotal time spent executing the statement.
min_timemin_exec_timeMinimum time spent executing the statement.
max_timemax_exec_timeMaximum time spent executing the statement.
mean_timemean_exec_timeMean time spent executing the statement.
stddev_timestddev_exec_timePopulation standard deviation of time spent executing the statement.
Table 30 Modified columns

PDF page 76

Example 83 Refer the pg_stat_statements view
postgres=# SELECT queryid, plans, total_plan_time, min_plan_time
FROM pg_stat_statements WHERE plans != 0;
       queryid        | plans |   total_plan_time    | min_plan_time
----------------------+-------+----------------------+---------------
  1809546128015582813 |     1 |               0.9533 |        0.9533
  1580010417825738145 |   900 |   29.697499999999998 |        0.0194
   726988806503882440 |     1 |               0.0889 |        0.0889
  6547867665616429211 |     1 |               0.3364 |        0.3364
  1518237015596383425 |     1 |               0.0522 |        0.0522
  6090531631178874043 |   900 |    51.09360000000001 |        0.0221
 -8944905077122340531 |     6 |  0.22340000000000002 |        0.0333
  -261743227044297956 |    10 | 0.061900000000000004 |        0.0054
…
SQL statement normalization

The SELECT statement with the FOR UPDATE clause specified and the SELECT statement without it are now separated. Previously, the presence or absence of the FOR UPDATE clause was ignored.

3.5.7 postgres_fdw

The following options have been added to the postgres_fdw extension:

Password_required option

By default, general users are refused connections without a password. This behavior can now be changed by specifying the password_required attribute when creating/changing a user mapping. Only superusers can change this option.

Example 84 Create USER MAPPING object without a password
postgres=# CREATE USER MAPPING FOR demo SERVER remhost1
OPTIONS (user 'demo') ;
CREATE USER MAPPING

PDF page 77

Example 85 Creation of external table by general user and error
postgres=> CREATE FOREIGN TABLE data1(c1 INT, c2 VARCHAR(10))
SERVER remhost1 ;
CREATE FOREIGN TABLE
postgres=> SELECT * FROM data1 ;
ERROR:  password is required
DETAIL:  Non-superusers must provide a password in the user
mapping.
By setting the option password_required to 'false', password setting for user mapping can be avoided.
Example 86 Setting to allow password omission
postgres=# ALTER USER MAPPING FOR demo SERVER remhost1 OPTIONS
(password_required 'false');
ALTER USER MAPPING
Additional authentication options

The sslkey and sslcert options can be specified as options when creating a user mapping. These options can only be specified if the superuser is creating/modifying USER MAPPING.

3.5.8 bool_plperl

The extension bool_plperl was added. Use this extension with PL/Perl extension. Used to correctly transfer the value of a bool value to a Perl program.

PDF page 78

Example 87 bool_plperl extension
postgres=> CREATE EXTENSION plperl ;
CREATE EXTENSION
postgres=> CREATE EXTENSION bool_plperl ;
CREATE EXTENSION
postgres=> CREATE FUNCTION perl_and(bool, bool) RETURNS bool
TRANSFORM FOR TYPE bool
AS $$
   my ($a, $b) = @_;
return $a && $b;
$$ LANGUAGE plperl ;
CREATE FUNCTION

8 URL List

The external references and release links listed by the source PDF.
GASource pages: PDF 79Original PDF on GitHub

The links in this chapter are preserved from the source PDF’s URL list.

PDF page 79

9 Change History

The source document’s revision history.
GASource pages: PDF 80Original PDF on GitHub

This chapter preserves the source document’s revision history and publication credits.

PDF page 80

Change history

VersionDateAuthorDescription
0.1Apr 09, 2020Noriyoshi ShinodaCreate an internal review version. Reviewers: Tomoo Takahashi Akiko Takeshima (Hewlett Packard Enterprise Japan)
1.0May 27, 2020Noriyoshi ShinodaModification completed according to PostgreSQL 13 Beta 1 Reviewer: Satoshi Nagayasu (Uptime Technologies, LCC.)
1.1Sep 27, 2020Noriyoshi ShinodaModified for PostgreSQL 13 GA - Modify ANALYZE (BUFFERS) statement - Modify column pg_stat_replication view - Drop columns pg_stat_replication view - Drop GUC enable_hashagg_disk - Rename GUC enable_incrementalsort - Add GUC hash_mem_multiplier - Add GUC max_slot_wal_keep_size - Modify GUC server_version value - Rename GUC wal_keep_segments - Modify the setting of earthdistance module - Modify default value of pg_stat_statements.track_planning - Modify default minimum SSL version to TLSv1.2 - Fix typo