PostgreSQL 11 New Features
PostgreSQL 11 New Features
WITH EXAMPLES · ENGLISH SOURCE EDITION
Explore the features, SQL examples, and compatibility changes documented by Noriyoshi Shinoda.
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
- Table 1 — Version
- Table 2 — Examples notation
- Table 3 — Syntax rules
- Table 4 — Related parameter name
- Table 5 — Simple INSERT statement
- Table 6 — Simple UPDATE statement (No tuple movement between partitions)
- Table 7 — Simple DELETE statement
- Table 8 — TRUNCATE statement
- Table 9 — When a tuple is moved between partitions by executing an UPDATE statement
- Table 10 — INSERT ON CONFLICT DO NOTHING (With conflict)
- Table 11 — System catalogs with columns added
- Table 12 — Catalogs with columns deleted
- Table 13 — Value is now stored information_schema catalog of the schema
- Table 14 — Added ROLE
- Table 15 — Added hash functions
- Table 16 — Added parameters
- Table 17 — Changed configuration parameters
- Table 18 — Parameters with default values changed
- Table 19 — Obsoleted parameter
- Table 20 — Added parameters
- Table 21 — The Variable indicating execution result of SQL statement
- Table 22 — Default setting
- Table 23 — -C ORACLE setting
- Table 24 — Added options for pg_resetwal command
- Table 25 — Option for pg_controldata command
- Table 26 — Provided functions
Examples
- Example 1 — CREATE FUNCTION statement with WITH clause
- Example 2 — TO_NUMBER function
- Example 3 — TO_NUMBER function
- Example 4 — Parallel Hash
- Example 5 — Parallel Append
- Example 6 — Parallelization of CREATE TABLE AS SELECT statement
- Example 7 — Parallelization of CREATE MATERIALIZED VIEW statement
- Example 8 — Parallelization of SELECT INTO statement
- Example 9 — Create HASH Partitioned table
- Example 10 — Create partition
- Example 11 — Confirmation of table structure
- Example 12 — Error when there are not enough partitions
- Example 13 — Error in the INSERT statement
- Example 14 — Partition elimination
- Example 15 — Catalogs for Hash Partition table
- Example 16 — Creating DEFAULT partition (LIST partition)
- Example 17 — Attach DEFAULT partition (LIST partition)
- Example 18 — DEFAULT partition restriction
- Example 19 — UPDATE statement to move the partition (preparation of data)
- Example 20 — UPDATE statement to move partitions (update and confirm data)
- Example 21 — Create index
- Example 22 — Check auto-created index
- Example 23 — Attaching a table
- Example 24 — Individual deletion of automatically created index
- Example 25 — Create the primary key in the partitioned table
- Example 26 — Attached table and primary key
- Example 27 — Create primary key without partition key column
- Example 28 — Attach a table with a different primary key
- Example 29 — Partitions and Unique Constraints with FOREIGN TABLE
- Example 30 — Partitioned table and INSERT ON CONFLICT statement
- Example 31 — INSERT ON CONFLICT statement across partitions
- Example 32 — Execution plan in the default state
- Example 33 — Execution plan with Partition-Wise Join enabled
- Example 34 — Execution plan with Partition-Wise Aggregate enabled
- Example 35 — Partitioned table and Foreign key
- Example 36 — Executed SQL statement for test
- Example 37 — Execution plan on PostgreSQL 10
- Example 38 — Execution plan on PostgreSQL 11
- Example 39 — Control Partition Pruning
- Example 40 — Specify TRUNCATE clause in CREATE PUBLICATION statement
- Example 41 — Set replication start LSN to current LSN
- Example 42 — Refer pg_stat_activity catalog
- Example 43 — Refer pg_attribute catalog
- Example 44 — pg_read_server_files role
- Example 45 — Execution plan of SQL using JIT compilation features
- Example 46 — Test case
- Example 47 — Lock status on PostgreSQL 10
- Example 48 — Lock status on PostgreSQL 11
- Example 49 — pgproto definition file
- Example 50 — backup_label file
- Example 51 — Execution of LOCK TABLE statement for the view
- Example 52 — Executing LOCK TABLE statement to MATERIALIZED VIEW
- Example 53 — STATISTICS value for function index column
- Example 54 — Execution of VACUUM, ANALYZE statement for multiple tables
- Example 55 — Output "aggressively"
- Example 56 — Execution plan of PostgreSQL 10
- Example 57 — Execution plan of PostgreSQL 11
- Example 58 — INCLUDE clause with CREATE INDEX statement
- Example 59 — INCLUDE clause with CREATE TABLE statement
- Example 60 — The option of CREATE INDEX statement
- Example 61 — Storage option for CREATE TABLE statement
- Example 62 — Parallel query executed in EXPLAIN statement
- Example 63 — SHA512 hash function
- Example 64 — json_to_tsvector function
- Example 65 — websearch_to_tsquery function
- Example 66 — ^@ operator
- Example 67 — Casting from JSONB type
- Example 68 — PROCEDURE creation
- Example 69 — Execute PROCEDURE (1)
- Example 70 — Execute PROCEDURE (2)
- Example 71 — List of PROCEDURE
- Example 72 — Display PROCEDURE definition
- Example 73 — Transaction control in PROCEDURE
- Example 74 — CONSTANT clause and changing value error
- Example 75 — NOT NULL clause and initial value
- Example 76 — SET TRANSACTION statement
- Example 77 — Parameter parallel_leader_participation = on
- Example 78 — Parameter parallel_leader_participation = off
- Example 79 — Parameter log_parser_stats (Linux)
- Example 80 — \gdesc command
- Example 81 — SQL execution result variable
- Example 82 — String output declaration
- Example 83 — String output declaration
- Example 84 — Fetch the column data
- Example 85 — Specify DO CONTINUE clause
- Example 86 — initdb --wal-segsize option
- Example 87 — initdb --allow-group-access option
- Example 88 — pg_dumpall command with specifying the character encoding
- Example 89 — pg_ctl command
- Example 90 — pg_basebackup command
- Example 91 — Batch mode operation
- Example 92 — Usage of pg_verify_checksums command
- Example 93 — Execute pg_verify_checksums command
- Example 94 — Use amcheck module
- Example 95 — Create B-Tree Gin index
- Example 96 — Execution plan on PostgreSQL 10
- Example 97 — Execution plan on PostgreSQL 11
- Example 98 — jsonb_plpython module
- Example 99 — jsonb_plperl module
- Example 100 — bt_metap function
- Example 101 — strict_word_similarity function
- Example 102 — Partition with FOREIGN TABLE
- Example 103 — The behavior of PostgreSQL 10
- Example 104 — The behavior of PostgreSQL 11
- Example 105 — Execution plan of PostgreSQL 10
- Example 106 — Execution plan of PostgreSQL 11
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
PDF page 5
1.1 Purpose
The purpose of this document is to provide information of the major new features of PostgreSQL 11.
1.2 Audience
This document is written for engineers who already have knowledge of PostgreSQL, such as installation, basic management, etc.
1.3 Scope
This document describes the major difference between PostgreSQL 10 (10.4) and PostgreSQL 11 (11.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.
Bug fix
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.
| Software | Version |
|---|---|
| PostgreSQL | PostgreSQL 10.4 (for comparison) PostgreSQL 11 (11.0) (October 15, 2018 21:15:55) |
| Operating System | Red Hat Enterprise Linux 7 Update 4 (x86-64) |
| Configure option | –with-llvm –with-python –with-perl |
PDF page 6
1.5 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 to Noriyoshi Shinoda
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:
| Notation | Description |
|---|---|
| # | Shell prompt for Linux root user |
| $ | Shell prompt for Linux general user |
| Bold | User input string |
| postgres=# | psql command prompt for PostgreSQL administrator |
| postgres=> | psql command prompt for PostgreSQL general user |
| Underline | Important output items |
The syntax is described in the following rules:
| Notation | Description |
|---|---|
| Italic | Replaced 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 |
2 New Features Summary
PDF page 7
2.1 Overview
More than 160 new features have been added to PostgreSQL 11. Here are some typical new features and benefits. This version focuses to enhance of various new features added in PostgreSQL 10.
2.1 Improve analytic query performance
PostgreSQL 11 has been enhanced to improve the performance of long-running analytical queries. The scope to which parallel query is applied has been greatly expanded. This allows the more efficient use of multiple processors in analytical queries and better throughput. Parallel queries can be executed with the following conditions.
With Hash Join operator
With Append operator
On SELECT INTO statement
At the same time, CREATE TABLE AS SELECT, CREATE INDEX, and CREATE MATERIALIZED VIEW statements that are executed to maintain large tables can also be executed in parallel. For the parallel query, see Section “2.2 Enhancements of Parallel query”. Also, JIT compilation feature by LLVM is now available for SQL statements that occupy CPU for a long time. SQL statements with high expected cost are compiled and executed by LLVM. For details of JIT compilation, refer to “2.5.3 LLVM Integration”.
2.2 Improve maintenance task
The following features that can improve operability have been added.
Enhancement of partitioned table
A declarative partitioning feature that can manage a table storing a large amount of data by dividing it appeared in PostgreSQL 10. However, the partitioning feature of PostgreSQL 10 had many restrictions. In PostgreSQL 11, many restrictions have been resolved, and the following enhancements were implemented.
Provided HASH partition as a partitioning method
Create PRIMARY KEY / UNIQUE KEY for the partitioned table
Automatic creation of indexes for each partition
Create a FOREIGN KEY for the partitioned table
DEFAULT partition that stores value not included in partitions
PDF page 8
Partition-Wise Join, Partition-Wise Aggregation for joining and aggregating partition
Provided parameter to control partition elimination
Improvement of Logical Replication feature
TRUNCATE statement is now propagated in the Logical Decoding environment and the Logical Replication environment. This feature makes synchronization of replication data easier. In PostgreSQL 10, TRUNCATE statement was not transferred to the remote instance.
Improved pg_prewarm Contrib module
Pg_prewarm module saves automatically the information of the page cached in the shared buffer and automatically caches the page when restarting the instance.
2.3 Improve reliability
In PostgreSQL 11, integrity checking tools have been enriched to improve reliability.
Provides block consistency check tool
Pg_verify_checksums command to check the integrity of the block is provided. This command must be executed after stopping the instance.
Confirm block checksum at backup
Pg_basebackup command now checks the checksum of the backup blocks.
amcheck module
The Contrib module amcheck is provided. This module can check the consistency of the B-Tree index.
2.4 For application development
PostgreSQL 11 also implements many new features related to application development.
PROCEDURE object
A new object PROCEDURE has been added. It is an object similar to FUNCTION without a return value. PROCEDURE can control transactions within a program.
Enhancement of PL/pgSQL Language
A CONSTANT clause that defines constant value and a NOT NULL clause that can detect variable initialization misses have been added to PL/pgSQL language.
PDF page 9
2.5 Incompatibility
PostgreSQL 11 has changed the following specifications from PostgreSQL 10.
WITH clause of CREATE FUNCTION statement
WITH clause of CREATE FUNCTION has been made obsolete.
Contrib module
The chkpass module has been deleted.
Removed columns from some system catalogs
Some columns have been removed from the pg_class catalog and pg_proc catalog. Please refer to “2.5.1 Changing system catalog”.
Changed default value
The default value of ssl_compression in libpq connection string has been changed.
Incompatibility of TO_NUMBER function
The TO_NUMBER function has been changed to ignore the separator in the template.
PDF page 10
Incompatibility of TO_DATE / TO_NUMBER / TO_TIMESTAMP functions
These functions now skip multibyte characters in templates by character.
PDF page 11
3 Enhancements of Parallel Query
PDF page 11
In PostgreSQL 11, parallel queries can now be used in many situations.
3.1.1 Parallel Hash
Hash joins and hashing can now be processed in parallel. Parallel Hash or Parallel Hash Join is displayed in the execution plan as follows.
3.1.2 Parallel Append
Append processing can now be executed in parallel. Parallel Append is displayed in the execution plan.
PDF page 12
3.1.3 CREATE TABLE AS SELECT statement
The SELECT processing in CREATE TABLE AS SELECT statement can now be executed as a parallel query. It was serial processing on PostgreSQL 10.
3.1.4 CREATE MATERIALIZED VIEW statement
The SELECT processing of CREATE MATERIALIZED VIEW statement now works as a parallel query. It was serial running on PostgreSQL 10.
PDF page 13
3.1.5 SELECT INTO statement
SELECT INTO statement now supports parallel queries.
3.1.6 CREATE INDEX statement
BTree index creation processing can now be executed in parallel.
4 Enhancements of Partitioned Table
PDF page 14
In PostgreSQL 11 the following features have been added to the partitioned table.
3.2.1 Hash Partition
HASH was added to partitioning method of the partitioned table. This feature calculates the hash value of column value and performs partitioning by the hash value. Specify PARTITION BY HASH clause in CREATE TABLE statement that creates the partitioned table.
PDF page 15
PDF page 16
3.2.2 Default partition
The partition table automatically selects the partition where tuples are stored by column values. In PostgreSQL 11 DEFAULT partition feature that stores tuples with column values that are not stored in existing other partitions have been added. To create DEFAULT partition, specify DEFAULT clause instead of the FOR VALUES clause of CREATE TABLE statement. It is a common syntax for RANGE partitioned table and LIST partitioned table.
PDF page 17
Multiple DEFAULT partitions cannot be specified in the partitioned table
Partitions with the same partition-key value as the tuples in DEFAULT partition cannot be
added
When attaching an existing table as DEFAULT partition, all tuples in the table to be attached
are checked, and an error occurs if the same value is stored in the existing partition
DEFAULT partition cannot be specified for HASH partitioned table
In the example below, while trying to add a partition whose c1 column value is 200, a tuple whose value in the c1 column is 200 is already stored in the default partition, it fails.
PDF page 18
3.2.3 Update partition key
It is now possible to execute an UPDATE statement which moves a tuple to another partition. In PostgreSQL 10, UPDATE statement that will change the value of partition-key column failed, but in PostgreSQL 11 it will move the tuple to another partition.
PDF page 19
Trigger
If an UPDATE statement is executed to move a tuple to another partition, the behavior of the trigger is complicated. For the trigger information to be executed, refer to “2.3.8 FOR EACH ROW Trigger”.
3.2.4 Automatic index creation
When creating an index on a partitioned table, an index with the same configuration is automatically created for each partition.
PDF page 20
PDF page 21
PDF page 22
3.2.5 Create unique constraint
Unique constraints (PRIMARY KEY and UNIQUE KEY) can now be specified for the partitioned table.
PDF page 23
PDF page 24
A primary key constraint must include a partition key column. Attempting to create a primary key constraint that does not contain partitioned columns results in an error.
PDF page 25
3.2.6 INSERT ON CONFLICT statement
INSERT ON CONFLICT statement to the partitioned table can now be executed. Both DO NOTHING syntax and DO UPDATE syntax are executable.
PDF page 26
3.2.7 Partition-Wise Join / Partition-Wise Aggregate
Partition-Wise Join which joins partition when joining tables and Partition-Wise Aggregate which performs aggregation is supported. These features are off by default but can be enabled by setting the following parameter to “on”.
| Features | Parameter name | Default value |
|---|---|---|
| Partition-Wise Join | enable partitionwise join__ | off |
| Partition-Wise Aggregate | enable partitionwise aggregate__ | off |
The following is an execution plan of the SQL statement that performs the join between the partitioned table with the c1 column as the key. In the default state, each partition is integrated by Append and then joined using Parallel Hash Join.
PDF page 27
PDF page 28
PDF page 29
PDF page 30
3.2.8 FOR EACH ROW trigger
FOR EACH ROW trigger for the partitioned table can now be created. However, BEFORE trigger cannot be created, only AFTER trigger can be created. Also, WHEN clause cannot be specified. When the FOR EACH ROW trigger is executed, TG_TABLE_NAME variable is changed to the partition name where the tuple is actually stored, not the partitioned table name. As a result of the verification, each trigger is executed in the following order.
| Order | Target table | TG_WHEN | TG_OP | TG_LEVEL | TG_TABLE_NAME |
|---|---|---|---|---|---|
| 1 | Partitioned table | BEFORE | INSERT | STATEMENT | Partitioned table |
| 2 | Partition | BEFORE | INSERT | ROW | Partition |
| 3 | Partitioned table | AFTER | INSERT | ROW | Partition |
| 4 | Partition | AFTER | INSERT | ROW | Partition |
| 5 | Partitioned table | AFTER | INSERT | STATEMENT | Partitioned table |
| Order | Target table | TG_WHEN | TG_OP | TG_LEVEL | TG_TABLE_NAME |
|---|---|---|---|---|---|
| 1 | Partitioned table | BEFORE | UPDATE | STATEMENT | Partitioned table |
| 2 | Partition | BEFORE | UPDATE | ROW | Partition |
| 3 | Partitioned table | AFTER | UPDATE | ROW | Partition |
| 4 | Partition | AFTER | UPDATE | ROW | Partition |
| 5 | Partitioned table | AFTER | UPDATE | STATEMENT | Partitioned table |
| Order | Target table | TG_WHEN | TG_OP | TG_LEVEL | TG_TABLE_NAME |
|---|---|---|---|---|---|
| 1 | Partitioned table | BEFORE | DELETE | STATEMENT | Partitioned table |
| 2 | Partition | BEFORE | DELETE | ROW | Partition |
| 3 | Partitioned table | AFTER | DELETE | ROW | Partition |
| 4 | Partition | AFTER | DELETE | ROW | Partition |
| 5 | Partitioned table | AFTER | DELETE | STATEMENT | Partitioned table |
PDF page 31
| Order | Target table | TG_WHEN | TG_OP | TG_LEVEL | TG_TABLE_NAME |
|---|---|---|---|---|---|
| 1 | Partitioned table | BEFORE | TRUNCATE | STATEMENT | Partitioned table |
| 2 | Partition | BEFORE | TRUNCATE | STATEMENT | Partition |
| 3 | Partitioned table | AFTER | TRUNCATE | STATEMENT | Partitioned table |
| 4 | Partition | BEFORE | TRUNCATE | STATEMENT | Partitioned table |
| Order | Target table | TG_WHEN | TG_OP | TG_LEVEL | TG_TABLE_NAME |
|---|---|---|---|---|---|
| 1 | Partitioned table | BEFORE | UPDATE | STATEMENT | Partitioned table |
| 2 | Source partition | BEFORE | UPDATE | ROW | Source partition |
| 3 | Source partition | BEFORE | DELETE | ROW | Source partition |
| 4 | Target partition | BEFORE | INSERT | ROW | Target partition |
| 5 | Partitioned table | AFTER | DELETE | ROW | Source partition |
| 6 | Source partition | AFTER | DELETE | ROW | Source partition |
| 7 | Partitioned table | AFTER | INSERT | ROW | Target partition |
| 8 | Target partition | AFTER | INSERT | ROW | Target partition |
| 9 | Partitioned table | AFTER | UPDATE | STATEMENT | Partitioned table |
| Order | Target table | TG_WHEN | TG_OP | TG_LEVEL | TG_TABLE_NAME |
|---|---|---|---|---|---|
| 1 | Partitioned table | BEFORE | INSERT | STATEMENT | Partitioned table |
| 2 | Partition | BEFORE | INSERT | ROW | Partition |
| 3 | Partitioned table | AFTER | INSERT | STATEMENT | Partitioned table |
3.2.9 FOREIGN KEY support
A Foreign key could not be created in PostgreSQL 10 partitioned table. In PostgreSQL 11 this restriction has been resolved.
PDF page 32
3.2.10 Dynamic Partition Elimination
Partition elimination is now executed even when the partition key is specified as a parameter. However, dynamic partition elimination is available only when “generic plan” by PREPARE and EXECUTE statements are used.
PDF page 33
3.2.11 Control Partition Pruning
The partition elimination feature can be controlled by setting the parameter enable_partition_pruning. Setting this parameter to “off” will disable partition pruning in the search process.
PDF page 34
5 Enhancement of Logical Replication
PDF page 35
The following features have been added to PostgreSQL 11 logical replication.
3.3.1 TRUNCATE statement support
The TRUNCATE statement executed on the PUBLICATION node in the Logical Replication environment now propagates to the SUBSCRIPTION node. Along with this, the specification to propagate TRUNCATE statement has been added to WITH clause of CREATE PUBLICATION and ALTER PUBLICATION statements.
3.3.2 pg_replication_slot_advance function
When a conflict occurs in the logical replication environment in PostgreSQL 10, the start LSN of logical replication needs to be specified by executing the pg_replication_origin_advance function on the standby instance to resolve a conflict. In PostgreSQL 11, similar processing can now be executed in the PUBLICATION instance. Execute pg_replication_slot_advance function. This function specifies the replication slot name and LSN.
6 Architecture
PDF page 36
3.4.1 Modified catalogs
The following catalogs have been changed.
| Catalog name | Added column | Data Type Description | |
|---|---|---|---|
| pg_aggregate | aggfinalmodify | char | Whether the aggfinalfn function changes the value |
| aggmfinalmodify | char | Whether the aggmfinalfn function changes the value | |
| pg_attribute | atthasmissing | bool | Have a default value that has not updated the page |
| attmissingval | anyarray | Default value not updating page | |
| pg_class | relrewrite | oid | OID when the new relation is created during DDL execution |
| pg_constraint | conparentid | oid | Parent partition constraint OID |
| pg_index | indnkeyatts | smallint | Number of key columns |
| pg_partitioned_table | partdefid | oid | OID of the default partition |
| pg_proc | prokind | char | Object kind f: function p: procedure a: aggregate function w: window function |
| pg_publication | pubtruncate | boolean | TRUNCATE propagation |
| pg_stat_wal_receiver | sender_host | text | Connection destination hostname |
| sender_port | integer | Connection destination port number | |
| information_schema.table_constraints | enforced | yes_or_no | Reserved for future use |
PDF page 37
| Catalog name | Deleted column | Description |
|---|---|---|
| pg_class | relhaspkey | Have primary key |
| pg_proc | proisagg | Is aggregate function |
| proiswindow | Is Window function |
| Catalog name | Column name | Description |
|---|---|---|
| triggers | action_order | Trigger execution order |
| action reference new table___ | “NEW” transition table name | |
| action reference old table___ | “OLD” transition table name | |
| tables | table_type | FOREIGN stored for the foreign table (previously FOREIGN TABLE stored) |
pg_stat_activity catalog
Backend_type column and process name are now synchronized. The value of the backend_type column of the replication launcher process was “background worker” in PostgreSQL 10, but in PostgreSQL 11 it is “logical replication launcher”.
pg_attribute catalog
In PostgreSQL 11, columns with the DEFAULT value and NOT NULL constraint can now be added without updating the actual tuples. Along with this, the columns for this feature have been added to the pg_attribute catalog.
PDF page 38
3.4.2 Added ROLE
The following roles were added. These roles are mainly used to allow general users to execute COPY statements and execute the file_fdw Contrib module.
| Role name | Description |
|---|---|
| pg_execute_server_program | Execute programs on the server |
| pg_read_server_files | Read files on the server |
| pg_write_server_files | Write files on the server |
3.4.3 LLVM integration
PostgreSQL 11 supports JIT compilation using LLVM (https://llvm.org/) to speed up long-running SQL statements caused by processor bottlenecks. SQL statements estimated to exceed more than a certain amount of cost are compiled beforehand and then executed.
Installation
In order to use LLVM, it is necessary to specify the option –with-llvm of “configure” command at
PDF page 39
the time of installation. When executing “configure” command, “llvm-config” command and “clang” command must be included in command execution path (or specified in environment variable LLVM_CONFIG and environment variable CLANG).
The behavior of JIT compilation
For SQL statements whose total execution cost exceeds the parameter jit_above_cost (default value 100000), the JIT compilation feature by LLVM runs. If this parameter is specified as “-1” or the parameter jit is set to “off”, the JIT feature will be disabled. The behavior of JIT compilation processing is changed by inlining (parameter jit_inline_above_cost) and optimization (parameter jit_optimize_above_cost).
Execution plan
By executing EXPLAIN statements for SQL statement using the JIT compilation feature, information starting from “JIT:” is displayed.
PDF page 40
3.4.4 Predicate locking for GIN / GiST / HASH index
Predicate locks are now available for GIN index, GiST index, HASH index. This feature reduces the lock range, improving the concurrency of SQL statements with multiple sessions. The following example is the result of verification using the HASH index. In PostgreSQL 10, the lock range is the relation, but in PostgreSQL 11 it is found to be page.
PDF page 41
3.4.5 Enhanced LDAP authentication
“ldapsearchfilter” attribute has been added to the LDAP authentication parameter described in the pg_hba.conf file. LDAP server can be searched more flexibe than “ldapsearchattribute” attribute.
3.4.6 Extended Query timeout
The timeout of conventional Extended Queries was determined by the time until SYNC messages were sent after sending multiple SQL statements. PostgreSQL 11 now takes into account the execution time of individual SQL statements. The example below is the definition file of pgproto (https://github.com/tatsuo-ishii/pgproto). In PostgreSQL 10 timeout occurred even if “SET statement_timeout = 4s” was set.
PDF page 42
3.4.7 Change of backup label file
A timeline ID is added to the backup_label file created when online backup is executed.
PDF page 43
3.4.8 Using Huge Pages under Windows environment
The “Lock Pages In Memory” setting is now available in the Microsoft Windows environment. When parameter huge_pages is set to “try” or “on”, shared memory will be reserved in a continuous area. Internally, PAGE_READWRITE, SEC_LARGE_PAGES, and SEC_COMMIT are specified in Windows API CreateFileMapping. Previously only PAGE_READWRITE was specified.
3.4.9 Remove secondary checkpoint information
PostgreSQL 10 saved the last two checkpoint information, but now only the latest checkpoint information is saved.
3.4.10 Error code list
macro names etc. of PostgreSQL, PL/pgSQL, and PL/Tcl.
7 SQL Statement
PDF page 44
This section explains new features related to SQL statements.
3.5.1 LOCK TABLE statement
In PostgreSQL 11, it is now possible to specify a view in the LOCK TABLE statement. When locking a view, the same mode lock is applied to the table included in the view definition.
PDF page 45
3.5.2 STATISTICS of function index
It is now possible to specify a STATISTICS value for a function index column.
PDF page 46
3.5.3 VACUUM statement and ANALYZE statement
Multiple tables
The VACUUM and ANALYZE statements can now specify multiple tables at the same time.
Output aggressively
When executing the VACUUM (VERBOSE, FREEZE) statement, “aggressively” is added to the output.
PDF page 47
3.5.4 Push down the LIMIT clause
The content of the LIMIT clause is now pushed to the subquery when the LIMIT clause is set for the sorted subquery.
PDF page 48
3.5.5 CREATE INDEX statement
The following enhancements have been added to the CREATE INDEX statement.
INCLUDE clause
An INCLUDE clause to add columns to the index can be specified. This is effective when adding columns which are unrelated to unique constraint to a unique index etc. In the example below the UNIQUE CONSTRAINT is created in columns c1 and c2, but the index includes c3 column.
PDF page 49
Surjective indexes
The recheck_on_update option can now be specified in the WITH clause of the CREATE INDEX statement. The default value is “on”. This parameter specifies whether to update the function index by HOT.
PDF page 50
3.5.6 CREATE TABLE statement
It is now possible to specify the storage parameter toast_tuple_target indicating the threshold value for TOAST conversion. The default value is the same as before.
3.5.7 WINDOW function
The GROUPS clause and EXCLUDE clause in the window frame specification can now be specified in the WINDOWS function. Also, float 4 type, float 8 type, and numeric type can be used for RANGE clause.
PDF page 51
Syntax
The following syntax can be specified in the frame_exclusion clause. Syntax (Part of the frame_exclusion)
3.5.8 EXPLAIN statement
Information on sorting is now displayed for each worker when executing a parallel query.
PDF page 52
3.5.9 Functions
The following functions have been added/extended.
Added hash functions
Hash functions using SHA-224 / SHA-256 / SHA-384 / SHA-512 has been provided. All usages are the same.
| Functionname | Description |
|---|---|
| sha224(bytea) | Calculate the SHA-224 hash value |
| sha256(bytea) | Calculate the SHA-256 hash value |
| sha384(bytea) | Calculate the SHA-384 hash value |
| sha512(bytea) | Calculate the SHA-512 hash value |
json(b)_to_tsvector function
The json(b)_to_tsvector function to convert from JSON type (or JSONB type) to tsvector type has been added.
PDF page 53
websearch_to_tsquery function
The websearch_to_tsquery function to convert Web search format string to tsquery type has been added.
3.5.10 Operator
The following operator has been added.
String forward match search
An operator “^ @” to search forward matches for strings has been added. It can be used for the same purpose as “LIKE ‘character_string%’” in the WHERE clause. Syntax
PDF page 54
3.5.11 Others
Cast from JSONB type
Casting from JSONB type to bool type and numerical type became possible.
Enhancement of SP-GiST index
The poly_ops operator class that can be created for polygon type has been provided. Also, userdefined methods to compress can be defined.
8 PL/pgSQL Language
PDF page 55
This article explains the enhancement of the PL/pgSQL language and new objects using PL/pgSQL.
3.6.1 PROCEDURE object
In PostgreSQL 11, PROCEDURE was added as a new schema object. PROCEDURE is almost the same object as FUNCTION without a return value. PROCEDURE is created with the CREATE PROCEDURE statement. Unlike the CREATE FUNCTION statement, there are no RETURNS clause, ROWS clause, PARALLEL clause, CALLED ON clause, etc.
PDF page 56
PDF page 57
Transaction control
Within procedures, it is possible to control transactions. In PL/pgSQL procedure, COMMIT statement and ROLLBACK statement can be used. It is now possible to control transactions within cursor loops.
PDF page 58
PL/Python plpy.commit() / plpy.rollback() PL/Perl spi_commit() / spi_rollback() PL/Tcl commit / rollback
Change of CREATE / ALTER TRIGGER statement
Since it was possible to distinguish between PROCEDURE object and FUNCTION object, EXECUTE PROCEDURE clause of CREATE TRIGGER statement and ALTER TRIGGER statement can also use EXECUTE FUNCTION clause. Both meanings are the same.
3.6.2 Enhancement of variable definition
The following enhancements have been added to PL/pgSQL.
CONSTANT variables
Constants can now be declared by adding the CONSTANT clause to the variable. If an initial value is not specified, no error occurs and the value of the variable is set as NULL. Syntax
PDF page 59
NOT NULL variables
It is now possible to specify a NOT NULL constraint on a variable. An initial value is required at the time of declaration. An error occurs if an initial value is not specified. Also, assignment of NULL value will result in an error. Syntax
SET TRANSACTION statement
In PostgreSQL 11, It is possible to execute the SET TRANSACTION statement in the PL/pgSQL block.
PDF page 60
9 Configuration Parameters
PDF page 61
In PostgreSQL 11 the following parameters have been changed.
3.7.1 Added parameters
The following parameters have been added.
| Parameter name | Description (context) | Default |
|---|---|---|
| data_directory_mode | Database cluster protection mode (internal) | 0700 |
| enable_parallel_append | Enabled Parallel Append feature (user) | on |
| enable_parallel_hash | Enabled Parallel Hash feature (user) | on |
| enable_partition_pruning | Enabled partition pruning (user) | on |
| enable_partitionwise_aggregate | Enabled Partition-Wise Join feature (user) | off |
| enable_partitionwise_join | Enabled Partition-Wise Aggregate feature (user) | off |
| jit | Enabled JIT compilation feature (user) | off1 |
| jit_above_cost | The Cost to enable JIT compile function (user) 100000 | The Cost to enable JIT compile function (user) 100000 |
| jit_debugging_support | Enable debugger at JIT compilation (superuser-backend) | off |
| jit_dump_bitcode | Add LLVM bit code (superuser) | off |
| jit_expressions | Enable JIT expression (user) | on |
| jit_inline_above_cost | The cost to decide whether to make JIT inlining (user) | 500000 |
| jit_optimize_above_cost | The cost to decide whether to perform JIT optimization (user) | 500000 |
| jit_profiling_support | Enabled perf profiler (superuser-backend) | off |
| jit_provider | JIT provider name (postmaster) | llvmjit |
| jit_tuple_deforming | Enabled JIT tuple deforming (user) | on |
| max_parallel_maintenance_workers Maximum number of parallel workers used in | max_parallel_maintenance_workers Maximum number of parallel workers used in maintenance processing (user) | 2 |
| parallel_leader_participation | Change the behavior of the leader process (user) | on |
| ssl_passphrase_command | Command to get SSL connection passphrases (sighup) | '' |
| ssl_passphrase_command_supports_reload | Whether to use ssl_passphrase_command when reloading (sighup) | off |
| vacuum_cleanup_index_scale_factor | The ratio of the number of INSERTs that perform index cleanup (user) | 0.1 |
1 The default value was changed during Beta.
PDF page 62
parallel_leader_participation parameter
When a parallel query is executed, the leader process which coordinates the entire query and the worker processes cooperate with each other. In PostgreSQL 10, the leader process also executed the plan on the Gather and Gather Merge nodes. If this parameter is set to “off”, the leader process will not perform the same process as the worker process. The following example searches for table data of 10 million tuples. In both examples, two worker processes are running. In the first example, the portion of Parallel Seq Scan is executed three times with 3,333,333 tuples. In the second example where the parameter parallel_leader_participation is changed to “off”, it is executed in 2 loops with 5,000,000 tuples.
PDF page 63
3.7.2 Changed parameters
The setting range and options were changed for the following configuration parameters.
| log_parser_stats | setting value is |
|---|---|
| log_statement_stats | changed to “on” log_statement_stats |
| log_planner_stats | |
| log_executor_stats | |
| wal_segment_size UNIT of pg_settings catalog changed from 8kB to B | wal_segment_size UNIT of pg_settings catalog changed from 8kB to B |
Parameter name Changes
log_parser_stats parameter
When the value is set to “on”, the information output is increased. Additional output information varies depending on the operating system. The example below is for Linux.
PDF page 64
3.7.3 Parameters with default values changed
The default values of the following configuration parameters have been changed.
| version | 10.4 | 11.0 |
|---|---|---|
| server_version_num | 100004 | 110000 |
Parameter name PostgreSQL 10 PostgreSQL 11
3.7.4 Obsoleted parameter
The following parameter is obsolete.
| Parameter name | Alternative |
|---|---|
| replacement_sort_tuples | None |
PDF page 65
3.7.5 Authentication parameter change
Instance connect string
The following parameters have been added to the instance connection string of the Libpq library.
| Parameter name | Default | Description |
|---|---|---|
| replication | false | Specify whether to use replication protocol true: Physical replication database: logical replication |
The default value of ssl_compression parameter has been changed to “off”.
LDAP Authentication parameter
The ldapschema parameter has been added for LDAP authentication. Specifying “ldaps” for the parameter uses LDAP over SSL.
10 Utilities
PDF page 66
This section explains the major enhancements of utility commands.
3.8.1 psql command
The following features have been added to the psql command.
\gdesc command
A \gdesc command has been added to display the column name and data type of the most recently executed query.
Pager specification
As the environment variable to specify the pager used by the psql command, PSQL_PAGER is the priority than PAGER.
Query status
Variables concerning the execution status of SQL statements are now available. Combined with the \if command, SQL statement execution results can now be handled in SQL scripts. The LAST_ERROR_MESSAGE and LAST_ERROR_SQLSTATE variables maintain their contents even if another SQL statement succeeds after an error.
PDF page 67
| Variable name | Description |
|---|---|
| ERROR | True if the most recently executed SQL failed |
| LAST_ERROR_MESSAGE | The error message of the last error |
| LAST_ERROR_SQLSTATE | The error code of the last error |
| ROW_COUNT | Number of tuples processed by the most recently executed SQL statement |
| SQLSTATE | statement |
exit and quit command
The “exit” and “quit” command can now be used to terminate the psql command. Previously, the only \q was available.
Parameter definition check
The syntax “:{?variable_name}” to check whether variables are defined is now available.
PDF page 68
3.8.2 ECPG command
The following enhancements were implemented in ECPG.
Oracle mode
Here, explains the comparison between using the default value and specifying -C ORACLE. First, declare an area for character string output and an indicator as shown below.
PDF page 69
| Tabledata | shortstrvalue | shortstr indvalue _ | Note |
|---|---|---|---|
| '' | '' | 0 | shortstr[0] = NULL |
| ‘AB’ | ‘AB’ | 0 | shortstr[4] = not updated |
| ‘ABCD’ | ‘ABCD’ | 0 | shortstr[4] = NULL |
| ‘ABCDE’ | ‘ABCDE’ | 0 | shortstr[4] = ‘E’ |
| ‘ABCDEF’ | ‘ABCDE’ | 6 | shortstr[4] = ‘E’ |
| ‘ABCDEFGHIJ’ ‘ABCDE’ | ‘ABCDEFGHIJ’ ‘ABCDE’ | 10 | shortstr[4] = ‘E’ |
| Tabledata | shortstrvalue | shortstr indvalue _ | Note |
|---|---|---|---|
| '' | ’ ' | -1 | shortstr variable is filled with spaces |
| ‘AB’ | ‘AB ' | 0 | shortstr variable is filled with spaces |
| ‘ABCD’ | ‘ABCD’ | 0 | shortstr[4] = NULL |
| ‘ABCDE’ | ‘ABCD’ | 5 | shortstr[4] = NULL |
| ‘ABCDEF’ | ‘ABCD’ | 6 | shortstr[4] = NULL |
| ‘ABCDEFGHIJ’ ‘ABCD’ | ‘ABCDEFGHIJ’ ‘ABCD’ | 10 | shortstr[4] = NULL |
As in the above example, if “-C ORACLE” is specified, space is added if the variable area is surplus, and NULL is appended to the last of the variable.
DO CONTINUE statement
The DO CONTINUE clause can now be specified in the WHENEVER statement. This causes the flow of control to return to the beginning of loop when the result of statement matches the condition specified in WHENEVER.
PDF page 70
3.8.3 initdb command
The following enhancements were implemented to the initdb command.
–wal-segsize option
A “–wal-segsize” option to specify the size of the WAL file has been added. This option can be specified to a multiple of 2, and from 1 to 1024 in megabytes. The default value is 16 MB as before. Along with this, the “–with-wal-segsize” option of the “configure” command executed at the time of installation is obsolete.
–allow-group-access option
Added –allow-group-access option (or -g option) to allow group access to database cluster access mode. If this option is specified, the group’s read / execute permission is added to the directory protection mode of the database cluster, and the database cluster parameter data_directory_mode is changed to 0750.
PDF page 71
3.8.4 pg_dump / pg_dumpall command
The following options have been added to the pg_dump and pg_dumpall commands.
–load-via-partition-root option
The –load-via-partition-root option has been added to the pg_dump and pg_dumpall commands. When this option is specified, data is loaded via the root table of the partition table, not the individual partitions when loading the data.
–encoding option
The –encoding option (or -E parameter) has been added to the pg_dumpall command. As with the pg_dump command, this option specifies the character encoding of the output data.
–no-comments option
The –no-comments option has been added to the pg_dump command. If this option is specified, COMMENT will not be loaded.
3.8.5 pg_receivewal command
The following options have been added to the pg_receivewal command.
–endpos option
Added –endpos option (or -E option) to specify the LSN where the command will stop has been added. This is the same feature as the –endpos option added to the pg_recvlogical command in PostgreSQL 10.
–no-sync option
The –no-sync option was added. When this option is specified, the sync system call is not executed when writing data.
PDF page 72
3.8.6 pg_ctl command
The feature to send SIGKILL signal from pg_ctl command was implemented.
3.8.7 pg_basebackup command
The following enhancements were implemented for the pg_basebackup command.
–no-verify-checksum option
The pg_basebackup command now checks the checksum of the backed-up block. The –no-verify-checksum option skips the checksum verification process. If an error occurs in the checksum, the pg_basebackup command exits with a nonzero value.
–create-slot option
The pg_basebackup command now has a –create-slot option (or -C option) to create a replication slot. This option is used with the –slot option. The created replication slots are maintained even after the pg_basebackup command completes. If a replication slot with the same name already exists, the pg_basebackup command displays an error message and exits.
PDF page 73
Operation change in batch mode
When specifying the –progress option to the pg_basebackup command and executing it from batch mode (redirect from a shell script to a file), a line feed code “\n” is output instead of the “\r”.
Exclude pg_internal.init file
The pg_internal.init file is excluded from the backup target of the pg_basebackup command.
Exclude UNLOGGED table
The UNLOGGED and TEMPORARY tables are excluded from the transfer data.
PDF page 74
3.8.8 pg_resetwal / pg_controldata command
The –wal-segsize option to specify the size of the WAL file has been added to the pg_resetwal command. Also, the pg_resetwal and pg_controldata commands have long name options corresponding to existing short options.
| Short option | Added option |
|---|---|
| -c | –commit-timestamp-ids |
| -D | –pgdata |
| -e | –epoch |
| -f | –force |
| -l | –next-wal-file |
| -m | –multixact-ids |
| -n | –dry-run |
| -o | –next-oid |
| -O | –multixact-offset |
| -x | –next-transaction-id |
| None | –wal-segsize |
| Short option | Added option |
|---|---|
| -D | –pgdata |
3.8.9 configure command
The following options have been changed in the configure command.
–with-wal-segsize option
The –with-wal-segsize option has been obsoleted. The size of the WAL file can be specified by -wal-segsize option of initdb command.
–with-llvm option
The –with-llvm option to provide JIT compilation feature with LLVM has been added. When specifying this option, llvm-config command and clang command must be included in the command search path (or set the environment variable LLVM_CONFIG and the environment variable CLANG).
PDF page 75
3.8.10 pg_verify_checksums command
Pg_verify_checksums has been added as a command for checksum consistency check from outside the database. This command cannot be executed when the instance is running. In the example below, checksums are confirmed for only certain files, indicating that some blocks do not match checksums.
11 Contrib Modules
PDF page 76
Describes the new features of the Contrib modules.
3.9.1 adminpack
Previously, functions included in this module required SUPERUSER privilege. But now, general users are also executable if allowed by the GRANT statement.
3.9.2 amcheck
A new Contrib module amcheck has been added. The only B-Tree index can be checked. In the following example, the index idx1_data1 whose integrity has been destroyed is checked. Also, check the HASH index and an error has occurred.
| Function name | Description |
|---|---|
| bt_index_check | Consistency check for B-Tree index |
| bt_index_parent_check | Consistency check of B-Tree index including parentage relationship |
PDF page 77
3.9.3 btree_gin
B-Tree GIN indexes can now be created for bool, bpchar, and uuid columns.
3.9.4 citext
Operator class citext_pattern_ops for the index has been added. Operators <, <=, >, >= can be used for the citext type similarly to text type. Conventionally, it was converted to text type and executed.
PDF page 78
3.9.5 cube / seg
Index Only Scan is now executable with the GiST index.
3.9.6 jsonb_plpython
A new Contrib module jsonb_plpython has been added. The –with-python option must be specified in the configure command for installation. The module name specified in the CREATE EXTENSION statement is “jsonb_plpythonu”, “jsonb_plpython2u”, or “jsonb_plpython3u”. Jsonb can be specified in the TRANSFORM clause of the CREATE FUNCTION statement.
PDF page 79
3.9.7 jsonb_plperl
A new Contrib module jsonb_plperl has been added. The –with-perl option must be specified in the “configure” command for installation. To use it, specify jsonb in the TRANSFORM clause of the CREATE FUNCTION statement.
PDF page 80
3.9.8 pageinspect
The last_cleanup_num_tuples column was added to the output of bt_metap function.
PDF page 81
3.9.9 pg_prewarm
The feature which automatically loads pages that existed in shared memory when the instance was running into shared memory at instance startup has been added. When “pg_prewarm” is specified for the parameter shared_preload_libraries and the instance is started, the background worker process “postgres: autoprewarm master” is started automatically. The autoprewarm master process loads the blocks previously stored in the shared memory into the shared memory at instance startup. After that, this process saves the block information on the shared memory in a file at regular intervals. If the parameter max_worker_processes is 0, the background worker process will not start.
File
The file to which the autoprewarm process saves the block information loaded on shared memory is {PGDATA}/autoprewarm.blocks. This file is in text format and saves information such as a database, tablespace, filenode, block etc… While updating the file, it writes to the {PGDATA}/autoprewarm.blocks.tmp file and the file name is changed.
Parameter pg_prewarm.autoprewarm
Specifying the default value “on” for this parameter enables the automatic prewarm feature.
Parameter pg_prewarm.autoprewarm_interval
Specify the minimum interval, in seconds, at which block information on shared memory is saved periodically. The default value is 300 seconds (5 minutes). When this parameter is set to 0, periodic shared memory saving processing is not performed. This process will be performed only when the instance is stopped.
3.9.10 pg_trgm
The function strict_word_similarity has been added. This function is similar to the word_similarity function, but it matches the extent boundary to the word boundary.
PDF page 82
3.9.11 postgres_fdw
The following enhancements have been added to the postgres_fdw module.
Update remote partition
Even if the partition is FOREIGN TABLE, it is now possible to update tuples via partition table. It is also possible to insert tuples by COPY statement.
PDF page 83
Change superuser’s checking method
The connection check to the remote instance is now done by the USER MAPPING user, not the session user.
Behavior when joining by UPDATE / DELETE statement
DELETE or UPDATE statements which join FOREIGN TABLEs on the same FOREIGN SERVER can now be pushed down to remote instances.
PDF page 84
12 URL List
The links in this chapter are preserved from the source PDF’s URL list.
PDF page 85
13 Change History
This chapter preserves the source document’s revision history and publication credits.
PDF page 86
Change history
| Version | Date | Author | Description |
|---|---|---|---|
| 0.1 | Apr 19, 2018 | Noriyoshi Shinoda | Create internal review version Reviewer: Tomoo Takahashi Takahiro Kitayama (Hewlett Packard Enterprise Japan) |
| 0.2 | May 24, 2018 Noriyoshi Shinoda | May 24, 2018 Noriyoshi Shinoda | Recheck completed to respond to for PostgreSQL 11 Beta 1 Reviewer: Satoshi Nagayasu (Uptime Technologies, LCC.) |
| 1.0 | May 25, 2018 Noriyoshi Shinoda | May 25, 2018 Noriyoshi Shinoda | Create a published version |
| 1.1 | Oct 22, 2018 | Noriyoshi Shinoda | Rewrite for PostgreSQL 11 (11.0) |