42
PostgreSQL 9.4 and Beyond JSON, Analytics, and More Uptime Technologies Satoshi Nagayasu @snaga FOSSASIA 2015

PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Embed Size (px)

Citation preview

Page 1: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

PostgreSQL 9.4 and BeyondJSON, Analytics, and More

Uptime Technologies

Satoshi Nagayasu@snaga

FOSSASIA 2015

Page 2: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Satoshi Nagayasu• Satoshi Nagayasu

– Database enthusiast. DBA and Data Steward.– Traveling Asia: Hong Kong, Shenzhen, Beijing, Singapore

• Uptime Technologies– Co-founder– Providing consulting services around Database and Platform

Technologies.

• PostgreSQL– pgstatindex, pageinspect, xlogdump– PostgresForest, Postgres-XC (clusters)– Organizing Japanese Users Group.

Page 3: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

What Iʼm doing on PostgreSQL

• Postgres Toolkit– Brand new PostgreSQL DBA tool– Stay informed at uptime.jp/go/pt

• Postgres Add-on for Hinemos– One of the most popular system management tools

in Japan.– Monitoring, Alerting, Job Management, etc.

Page 4: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

PostgreSQL and Hinemos

Number of sessions Database Size

Cache Hit Ratio Number of Written Blocks

Page 5: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Hacking Hardware

RaspberryPi 2&

DE0 (FPGA)

ZigBee(wireless)

Page 6: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Thanks to...• Magnus Hagander• Michael Paquier• Toshi Harada• Noriyoshi Shinoda

• ... and many pg guys!

Page 7: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Agenda• 9.4 Overview• NoSQL (JSON and GIN Index)• Analytics (Aggregation & Mat.View)• Replication and Beyond (Logical

Decoding)• Administration (ALTER SYSTEM)• Infrastructure (For Parallelization)• Beyond 9.4

Page 8: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

9.4 Overview

Page 9: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

9.4 Overview - Status• The first official release.

– 9.4 released on 18th December.

• The latest stable release– 9.4.1 released on 5th February.

Page 10: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

9.4 Overview - Statistics• 9.4.0 - compared to 9.3.5

– 3,750 files changed.– 62,960 insertions (+)– 15,935 deletions (-)

Page 11: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

9.4 Overview - Changes

Page 12: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Server

Indexes

General Performance

Monitoring

SSL

Server Settings

Replication and Recovery

Logical Decoding

Queries

Utility Commands

EXPLAIN

Views

Object Manipulation

Data Types

JSON

Functions

System Information Functions

Aggregates

Server‐Side Languages

PL/pgSQL Server‐Side Language

libpq

Client Applications

psql

Backslash Commands

pg_dump

pg_basebackup

Source Code

Additional Modules

pgbench

pg_stat_statements

9.4 Overview - Changes

Page 13: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Categories of Enhancements• NoSQL (JSON and GIN Index)• Analytics (Aggregation & Mat.View)• Replication+ (Logical Decoding)• Administration (ALTER SYSTEM)• Basic Infrastructure (Parallelization)

Page 14: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

NoSQL(JSON and GIN Index)

Page 15: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

NoSQL - JSONB• JSON vs. JSONB

Page 16: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

NoSQL - JSONB• “Binary JSON”

– Different from JSON, a text representation– Faster for searching

• With JSONB...– No duplicated keys allowed. Last wins.– Key order not preserved.– Can take advantages of GIN Index.

Page 17: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

NoSQL - GIN Index• JSON+btree vs. JSONB+GIN

– Btree indexes vs. GIN index

http://www.slideshare.net/toshiharada/jpug-studyjsonbdatatype20141011-40103981

Table Index Size Comparison

Page 18: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Analytics(Aggregation & Materialized View)

Page 19: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Analytics - Aggregation• FILTER replaces CASE WHEN.

Page 20: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Analytics - Aggregation• New Aggregate Functions

– percentile_cont()– percentile_disc()– mode()– rank()– dense_rank()– percent_rank()– cume_dist()

Page 21: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Analytics - Aggregation• Ordered-set aggregates

– mode(), most common value in a subset

Page 22: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Analytics - Aggregation• Ordered-set aggregates

– rank(), rank of a value in a subset

Page 23: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Analytics – Materialized Views

• REFRESH MATERIALIZED VIEW CONCURRENTLY myview

• Refreshing a MV concurrently (in background) without exclusive lock.

• Usability and availability improved.

Page 24: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Replication and Beyond(Logical Decoding)

Page 25: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Replication and Beyond –Logical Decoding

• “Logical” representation from replication stream– INSERT/UPDATE/DELETE operations– Can be replayed on different version/platform

• pg_recvlogical command– Shows how it works

• Replication can be more flexible– BDR (Bi-Directional Rep.), Slony, and more ...– Continuous Backup as well

Page 26: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

pg_recvlogical (contrib)

Page 27: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Administration(ALTER SYSTEM)

Page 28: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Administration - ALTER SYSTEM

• ALTER SYSTEM SET– puts new value in postgresql.auto.conf– pg_reload_conf() reloads them.– postgresql.auto.conf takes priority over

postgresql.conf.

• ALTER SYSTEM RESET– Remove values from postgresql.auto.conf.

Page 29: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Infrastructure(For Parallelization)

Page 30: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Dynamic Background Workers

• In 9.3, background workers must start at the postmaster startup.

• After 9.4, they can be launched “on-demand” basis.

• From parallelization point of view...– It allows to launch multiple background

processes to execute child queries in parallel.

Page 31: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Dynamic Shared Memory• Shared memory can be allocated “on-demand”

basis– Cf.) by background workers

• Main segment (ex. shared_buffers) still fixed at startup

• Also supports lightweight message queue

• From parallelization point of view...– It allows to share data and communicate with

several bgworker processes.

Page 32: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

My Tiny Favorite(pl/pgsql stacktrace)

Page 33: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

pl/pgsql stacktrace

http://h50146.www5.hp.com/services/ci/opensource/pdfs/PostgreSQL_9_4%20_Ver_1_0.pdf

Page 34: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

There are many other enhancements,

so please try it asap.

Page 35: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Beyond 9.4

Page 36: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

BRIN Index• Block Range INdex

– Holds "summary“ data, instead of raw data.– Reduces index size tremendously.– Also reduces creation/maintenance cost.– Needs extra tuple fetch to get the exact record.

0

50,000

100,000

150,000

200,000

250,000

300,000

Btree BRIN

Elap

sed tim

e (m

s)

Index Creation

0

50,000

100,000

150,000

200,000

250,000

300,000

Btree BRIN

Numbe

r of B

locks

Index Size

0

2

4

6

8

10

12

14

16

18

Btree BRIN

Elap

sed tim

e (m

s)

Select 1 record

https://gist.github.com/snaga/82173bd49749ccf0fa6c

Page 37: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore
Page 38: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Commitfest 2015-2CommitFest is a process to review, fix and commit the submitted patches.

• Parallel Seq Scan• INSERT ... ON CONFLICT {UPDATE | IGNORE}• File level incremental backup• and others..

Still work in progress...

commitfest.postgresql.org

Page 39: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Wrap-up• One of the most developer-friendly

RDBMSes in the world.

• Analytics features and the performance are improving.

• Things are going to parallel.

Page 40: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Resources• www.postgresql.org

• www.planetpostgresql.org

• www.pgcon.org

Page 41: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Any Question?

Page 42: PostgreSQL 9.4 and Beyond @ FOSSASIA 2015 Singapore

Thank you!• E-mail: [email protected]• Twitter, Github: @snaga• WeChat: satoshinagayasu