62
A look at the Elephants Trunk A look at the Elephants Trunk PostgreSQL 12 PostgreSQL 12 Postgres Open 2019 Orlando, FL Magnus Hagander [email protected]

Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

A look at the Elephants TrunkA look at the Elephants Trunk

PostgreSQL 12PostgreSQL 12Postgres Open 2019

Orlando, FL

Magnus [email protected]

Page 2: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

Magnus HaganderMagnus HaganderRedpill Linpro

Principal database consultantPostgreSQL

Core Team memberCommitterPostgreSQL Europe

Page 3: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

PostgreSQL 12PostgreSQL 12

Page 4: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

PostgreSQL 12PostgreSQL 12NOTNOT done yet! done yet!

(almost)

Page 5: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

Development scheduleDevelopment scheduleJuly 2018 - branch 11July 2018 - CF1September 2018 - CF2November 2018 - CF3January 2019 - CF4March 2019 - CF5September 2019 - Beta 4

Page 6: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

Breaking stuff!Breaking stuff!

Page 7: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

Datatype removalDatatype removalabstimereltimetinterval

Page 8: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

Random numbersRandom numbersRemoved support for --disable-strong-random

Page 9: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

(more later)(more later)

Page 10: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

New featuresNew featuresDBA and administrationSQL and developerBackup and replicationPerformance

Page 11: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

psqlpsqlpostgres=# \h vacuum Command: VACUUM Description: garbage-collect and optionally analyze a database Syntax: ... ... URL: https://www.postgresql.org/docs/devel/sql-vacuum.html

Page 12: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

Figures inFigures indocumentationdocumentation

Graphs and stuff!

Page 13: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

New featuresNew featuresDBA and administrationSQL and developerBackup and replicationPerformance

Page 14: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

pg_stat_sslpg_stat_sslAdded columns:

client_serialissuer_dn

Mask data for unprivileged users

Page 15: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

SSL configurationSSL configurationControl min/max SSL version

ssl_min_protocol_version=TLSv1ssl_max_protocol_version=''

Any supported TLS levelTLSv1, TLSv1.1, TLSv1.2, TLSv1.3

Page 16: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

GSSAPI encryptionGSSAPI encryptionEncryption without SSLNo need for certificates etcAssuming GSSAPI already in placepg_stat_gssapi

Page 17: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

VACUUMVACUUMSKIP_LOCKED

Skip any relation not immediately lockableDISABLE_PAGE_SKIPPING

Bypasses visibility mapFor debugging!

Page 18: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

VACUUMVACUUMvacuumdb

--min-xid-age--min-mxid-age

Page 19: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

COPYCOPYCOPY FROM WHERE

COPY mytable (a,b,c) FROM '/tmp/myfile.csv' WITH CSV WHERE a>5

Page 20: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

psqlpsqlCSV output format

postgres=# \pset format csv Output format is csv. postgres=# SELECT * FROM mytable; a,b,c 7,8,9

Page 21: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

pg_stat_statementspg_stat_statementsReset individual query statistics

SELECT pg_stat_statements_reset(queryid => -6363133595459221451);

Page 22: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

Progress monitoringProgress monitoringCREATE INDEXREINDEXCLUSTER

Page 23: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

REINDEXREINDEXCONCURRENTLYCONCURRENTLY

Page 24: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

ChecksumsChecksumsOffline enable/disableProgress report for checking

Page 25: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

Pluggable accessPluggable accessmethodmethodAPI for storage enginesWon't have >1 engine

Yet

Page 26: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

New featuresNew featuresDBA and administrationSQL and developerBackup and replicationPerformance

Page 27: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

WITH OIDSWITH OIDSRemoved!

(but you weren't using it, right?)(deprecated since 2005)

oid is now a regular columnNo more magic!

Page 28: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

Generated columnsGenerated columnsColumns with results of computation

Only STOREDWithout triggers

CREATE TABLE foo ( a int NOT NULL, b int GENERATED ALWAYS AS (a*2) STORED );

Page 29: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

ENUMsENUMsAddition of enum inside transactions

postgres=# BEGIN; postgres=# ALTER TYPE etype ADD VALUE 'foo'; postgres=# ROLLBACK;

Page 30: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

ENUMsENUMsNew restriction

postgres=# BEGIN; postgres=# ALTER TYPE etype ADD VALUE 'foo'; postgres=# SELECT 'foo'::etype; ERROR: unsafe use of new value "foo" of enum type etype

Page 31: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

JSONPATHJSONPATHSQL standard to query JSONNew "query language"Still same indexing!

Page 32: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

JSONPATHJSONPATHNew functions and operatorsNew functions and operators

jsonb_path_exists() (@?)jsonb_path_matches() (@@)jsonb_path_query()...

Page 33: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

JSONPATHJSONPATHSELECT jsonb_path_exists('{"a": 1}', '$.a');SELECT '{"a": 1}'::jsonb @? '$.a'; SELECT jsonb_path_match('{"a": 1}', '$.a == 1');SELECT '{"a": 1}'::jsonb @@ '$.a == 1';

Page 34: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

CTEsCTEsOptimization barrierOr is it?

Page 35: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

CTEsCTEsNew materialization keyword

postgres=# WITH t AS (SELECT * FROM foo), postgres-# t2 AS (SELECT * FROM foo) postgres-# SELECT * FROM t UNION ALL SELECT * FROM t2;

Page 36: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

CTEsCTEsQUERY PLAN ------------------------------------------------------------------ Append (cost=2.02..2.06 rows=2 width=17) CTE t -> Seq Scan on foo (cost=0.00..1.01 rows=1 width=17) CTE t2 -> Seq Scan on foo foo_1 (cost=0.00..1.01 rows=1 width=17) -> CTE Scan on t (cost=0.00..0.02 rows=1 width=17) -> CTE Scan on t2 (cost=0.00..0.02 rows=1 width=17) (7 rows)

Page 37: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

CTEsCTEsNew materialization keyword

postgres=# WITH t AS (SELECT * FROM foo), postgres-# t2 AS MATERIALIZED (SELECT * FROM foo) postgres-# SELECT * FROM t UNION ALL SELECT * FROM t2;

Page 38: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

CTEsCTEspostgres=# EXPLAIN postgres-# WITH t AS (SELECT * FROM foo), postgres-# t2 AS MATERIALIZED (SELECT * FROM foo) postgres-# SELECT * FROM t UNION ALL SELECT * FROM t2; QUERY PLAN ------------------------------------------------------------------ Append (cost=35.50..147.50 rows=5100 width=4) CTE t2 -> Seq Scan on foo foo_1 (cost=0.00..35.50 rows=2550 width= -> Seq Scan on foo (cost=0.00..35.50 rows=2550 width=4) -> CTE Scan on t2 (cost=0.00..51.00 rows=2550 width=4) (5 rows)

Page 39: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

New featuresNew featuresDBA and administrationSQL and developerBackup and replicationPerformance

Page 40: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

max_wal_sendersmax_wal_sendersNo longer part of max_connectionsSeparate settingNow dedicated to wal senders

Page 41: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

recovery.confrecovery.confIntegrated in postgresql.confIn main config, or include file

E.g. postgresql.auto.conf

Page 42: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

recovery.signalrecovery.signalNew "trigger" fileSince recovery.conf doesn't existUpdate your scripts!

Page 43: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

standby.signalstandby.signalNew "trigger" fileFor standby mode

Page 44: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

recovery.confrecovery.confReconfigure with reload only

recovery_min_apply_delayarchive_cleanup_command...

Page 45: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

recovery_target_timelinerecovery_target_timelineNew default: latest

Page 46: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

pg_promote()pg_promote()SQL function to promote standby

Page 47: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

Exclusive base backupsExclusive base backupsEven more deprecated!

Page 48: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

New featuresNew featuresDBA and administrationSQL and developerBackup and replicationPerformance

Page 49: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

SP-GiSTSP-GiSTNow supports KNN searches

Page 50: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

GiST, GIN and SP-GiSTGiST, GIN and SP-GiSTWALWAL

Less WAL generated during index buildFaster and better!

Page 51: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

Detoast compressedDetoast compresseddatumdatum

Partial decompression of TOASTDon't decompress whole Datum when only part is neededUseful for eg postgis

Page 52: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

PartitioningPartitioningMore flexible partition bounds

Generalized expressions

Page 53: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

PartitioningPartitioningLocking delayed until scanCan lead to much faster scans

When many partitions are involvedATTACH without access exclusive lock

Page 54: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

PartitioningPartitioningMulti-inserts for COPY(simply: faster COPY into partitioned tables)

Page 55: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

PartitioningPartitioningForeign keys referencing partitioned tables

When partitioned table has PRIMARY KEY

Page 56: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

SERIALIZABLESERIALIZABLEFor parallel query

Page 57: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

JIT compilationJIT compilationNow enabled by default

Page 58: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

That's a lot!That's a lot!

Page 59: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

There's always moreThere's always moreLots of smaller fixesPerformance improvementsetc, etcCan't mention them all!

Page 60: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

Please help!Please help!

Page 61: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

Please help!Please help!Download and test!

apt packages availablerpm/yum packages availableWindows installers available

Page 62: Pos tgreS Q L 1 2 - Hagander 12.pdf · 2019-09-18 · DBA an d admin is t rat io n SQL an d de v e l o pe r Backu p an d re pl icat io n Pe rfo rman ce. m a x _ wa l _ s end ers N

Thank you!Thank you!Magnus Hagander

[email protected]@magnushagander

https://www.hagander.net/talks/

This material is licensed