pos tgres q l 1 0 · pos tgres q l 1 0 pgconf.asia 2017 tokyo, japan magnus hagander magn us@ h...

57
PostgreSQL 10 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander [email protected]

Upload: others

Post on 23-Sep-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

PostgreSQL 10PGConf.Asia 2017

Tokyo, Japan

Magnus Hagander [email protected]

Page 2: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

Magnus HaganderRedpill Linpro

Principal database consultantPostgreSQL

Core Team memberCommitterPostgreSQL Europe

Page 3: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

PostgreSQL 10

Page 4: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

A new era of versioning

Page 5: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

Versioning...8.49.0...9.49.59.6

Page 6: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

Versioning9.6

9.6.210

10.11112

Page 7: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

New FeaturesDBA and administrationMonitoringDeveloper and SQL featuresBackup and replicationPerformance

Page 8: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

First things first

Page 9: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et
Page 10: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

The small thingsDrop support for protocol 1.0

(No more clients < 6.3)Drop support for floating point timestamps

Page 11: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

The bigger thingsDirectory pg_xlog is now pg_wal Directory pg_clog is now pg_xact

Page 12: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

Even bigger...pg_switch_xlog() is now pg_switch_wal() pg_xlogfile_name() is now pg_walfile_name() pg_current_xlog*() is now pg_current_wal* pg_last_xlog*() is now pg_last_wal* pg_xlog_location_diff() is nowpg_wal_location_diff()

Page 13: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

One more...pg_receivexlog is now pg_receivewal pg_resetxlog is now pg_resetwal pg_xlogdump is now pg_waldump

Page 14: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

Last one!(not really)

pg_basebackup --xlog-method is now --wal-method pg_basebackup --xlogdir is now --waldir

Page 15: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

OK, some good news

Page 16: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

New FeaturesDBA and administrationMonitoringDeveloper and SQL featuresBackup and replicationPerformance

Page 17: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

SCRAM authenticationSalted Challenge Response AuthenticationStandardized way to do authMore secure than md5!Switch when your clients support it

Page 18: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

libpq enhancementsMultiple hosts can be specified

host=pg1,pg2,pg3 user=bob password=topsecret

Writable host can be requestedhost=pg1,pg2,pg3 target_session_attrs=read-write

Page 19: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

New FeaturesDBA and administrationMonitoringDeveloper and SQL featuresBackup and replicationPerformance

Page 20: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

pg_stat_activitywalsender processes now visible

-[ RECORD 2 ]----+--------------------------------- datid | datname | ... application_name | pg_receivewal ... backend_start | 2017-03-19 16:09:59.842833+01 ... wait_event | WalSenderMain state | active ... backend_type | walsender

Page 21: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

pg_stat_activityBackgrund worker processes now visible!

datid | pid | backend_type | application_name -------+-------+---------------------+---------------------------- 12295 | 18301 | client backend | psql | 17295 | autovacuum launcher | | 17297 | background worker | logical replication launche | 17293 | background writer | | 17292 | checkpointer | | 18615 | walsender | pg_receivewal | 17294 | walwriter | (7 rows)

Page 22: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

New wait eventsLatches

ExtensionsClient/socketTimeout...

I/O eventsReadsWritesIndividually identified

Page 23: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

Monitoring rolesAvoid superuser!

pg_read_all_settingspg_read_all_statspg_stat_scan_tablespg_monitor

Page 24: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

New FeaturesDBA and administrationMonitoringDeveloper and SQL featuresBackup and replicationPerformance

Page 25: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

Transition TablesAccess old and new data in statement triggersAvailable as virtual tables

CREATE TRIGGER mytrigger AFTER UPDATE ON mytable REFERENCING NEW TABLE AS my_new_table OLD TABLE AS my_old_table FOR EACH STATEMENT EXECUTE PROCEDURE foo()

Page 26: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

IDENTITY columnsSame functionality as SERIAL

Minus the permissions gotcha!SQL standard

CREATE TABLE itest ( a int GENERATED BY DEFAULT AS IDENTITY, b int GENERATED ALWAYS AS IDENTITY )

Page 27: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

XMLTABLE(almost) per SQL standardConvert XML document to resultsetMapping XPath etcMuch faster than individual queries

Page 28: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

JSON(b) FTSJSON-aware full text searchWorking ts_headline()

postgres=# SELECT to_tsvector('{"foo": "bar", "baz": 3}'); '3':4 'bar':2 'baz':3 'foo':1

postgres=# SELECT to_tsvector('{"foo": "bar", "baz": 3}'::jsonb); 'bar':1

postgres=# SELECT ts_headline('{"foo": "bar", "baz": 3}', 'foo'); {"<b>foo</b>": "bar", "baz": 3}

postgres=# SELECT ts_headline('{"foo": "bar", "baz": 3}'::jsonb, '{"baz": 3, "foo": "bar"}

Page 29: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

ICU collationsMore choice for collations

Not just OS onesStable across versions

Except ICU major versionsBut those are detected

Page 30: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

ICU collationsSELECT * FROM t ORDER BY a COLLATE "sv-SE-x-icu";

valle vera walle wera

Page 31: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

ICU collationsSELECT * FROM t ORDER BY a COLLATE "sv-SE-u-co-standard-x-icu";

valle walle vera wera

Page 32: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

New FeaturesDBA and administrationMonitoringDeveloper and SQL featuresBackup and replicationPerformance

Page 33: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

New defaultsNew postgresql.conf defaults:

wal_level = replicamax_wal_senders = 10max_replication_slots = 10

New pg_hba.conf defaultsReplication connections by default

Page 34: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

Replication slotsSupport for temporary replication slotsAutomatically dropped at end of sessionPrevents fall-behind with less risk

Page 35: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

pg_basebackupWAL streaming supported in tar mode (-Ft)Better excludesNew defaults

WAL streaming (-X stream) now defaultUses temporary replication slots by default

Page 36: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

Quorum based sync replicationSupport ANY and FIRST modePreviously only FIRST

synchronous_standby_names= FIRST 2 (pg1, pg2, pg3, pg4)

synchronous_standby_names= ANY 2 (pg1, pg2, pg3, pg4)

Page 37: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

Logical replicationBased on WALAnd logical decodingReplicate individual tables

Or sets of tables

Page 38: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

Logical replicationCREATE TABLE testtable (a int PRIMARY KEY, b text);

CREATE PUBLICATION testpub FOR TABLE testtable;

Page 39: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

Logical replicationCREATE TABLE testtable (a int PRIMARY KEY, b text);

CREATE SUBSCRIPTION testsub CONNECTION 'host=/tmp port=5500 dbname=postgres user=mha' PUBLICATION testpub;

Page 40: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

Logical replicationALTER PUBLICATION testpub ADD TABLE anothertable;

ALTER SUBSCRIPTION testsub REFRESH PUBLICATION;

Page 41: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

LimitsNo schema replicationNo sequence replicationNot suitable for fail-over

Page 42: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

Don't forgetUses replication slots

Blocks WAL recyclingAnd VACUUM!

Monitor!!

Page 43: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

New FeaturesDBA and administrationMonitoringDeveloper and SQL featuresBackup and replicationPerformance

Page 44: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

Hash indexesNow WAL logged

So actually usefulMany performance enhancements

Better cachingSupports page-level vacuum...

Sometimes better than btree

Page 45: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

PartitioningBased on existing inheritance

Same as old "manual partitioning"Automatic tuple routing

Easier to useMuch faster on INSERT

More limitations -> more optimizationsMany not there yet

Page 46: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

PartitioningRange partitioningList partitioning

Page 47: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

PartitioningCREATE TABLE testlog (t timestamptz DEFAULT now(), txt text) PARTITION BY RANGE(t);

CREATE TABLE testlog_2017 PARTITION OF testlog (t) FOR VALUES FROM ('2017-01-01') TO ('2018-01-01');

INSERT INTO testlog (txt) VALUES ('test');

Page 48: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

PartitioningCREATE TABLE testcat (category text, txt text) PARTITION BY LIST(category);

CREATE TABLE testcat_cat13 PARTITION OF testcat (category) FOR VALUES IN ('cat1', 'cat2', 'cat3');

INSERT INTO testcat VALUES ('cat1', 'Test1');

Page 49: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

PartitioningStill many limitations

No row-movementNo cross-partition indexesNo cross-partition keysNo partition-wise processingNo tuple routing for foreign partitions

Page 50: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

More parallelism9.6 introduced parallelism

Sequential scansAggregatesHash and loop joins

Page 51: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

UsabilityNew parameter max_parallel_workersquery string now in workers

Shows in pg_stat_activitypid | 28040 ... wait_event_type | Timeout wait_event | PgSleep state | active query | select x, pg_sleep(2000) from tt; backend_type | background worker

Page 52: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

Index scansRegular index scans (btree)Index Only scans (btree)Bitmap Heap Scan

Index still scanned serially

Page 53: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

JoinsMerge joins

Page 54: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

Multi column statisticsCollect statistics across columns

Previously each column individuallyCombinations must be explicitly selected

CREATE STATISTICS test_stats ON b,c FROM test

Collects dependency and n_distinct

Page 55: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

That's a lot!

Page 56: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

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

Page 57: Pos tgreS Q L 1 0 · Pos tgreS Q L 1 0 PGConf.Asia 2017 Tokyo, Japan Magnus Hagander magn us@ h agan der.n et

Thank you!Magnus Hagander

[email protected] @magnushagander

http://www.hagander.net/talks/

This material is licensed