postgresql 9 - 2012.pgday.it€¦ · •postgresql 9.2 •index-only scan •accesso alla...

24
PostgreSQL 9.2 Marco Nenciarini [email protected] http://www.2ndQuadrant.it/ @mnencia venerdì 23 novembre 12

Upload: others

Post on 14-Jun-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

PostgreSQL 9.2

Marco [email protected]

http://www.2ndQuadrant.it/@mnencia

venerdì 23 novembre 12

Page 2: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

Marco Nenciarini•DBA, sviluppatore e sysadmin presso 2ndQuadrant

• Database OLTP business critical

• Data warehousing

•Membro della comunità di PostgreSQL

• Co-Fondatore di ITPUG

•Debian Developer

venerdì 23 novembre 12

Page 3: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

10 09 2012PostgreSQL 9.2

venerdì 23 novembre 12

Page 4: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

Principali novità•Replica in cascata

•Supporto JSON e PL/V8 (Javascript)

•Tipi di dato range

• Indici covering

•Miglioramenti prestazionali

venerdì 23 novembre 12

Page 5: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

Replica in cascata•Standby in grado di agire da server per il protocollo di replica

•pg_basebackup può eseguire backup fisico su un server in standby

venerdì 23 novembre 12

Page 6: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

Esempio di cluster HA

M

S S S

Sync

PostgreSQL 9.1

S

Data Centre 1 Data Centre 2

venerdì 23 novembre 12

Page 7: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

Replica in cascata

M

S

S S

PostgreSQL 9.2

S

Data Centre 1 Data Centre 2

backup

venerdì 23 novembre 12

Page 8: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

JSON e PL/V8•JSON = JavaScript Object

Notation

• Formato per scambio di dati

• Diffusissimo in ambito Web

•Tipo di dato json

• stringhe JSON valide

•Funzioni:

• row_to_json

• array_to_json

•Usato con PL/V8:

• Javascript in Postgres

• indici su JSON?

venerdì 23 novembre 12

Page 9: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

Web App standard

HTML 5Javascript

CSS 3Apps

Postgres

JSON

ResultSet

venerdì 23 novembre 12

Page 10: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

Web App Postgres 9.2

HTML 5Javascript

CSS 3Apps

Postgres

JSON

venerdì 23 novembre 12

Page 11: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

PostgreNoSQL•Stored procedure

•JSON + PL/V8

•XML

•hstore

•PL/Proxy

• sharding (scalabilità infinita)

venerdì 23 novembre 12

Page 12: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

NoSQL con Postgres

HTML 5Javascript

CSS 3Apps

Postgres

PL/Proxy

Postgres PostgresPostgres

“NoSQL”

......

venerdì 23 novembre 12

Page 13: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

Tipo di dato RANGE• Intervallo di valori

consecutivi

• limite incluso [1, 10]

• limite escluso (1,10)

• int4range, int8range, numrange, tsrange, tstzrange, daterange

•Esclusiva di PostgreSQL

•Casi d’uso:

• calendari, planning

• data warehouse

• scientifico

venerdì 23 novembre 12

Page 14: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

Indici covering•MVCC

•PostgreSQL < 9.2

• Ogni index scan in PostgreSQL genera fetch di tuple per controllo visibilità

•PostgreSQL 9.2

• Index-only scan

•accesso alla visibility map

•se tutte le colonne di una SELECT sono presenti in un indice, non c’è più bisogno di accedere alle tuple per la visibilità

•PRO: prestazioni

•CONTRO: dimensione indice

venerdì 23 novembre 12

Page 15: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

Indici

I

I

I

I

I

I

I

I

I

I

I

PostgreSQL 9.1

Heap Visibility

venerdì 23 novembre 12

Page 16: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

Indici covering

I

I

I

I

I

I

I

I

I

I

I

PostgreSQL 9.2

Visibility

venerdì 23 novembre 12

Page 17: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

•Statistiche su deadlock e file temporanei

•pg_stat_activity (state, query, pid)

•pg_tablespace_location()

•pg_stat_statements (normalizzazione query)

•No REINDEX su ALTER COLUMN TYPE

• ...

Amministrazione

venerdì 23 novembre 12

Page 18: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

•Scalabilità lineare su architetture 64 core

•fino a 350.000 query di lettura al secondo (4x)

• "index-only scan" per query nel campo del data warehousing e della business intelligence (20x)

•fino a 14.000 scritture di dati al secondo (5x)

•fino al 30% di riduzione del consumo di CPU

Prestazioni

venerdì 23 novembre 12

Page 19: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

• Statistiche planner su tabelle esterne FDW

• DROP INDEX CONCURRENTLY

• Parametri denominati in funzioni SQL

• Profondità funzioni trigger

• GET STACKED DIAGNOSTICS PL/pgSQL

• ...

• http://www.postgresql.org/about/press/presskit92/it/

Altro

venerdì 23 novembre 12

Page 20: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

•DDL trigger

• Indici su regexp

•pg_dump parallelo

• ...

•Array ELEMENT foreign KEY (9.3?)

Non ce l’hanno fatta

venerdì 23 novembre 12

Page 21: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

CREATE TABLE drivers ( driver_id integer PRIMARY KEY, first_name text, last_name text, ...);

CREATE TABLE races ( race_id integer PRIMARY KEY, title text, race_day DATE, ... practice1_positions integer[] ELEMENT REFERENCES drivers, practice2_positions integer[] ELEMENT REFERENCES drivers, practice3_positions integer[] ELEMENT REFERENCES drivers, qualifying_positions integer[] ELEMENT REFERENCES drivers, final_positions integer[] ELEMENT REFERENCES drivers);

Array Element FK

venerdì 23 novembre 12

Page 22: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

Conclusioni

•DBMS per ambienti business critical

• veloce, consistente, affidabile, sicuro, integrabile, disponibile, recuperabile, ...

• PostgreSQL 9.2

• miglioramenti di prestazioni

• architettura HA/DR flessibile

• integrazione con il web

venerdì 23 novembre 12

Page 23: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

Domande?•[email protected]

•Twitter: @mnencia

•www.2ndQuadrant.it

•blog.2ndQuadrant.it

•www.pgbarman.org

•www.postgresql.org

venerdì 23 novembre 12

Page 24: PostgreSQL 9 - 2012.pgday.it€¦ · •PostgreSQL 9.2 •Index-only scan •accesso alla visibility map •se tutte le colonne di una SELECT sono presenti in un indice, non c’è

Grazie!Licenza Creative Commons BY-NC-SA 3.0

http://creativecommons.org/licenses/by-nc-sa/3.0/it/deed.it

venerdì 23 novembre 12