SlideShare a Scribd company logo
Major Features: Postgres 11
BRUCE MOMJIAN
POSTGRESQL is an open-source, full-featured relational database.
This presentation gives an overview of the Postgres 11 release.
Creative Commons Attribution License http://momjian.us/presentations
Last updated: September, 2018
1 / 24
Postgres 11 Feature Outline
1. Partitioning improvements
2. Parallelism improvements
3. Stored procedures with transaction control
4. Executor-stage compilation
5. Prevent table rewrite for ALTER TABLE … ADD COLUMN with
non-NULL default
6. Finer-grained access control
7. Write-ahead log (WAL) improvements
8. Allow ’quit’ and ’exit’ to exit psql
9. Miscellaneous
Full item list at https://www.postgresql.org/docs/devel/static/
release-11.html
2 / 24
1. Partitioning Improvements
◮ Partitioning syntax added in Postgres 10
◮ simplified administration
◮ Postgres 11
◮ faster partition pruning during optimization
◮ executor-level partition pruning, e.g., for joins
◮ hash partitioning
◮ move updated rows to new partitions
◮ allow a default partition for non-matching rows
◮ allow unique/primary indexes when the partition key is
included, and allow foreign keys to reference them
◮ more items
3 / 24
Hash Partitioning Example
-- hash partition
CREATE TABLE part_test (x int, y text) PARTITION BY hash (x);
-- create child partitions
CREATE TABLE part_test_0 PARTITION OF part_test FOR VALUES
WITH (MODULUS 4, REMAINDER 0);
CREATE TABLE part_test_1 PARTITION OF part_test FOR VALUES
WITH (MODULUS 4, REMAINDER 1);
CREATE TABLE part_test_2 PARTITION OF part_test FOR VALUES
WITH (MODULUS 4, REMAINDER 2);
CREATE TABLE part_test_3 PARTITION OF part_test FOR VALUES
WITH (MODULUS 4, REMAINDER 3);
4 / 24
Partitioning Row Migration
-- insert 1k rows
INSERT INTO part_test SELECT generate_series(0, 999), ’old’;
-- What partition contains row zero?
SELECT relname
FROM pg_class
WHERE oid = (SELECT tableoid FROM part_test WHERE x = 0);
relname
-------------
part_test_0
-- change row zero to row 1003
UPDATE part_test SET x = 1003, y = ’new’ WHERE x = 0;
--What partition contains row 1003? Values are hashed twice.
SELECT relname
FROM pg_class
WHERE oid = (SELECT tableoid FROM part_test WHERE x = 1003);
relname
-------------
part_test_1
5 / 24
Partitioning Row Distribution
-- How are the rows distributed?
SELECT name, y, COUNT(*)
FROM part_test, LATERAL (
SELECT relname
FROM pg_class
WHERE pg_class.oid = part_test.tableoid) AS table_name (name)
GROUP BY name, y
ORDER BY 1, 2;
name | y | count
-------------+-----+-------
part_test_0 | old | 258
part_test_1 | new | 1
part_test_1 | old | 234
part_test_2 | old | 276
part_test_3 | old | 231
6 / 24
Range Partitioning Example
-- range partition
CREATE TABLE part_test2 (instant TIMESTAMP WITH TIME ZONE, description TEXT)
PARTITION BY RANGE (instant);
CREATE TABLE part_test2_2017 PARTITION OF part_test2 FOR VALUES
FROM (’2017-01-01’) TO (’2018-01-01’);
CREATE TABLE part_test2_2018 PARTITION OF part_test2 FOR VALUES
FROM (’2018-01-01’) TO (’2019-01-01’);
-- create default partition
CREATE TABLE part_test2_default PARTITION OF part_test2 DEFAULT;
-- add primary key to parent table
ALTER TABLE part_test2 ADD PRIMARY KEY (instant);
7 / 24
Default Partition
-- insert two years of rows
INSERT INTO part_test2
SELECT generate_series(’2017-01-01’::timestamptz,
’2018-12-31’, ’1 day’), ’rain’;
-- insert rows outside of the defined range
INSERT INTO part_test2 VALUES (’2019-02-20’, ’snow’);
SELECT name, COUNT(*)
FROM part_test2, LATERAL (
SELECT relname
FROM pg_class
WHERE pg_class.oid = part_test2.tableoid) AS table_name (name)
GROUP BY name
ORDER BY 1;
name | count
--------------------+-------
part_test2_2017 | 365
part_test2_2018 | 365
part_test2_default | 1
8 / 24
2. Parallelism Improvements
◮ Parallel btree index builds
◮ Parallel hash joins
◮ Parallelize individual SELECTs in UNION
◮ Seven more items
9 / 24
3. Stored Procedures with Transaction Control
◮ Similar to functions
◮ allows transaction commit and abort blocks inside procedures
◮ returns no values
◮ commands prohibited in transaction blocks are still
prohibited in procedures, e.g., VACUUM
◮ inner transactions cannot be committed independently of
outer transactions, i.e., no autonomous transactions
◮ Supported languages
◮ PL/pgSQL
◮ PL/Perl
◮ PL/Python
◮ PL/Tcl
◮ SPI
10 / 24
Stored Procedure Example
CREATE TABLE system (status text NOT NULL);
-- no more than one row in the table
CREATE UNIQUE INDEX ON system ((true));
CREATE TABLE customer (name TEXT, sales_monthly_total NUMERIC(10,2));
CREATE TABLE employee (name TEXT, sales_monthly_total NUMERIC(10,2));
11 / 24
Stored Procedure Example
CREATE PROCEDURE end_of_month_processing() AS $$
BEGIN
INSERT INTO system VALUES (’end-of-month processing’)
ON CONFLICT ((true)) DO UPDATE SET status = excluded.status;
-- allow all sessions to see the new status
COMMIT;
UPDATE customer SET sales_monthly_total = 0;
UPDATE employee SET sales_monthly_total = 0;
INSERT INTO system VALUES (’normal operation’)
ON CONFLICT ((true)) DO UPDATE SET STATUS = excluded.status;
-- allow all sessions to see the new status
COMMIT;
-- inform managers only after complete
PERFORM email_managers(’end-of-month processing complete’);
END
$$ LANGUAGE plpgsql;
CALL end_of_month_processing();
12 / 24
Stored Procedure Example
CREATE TABLE web_session (data JSONB, last_active TIMESTAMP WITH TIME ZONE);
-- add five web sessions
INSERT INTO web_session
SELECT ’{"abc": 1}’, CURRENT_TIMESTAMP
FROM generate_series(1, 5);
13 / 24
Stored Procedure Example
CREATE PROCEDURE expire_web_sessions(min_expire INTERVAL) AS $$
DECLARE
rows INTEGER;
BEGIN
WHILE TRUE LOOP
-- clock_timestamp() is updated on every loop
DELETE FROM web_session WHERE last_active < clock_timestamp()-min_expire;
GET DIAGNOSTICS rows = ROW_COUNT;
COMMIT;
RAISE NOTICE ’% rows deleted’, rows;
-- check at half of expiration time
PERFORM pg_sleep(EXTRACT(EPOCH FROM min_expire) / 2);
END LOOP;
END
$$ LANGUAGE plpgsql;
CALL expire_web_sessions(’15 minutes’);
NOTICE: 0 rows deleted
NOTICE: 0 rows deleted
NOTICE: 5 rows deleted
NOTICE: 0 rows deleted
14 / 24
4. Executor-Stage Compilation
utility
Plan
Optimal Path
Query
Generate Plan
Traffic Cop
Generate Paths
Execute Plan
e.g. CREATE TABLE, COPY
SELECT, INSERT, UPDATE, DELETE
Rewrite Query
Parse Statement
Utility
Command
15 / 24
Executor-Stage Compilation
utility
Optimal Path
Query
Plan
Plan with Ojbect Code
Execute Plan
Just−in−Time Compiler
Object Code
Generate Plan
Traffic Cop
Generate Paths
e.g. CREATE TABLE, COPY
SELECT, INSERT, UPDATE, DELETE
Rewrite Query
Parse Statement
Utility
Command
16 / 24
5. Prevent Table Rewrite For ALTER TABLE …
ADD COLUMN with Non-NULL Default
-- Postgres 10
CREATE TABLE alter_test (id SERIAL, name TEXT);
INSERT INTO alter_test (name) SELECT repeat(’x’, 100);
SELECT relfilenode FROM pg_class WHERE relname = ’alter_test’;
relfilenode
-------------
16439
ALTER TABLE alter_test ADD COLUMN col1 INTEGER;
SELECT relfilenode FROM pg_class WHERE relname = ’alter_test’;
relfilenode
-------------
16439
ALTER TABLE alter_test ADD COLUMN col2 INTEGER DEFAULT 1;
SELECT relfilenode FROM pg_class WHERE relname = ’alter_test’;
relfilenode
-------------
16447
17 / 24
Prevent Table Rewrite For ALTER TABLE …
ADD COLUMN with Non-NULL Default
-- Postgres 11
CREATE TABLE alter_test (id SERIAL, name TEXT);
INSERT INTO alter_test (name) SELECT repeat(’x’, 100);
SELECT relfilenode FROM pg_class WHERE relname = ’alter_test’;
relfilenode
-------------
16388
ALTER TABLE alter_test ADD COLUMN col1 INTEGER;
SELECT relfilenode FROM pg_class WHERE relname = ’alter_test’;
relfilenode
-------------
16388
ALTER TABLE alter_test ADD COLUMN col2 INTEGER DEFAULT 1;
SELECT relfilenode FROM pg_class WHERE relname = ’alter_test’;
relfilenode
-------------
16388
18 / 24
6. Finer-Grained Access Control
◮ Superuser-only file system access now controlled by role
membership
◮ pg_read_server_files
◮ pg_write_server_files
◮ pg_execute_server_program
◮ Superuser-only access to file system functions now controlled
by function execute permissions
◮ pg_ls_dir()
◮ pg_read_file()
◮ pg_read_binary_file()
◮ pg_stat_file()
◮ Superuser-only import/export of large objects now controlled
by function execute permissions
◮ lo_import()
◮ lo_export()
19 / 24
7. Write-Ahead Log (WAL) Improvements
◮ Allow WAL file size to be specified via initdb or pg_resetwal
◮ default still 16MB
◮ larger files simplify WAL archiving for active clusters
◮ Halve number of WAL files kept in pg_wal
◮ Zero trailing bytes during forced WAL switch
20 / 24
8. Allow ’quit’ and ’exit’ to Exit Psql
$ psql test
psql (11beta3)
Type "help" for help.
test=> quit
$ psql test
psql (11beta3)
Type "help" for help.
test=> exit
$ psql test
psql (11beta3)
Type "help" for help.
test=> SELECT
test-> quit
Use q to quit.
test-> q
21 / 24
Allow ’quit’ and ’exit’ to Exit Psql
$ psql test
psql (11beta3)
Type "help" for help.
test=> quit
test-> exit
test-> q
$ psql test
psql (11beta3)
Type "help" for help.
test=> SELECT ’
test’> q
Use control-D to quit.
test’> ^D
22 / 24
9. Miscellaneous
◮ Allow unique indexes to contain non-unique columns via
INCLUDE
◮ additional columns can be used for index lookups or
index-only scans
◮ Window function improvements
◮ Add extensions to convert JSONB data to/from PL/Perl and
PL/Python
◮ Add support for large pages on Windows
◮ Allow pg_prewarm to restore previous shared buffer contents
◮ Allow a password prompt for TLS private key access
◮ Sharding advances
23 / 24
Conclusion
http://momjian.us/presentations https://www.flickr.com/photos/8113246@N02/
24 / 24

More Related Content

PPTX
PDF
MySQL shell and It's utilities - Praveen GR (Mydbops Team)
PPTX
PostgreSQL Database Slides
PDF
PostgreSQL 9.5 - Major Features
PDF
Sap basis administrator user guide
PPTX
Oracle Database 12.1.0.2 New Features
PDF
Troubleshooting Complex Performance issues - Oracle SEG$ contention
DOCX
Oracle Database 12c "New features"
MySQL shell and It's utilities - Praveen GR (Mydbops Team)
PostgreSQL Database Slides
PostgreSQL 9.5 - Major Features
Sap basis administrator user guide
Oracle Database 12.1.0.2 New Features
Troubleshooting Complex Performance issues - Oracle SEG$ contention
Oracle Database 12c "New features"

What's hot (20)

PDF
The Top 12 Features new to Oracle 12c
PDF
Presentation oracle net services
PDF
PostgreSQL WAL for DBAs
PDF
Crating a Robust Performance Strategy
PDF
Setup oracle golden gate 11g replication
PPTX
Postgresql Database Administration Basic - Day1
PDF
Get to know PostgreSQL!
PPTX
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
PPTX
Dan Hotka's Top 10 Oracle 12c New Features
PPTX
Ensuring Data Protection Using Oracle Flashback Features - Presentation
PDF
PostgreSQL 9.4, 9.5 and Beyond @ COSCUP 2015 Taipei
PDF
Oracle 12c New Features_RMAN_slides
PDF
Managing terabytes: When PostgreSQL gets big
PDF
PGConf.ASIA 2019 Bali - Upcoming Features in PostgreSQL 12 - John Naylor
PPTX
Best New Features of Oracle Database 12c
PDF
Oracle10g New Features I
PDF
PostgreSQL Table Partitioning / Sharding
PDF
RMAN – The Pocket Knife of a DBA
PDF
Oracle 12c New Features for Developers
PPTX
PostgreSQL Terminology
The Top 12 Features new to Oracle 12c
Presentation oracle net services
PostgreSQL WAL for DBAs
Crating a Robust Performance Strategy
Setup oracle golden gate 11g replication
Postgresql Database Administration Basic - Day1
Get to know PostgreSQL!
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Dan Hotka's Top 10 Oracle 12c New Features
Ensuring Data Protection Using Oracle Flashback Features - Presentation
PostgreSQL 9.4, 9.5 and Beyond @ COSCUP 2015 Taipei
Oracle 12c New Features_RMAN_slides
Managing terabytes: When PostgreSQL gets big
PGConf.ASIA 2019 Bali - Upcoming Features in PostgreSQL 12 - John Naylor
Best New Features of Oracle Database 12c
Oracle10g New Features I
PostgreSQL Table Partitioning / Sharding
RMAN – The Pocket Knife of a DBA
Oracle 12c New Features for Developers
PostgreSQL Terminology
Ad

Similar to Major features postgres 11 (20)

PPT
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
PPTX
Procedures and triggers in SQL
PPT
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
PDF
Performance improvements in PostgreSQL 9.5 and beyond
PPT
MySQL 5.5
PDF
PostgreSQL 9.5 Features
ODP
PostgreSQL 8.4 TriLUG 2009-11-12
PPT
Less04 Instance
PDF
Reducing Risk When Upgrading MySQL
PPTX
DBA Commands and Concepts That Every Developer Should Know
PPTX
Sql and PL/SQL Best Practices I
PPT
Introduction to Parallel Execution
PDF
Dynamic websites lec3
PPT
Intro to tsql
PPT
Intro to tsql unit 14
PDF
Lecture Notes Unit5 chapter17 Stored procedures and functions
PDF
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
PDF
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
PPT
12c Database new features
PPTX
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Procedures and triggers in SQL
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Performance improvements in PostgreSQL 9.5 and beyond
MySQL 5.5
PostgreSQL 9.5 Features
PostgreSQL 8.4 TriLUG 2009-11-12
Less04 Instance
Reducing Risk When Upgrading MySQL
DBA Commands and Concepts That Every Developer Should Know
Sql and PL/SQL Best Practices I
Introduction to Parallel Execution
Dynamic websites lec3
Intro to tsql
Intro to tsql unit 14
Lecture Notes Unit5 chapter17 Stored procedures and functions
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
12c Database new features
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Ad

More from EDB (20)

PDF
Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
 
PDF
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
 
PDF
Migre sus bases de datos Oracle a la nube
 
PDF
EFM Office Hours - APJ - July 29, 2021
 
PDF
Benchmarking Cloud Native PostgreSQL
 
PDF
Las Variaciones de la Replicación de PostgreSQL
 
PDF
NoSQL and Spatial Database Capabilities using PostgreSQL
 
PDF
Is There Anything PgBouncer Can’t Do?
 
PDF
Data Analysis with TensorFlow in PostgreSQL
 
PDF
Practical Partitioning in Production with Postgres
 
PDF
A Deeper Dive into EXPLAIN
 
PDF
IOT with PostgreSQL
 
PDF
A Journey from Oracle to PostgreSQL
 
PDF
Psql is awesome!
 
PDF
EDB 13 - New Enhancements for Security and Usability - APJ
 
PPTX
Comment sauvegarder correctement vos données
 
PDF
Cloud Native PostgreSQL - Italiano
 
PDF
New enhancements for security and usability in EDB 13
 
PPTX
Best Practices in Security with PostgreSQL
 
PDF
Cloud Native PostgreSQL - APJ
 
Cloud Migration Paths: Kubernetes, IaaS, or DBaaS
 
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
 
Migre sus bases de datos Oracle a la nube
 
EFM Office Hours - APJ - July 29, 2021
 
Benchmarking Cloud Native PostgreSQL
 
Las Variaciones de la Replicación de PostgreSQL
 
NoSQL and Spatial Database Capabilities using PostgreSQL
 
Is There Anything PgBouncer Can’t Do?
 
Data Analysis with TensorFlow in PostgreSQL
 
Practical Partitioning in Production with Postgres
 
A Deeper Dive into EXPLAIN
 
IOT with PostgreSQL
 
A Journey from Oracle to PostgreSQL
 
Psql is awesome!
 
EDB 13 - New Enhancements for Security and Usability - APJ
 
Comment sauvegarder correctement vos données
 
Cloud Native PostgreSQL - Italiano
 
New enhancements for security and usability in EDB 13
 
Best Practices in Security with PostgreSQL
 
Cloud Native PostgreSQL - APJ
 

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Spectral efficient network and resource selection model in 5G networks
PPT
Teaching material agriculture food technology
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Tartificialntelligence_presentation.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Empathic Computing: Creating Shared Understanding
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Encapsulation theory and applications.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Big Data Technologies - Introduction.pptx
PPTX
1. Introduction to Computer Programming.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Assigned Numbers - 2025 - Bluetooth® Document
Spectral efficient network and resource selection model in 5G networks
Teaching material agriculture food technology
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Tartificialntelligence_presentation.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Empathic Computing: Creating Shared Understanding
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Network Security Unit 5.pdf for BCA BBA.
Encapsulation theory and applications.pdf
A comparative analysis of optical character recognition models for extracting...
SOPHOS-XG Firewall Administrator PPT.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Big Data Technologies - Introduction.pptx
1. Introduction to Computer Programming.pptx

Major features postgres 11

  • 1. Major Features: Postgres 11 BRUCE MOMJIAN POSTGRESQL is an open-source, full-featured relational database. This presentation gives an overview of the Postgres 11 release. Creative Commons Attribution License http://momjian.us/presentations Last updated: September, 2018 1 / 24
  • 2. Postgres 11 Feature Outline 1. Partitioning improvements 2. Parallelism improvements 3. Stored procedures with transaction control 4. Executor-stage compilation 5. Prevent table rewrite for ALTER TABLE … ADD COLUMN with non-NULL default 6. Finer-grained access control 7. Write-ahead log (WAL) improvements 8. Allow ’quit’ and ’exit’ to exit psql 9. Miscellaneous Full item list at https://www.postgresql.org/docs/devel/static/ release-11.html 2 / 24
  • 3. 1. Partitioning Improvements ◮ Partitioning syntax added in Postgres 10 ◮ simplified administration ◮ Postgres 11 ◮ faster partition pruning during optimization ◮ executor-level partition pruning, e.g., for joins ◮ hash partitioning ◮ move updated rows to new partitions ◮ allow a default partition for non-matching rows ◮ allow unique/primary indexes when the partition key is included, and allow foreign keys to reference them ◮ more items 3 / 24
  • 4. Hash Partitioning Example -- hash partition CREATE TABLE part_test (x int, y text) PARTITION BY hash (x); -- create child partitions CREATE TABLE part_test_0 PARTITION OF part_test FOR VALUES WITH (MODULUS 4, REMAINDER 0); CREATE TABLE part_test_1 PARTITION OF part_test FOR VALUES WITH (MODULUS 4, REMAINDER 1); CREATE TABLE part_test_2 PARTITION OF part_test FOR VALUES WITH (MODULUS 4, REMAINDER 2); CREATE TABLE part_test_3 PARTITION OF part_test FOR VALUES WITH (MODULUS 4, REMAINDER 3); 4 / 24
  • 5. Partitioning Row Migration -- insert 1k rows INSERT INTO part_test SELECT generate_series(0, 999), ’old’; -- What partition contains row zero? SELECT relname FROM pg_class WHERE oid = (SELECT tableoid FROM part_test WHERE x = 0); relname ------------- part_test_0 -- change row zero to row 1003 UPDATE part_test SET x = 1003, y = ’new’ WHERE x = 0; --What partition contains row 1003? Values are hashed twice. SELECT relname FROM pg_class WHERE oid = (SELECT tableoid FROM part_test WHERE x = 1003); relname ------------- part_test_1 5 / 24
  • 6. Partitioning Row Distribution -- How are the rows distributed? SELECT name, y, COUNT(*) FROM part_test, LATERAL ( SELECT relname FROM pg_class WHERE pg_class.oid = part_test.tableoid) AS table_name (name) GROUP BY name, y ORDER BY 1, 2; name | y | count -------------+-----+------- part_test_0 | old | 258 part_test_1 | new | 1 part_test_1 | old | 234 part_test_2 | old | 276 part_test_3 | old | 231 6 / 24
  • 7. Range Partitioning Example -- range partition CREATE TABLE part_test2 (instant TIMESTAMP WITH TIME ZONE, description TEXT) PARTITION BY RANGE (instant); CREATE TABLE part_test2_2017 PARTITION OF part_test2 FOR VALUES FROM (’2017-01-01’) TO (’2018-01-01’); CREATE TABLE part_test2_2018 PARTITION OF part_test2 FOR VALUES FROM (’2018-01-01’) TO (’2019-01-01’); -- create default partition CREATE TABLE part_test2_default PARTITION OF part_test2 DEFAULT; -- add primary key to parent table ALTER TABLE part_test2 ADD PRIMARY KEY (instant); 7 / 24
  • 8. Default Partition -- insert two years of rows INSERT INTO part_test2 SELECT generate_series(’2017-01-01’::timestamptz, ’2018-12-31’, ’1 day’), ’rain’; -- insert rows outside of the defined range INSERT INTO part_test2 VALUES (’2019-02-20’, ’snow’); SELECT name, COUNT(*) FROM part_test2, LATERAL ( SELECT relname FROM pg_class WHERE pg_class.oid = part_test2.tableoid) AS table_name (name) GROUP BY name ORDER BY 1; name | count --------------------+------- part_test2_2017 | 365 part_test2_2018 | 365 part_test2_default | 1 8 / 24
  • 9. 2. Parallelism Improvements ◮ Parallel btree index builds ◮ Parallel hash joins ◮ Parallelize individual SELECTs in UNION ◮ Seven more items 9 / 24
  • 10. 3. Stored Procedures with Transaction Control ◮ Similar to functions ◮ allows transaction commit and abort blocks inside procedures ◮ returns no values ◮ commands prohibited in transaction blocks are still prohibited in procedures, e.g., VACUUM ◮ inner transactions cannot be committed independently of outer transactions, i.e., no autonomous transactions ◮ Supported languages ◮ PL/pgSQL ◮ PL/Perl ◮ PL/Python ◮ PL/Tcl ◮ SPI 10 / 24
  • 11. Stored Procedure Example CREATE TABLE system (status text NOT NULL); -- no more than one row in the table CREATE UNIQUE INDEX ON system ((true)); CREATE TABLE customer (name TEXT, sales_monthly_total NUMERIC(10,2)); CREATE TABLE employee (name TEXT, sales_monthly_total NUMERIC(10,2)); 11 / 24
  • 12. Stored Procedure Example CREATE PROCEDURE end_of_month_processing() AS $$ BEGIN INSERT INTO system VALUES (’end-of-month processing’) ON CONFLICT ((true)) DO UPDATE SET status = excluded.status; -- allow all sessions to see the new status COMMIT; UPDATE customer SET sales_monthly_total = 0; UPDATE employee SET sales_monthly_total = 0; INSERT INTO system VALUES (’normal operation’) ON CONFLICT ((true)) DO UPDATE SET STATUS = excluded.status; -- allow all sessions to see the new status COMMIT; -- inform managers only after complete PERFORM email_managers(’end-of-month processing complete’); END $$ LANGUAGE plpgsql; CALL end_of_month_processing(); 12 / 24
  • 13. Stored Procedure Example CREATE TABLE web_session (data JSONB, last_active TIMESTAMP WITH TIME ZONE); -- add five web sessions INSERT INTO web_session SELECT ’{"abc": 1}’, CURRENT_TIMESTAMP FROM generate_series(1, 5); 13 / 24
  • 14. Stored Procedure Example CREATE PROCEDURE expire_web_sessions(min_expire INTERVAL) AS $$ DECLARE rows INTEGER; BEGIN WHILE TRUE LOOP -- clock_timestamp() is updated on every loop DELETE FROM web_session WHERE last_active < clock_timestamp()-min_expire; GET DIAGNOSTICS rows = ROW_COUNT; COMMIT; RAISE NOTICE ’% rows deleted’, rows; -- check at half of expiration time PERFORM pg_sleep(EXTRACT(EPOCH FROM min_expire) / 2); END LOOP; END $$ LANGUAGE plpgsql; CALL expire_web_sessions(’15 minutes’); NOTICE: 0 rows deleted NOTICE: 0 rows deleted NOTICE: 5 rows deleted NOTICE: 0 rows deleted 14 / 24
  • 15. 4. Executor-Stage Compilation utility Plan Optimal Path Query Generate Plan Traffic Cop Generate Paths Execute Plan e.g. CREATE TABLE, COPY SELECT, INSERT, UPDATE, DELETE Rewrite Query Parse Statement Utility Command 15 / 24
  • 16. Executor-Stage Compilation utility Optimal Path Query Plan Plan with Ojbect Code Execute Plan Just−in−Time Compiler Object Code Generate Plan Traffic Cop Generate Paths e.g. CREATE TABLE, COPY SELECT, INSERT, UPDATE, DELETE Rewrite Query Parse Statement Utility Command 16 / 24
  • 17. 5. Prevent Table Rewrite For ALTER TABLE … ADD COLUMN with Non-NULL Default -- Postgres 10 CREATE TABLE alter_test (id SERIAL, name TEXT); INSERT INTO alter_test (name) SELECT repeat(’x’, 100); SELECT relfilenode FROM pg_class WHERE relname = ’alter_test’; relfilenode ------------- 16439 ALTER TABLE alter_test ADD COLUMN col1 INTEGER; SELECT relfilenode FROM pg_class WHERE relname = ’alter_test’; relfilenode ------------- 16439 ALTER TABLE alter_test ADD COLUMN col2 INTEGER DEFAULT 1; SELECT relfilenode FROM pg_class WHERE relname = ’alter_test’; relfilenode ------------- 16447 17 / 24
  • 18. Prevent Table Rewrite For ALTER TABLE … ADD COLUMN with Non-NULL Default -- Postgres 11 CREATE TABLE alter_test (id SERIAL, name TEXT); INSERT INTO alter_test (name) SELECT repeat(’x’, 100); SELECT relfilenode FROM pg_class WHERE relname = ’alter_test’; relfilenode ------------- 16388 ALTER TABLE alter_test ADD COLUMN col1 INTEGER; SELECT relfilenode FROM pg_class WHERE relname = ’alter_test’; relfilenode ------------- 16388 ALTER TABLE alter_test ADD COLUMN col2 INTEGER DEFAULT 1; SELECT relfilenode FROM pg_class WHERE relname = ’alter_test’; relfilenode ------------- 16388 18 / 24
  • 19. 6. Finer-Grained Access Control ◮ Superuser-only file system access now controlled by role membership ◮ pg_read_server_files ◮ pg_write_server_files ◮ pg_execute_server_program ◮ Superuser-only access to file system functions now controlled by function execute permissions ◮ pg_ls_dir() ◮ pg_read_file() ◮ pg_read_binary_file() ◮ pg_stat_file() ◮ Superuser-only import/export of large objects now controlled by function execute permissions ◮ lo_import() ◮ lo_export() 19 / 24
  • 20. 7. Write-Ahead Log (WAL) Improvements ◮ Allow WAL file size to be specified via initdb or pg_resetwal ◮ default still 16MB ◮ larger files simplify WAL archiving for active clusters ◮ Halve number of WAL files kept in pg_wal ◮ Zero trailing bytes during forced WAL switch 20 / 24
  • 21. 8. Allow ’quit’ and ’exit’ to Exit Psql $ psql test psql (11beta3) Type "help" for help. test=> quit $ psql test psql (11beta3) Type "help" for help. test=> exit $ psql test psql (11beta3) Type "help" for help. test=> SELECT test-> quit Use q to quit. test-> q 21 / 24
  • 22. Allow ’quit’ and ’exit’ to Exit Psql $ psql test psql (11beta3) Type "help" for help. test=> quit test-> exit test-> q $ psql test psql (11beta3) Type "help" for help. test=> SELECT ’ test’> q Use control-D to quit. test’> ^D 22 / 24
  • 23. 9. Miscellaneous ◮ Allow unique indexes to contain non-unique columns via INCLUDE ◮ additional columns can be used for index lookups or index-only scans ◮ Window function improvements ◮ Add extensions to convert JSONB data to/from PL/Perl and PL/Python ◮ Add support for large pages on Windows ◮ Allow pg_prewarm to restore previous shared buffer contents ◮ Allow a password prompt for TLS private key access ◮ Sharding advances 23 / 24