SlideShare a Scribd company logo
PostgreSQL, The Big, The Fast and The Ugly 
Il piu' avanzato database open source come big data player 
Federico Campoli 
Brandwatch.com 
25 Ottobre 2014 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 1 / 34
Sommario 
1 PostgreSQL, una storia di eccellenza 
2 The Big 
3 The Fast 
4 The Ugly 
5 Conclusioni 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 2 / 34
Sommario 
1 PostgreSQL, una storia di eccellenza 
2 The Big 
3 The Fast 
4 The Ugly 
5 Conclusioni 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 3 / 34
PostgreSQL, una storia di eccellenza 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 4 / 34
PostgreSQL, una storia di eccellenza 
Creato all'universita' di Berkeley nel 1982 dal Prof. Stonebraker 
Nel 1994 Andrew Yu e Jolly Chen aggiungono l'interprete SQL 
Nel 1996 diventa un progetto Open Source prendendo il nome di PostgreSQL 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 5 / 34
PostgreSQL, una storia di eccellenza 
Creato all'universita' di Berkeley nel 1982 dal Prof. Stonebraker 
Nel 1994 Andrew Yu e Jolly Chen aggiungono l'interprete SQL 
Nel 1996 diventa un progetto Open Source prendendo il nome di PostgreSQL 
Totalmente ACID compliant 
Alta scalabilita' con MVCC 
Tablespace 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 5 / 34
PostgreSQL, una storia di eccellenza 
Creato all'universita' di Berkeley nel 1982 dal Prof. Stonebraker 
Nel 1994 Andrew Yu e Jolly Chen aggiungono l'interprete SQL 
Nel 1996 diventa un progetto Open Source prendendo il nome di PostgreSQL 
Totalmente ACID compliant 
Alta scalabilita' con MVCC 
Tablespace 
Disponibile per numerosi unix 
avours 
Dalla versione 8.0 e' nativo su *cough* MS Windows *cough* 
High Availability fornita da hot standby e streaming replication 
Federation verso fonti dati eterogenee 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 5 / 34
PostgreSQL, una storia di eccellenza 
Creato all'universita' di Berkeley nel 1982 dal Prof. Stonebraker 
Nel 1994 Andrew Yu e Jolly Chen aggiungono l'interprete SQL 
Nel 1996 diventa un progetto Open Source prendendo il nome di PostgreSQL 
Totalmente ACID compliant 
Alta scalabilita' con MVCC 
Tablespace 
Disponibile per numerosi unix 
avours 
Dalla versione 8.0 e' nativo su *cough* MS Windows *cough* 
High Availability fornita da hot standby e streaming replication 
Federation verso fonti dati eterogenee 
Numerosi linguaggi procedurali (pl/pgsql, pl/python, pl/perl...) 
Supporto per tipi dato schemaless come HSTORE e JSON 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 5 / 34
PostgreSQL, una storia di eccellenza 
Sviluppo 
Programmato in linguaggio C 
Numerose versioni supportate 
Versioni supportate a lungo termine (almeno 5 anni) 
Espandibile con l'uso di librerie esterne 
Supporto per le estensioni (dalla versione 9.1) 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 6 / 34
PostgreSQL, una storia di eccellenza 
Limiti 
Dimensione massima database. Illimitata. 
Dimensione massima singola tabella, 32 TB 
Dimensione massima singola riga 1.6 TB 
Numero massimo di righe per tabella. Illimitate. 
Numero massimo di campi per tabella, 250 1600 a seconda del tipo dati. 
Numero massimo tabelle. Illimitato. 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 7 / 34
PostgreSQL, una storia di eccellenza 
Insieme ai tipi dato comuni, PostgreSQL fornisce alcuni tipi decisamente esotici. 
Range 
Dati geometrici 
Indirizzi di rete 
XML 
JSON 
HSTORE (extension) 
Gli ultimi due sono oggetto della presentazione in quanto molto popolari 
nell'universo NOSQL. 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 8 / 34
Sommario 
1 PostgreSQL, una storia di eccellenza 
2 The Big 
3 The Fast 
4 The Ugly 
5 Conclusioni 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 9 / 34
The Big 
Image by Caitlin - https://www.
ickr.com/people/50194168@N00 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 10 / 34
The Big 
JSON - JavaScript Object Notation 
JSON supportato come tipo nativo dalla versione 9.2 
La 9.3 introduce numerose funzioni di supporto 
Lo storage e' praticamente testo 
La sintassi JSON viene validata al volo 
La struttura JSON viene gestita dal database 
Dalla versione 9.4 appare JSONB (binario) che migliora notevolmente le 
performance 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 11 / 34
The Big 
JSON - Esempi 
Da record a JSON 
postgres=# SELECT row_to_json(ROW(1,'foo')); 
row_to_json 
--------------------- 
{"f1":1,"f2":"foo"} 
(1 row) 
Espansione di JSON in elementi key to value 
postgres=# SELECT * from json_each('{"a":"foo", "b":"bar"}'); 
key | value 
-----+------- 
a | "foo" 
b | "bar" 
(2 rows) 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 12 / 34
The Big 
HSTORE e' un tipo dato per elementi key to value 
Supportato come estensione 
I dati sono memorizzati come testo 
Una libreria condivisa transforma il testo nel tipo HSTORE 
Simile a json ma senza elementi annidati 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 13 / 34
The Big 
HSTORE - Esempi 
Da record a HSTORE 
postgres=# SELECT hstore(ROW(1,2)); 
hstore 
---------------------- 
"f1"=>"1", "f2"=>"2" 
(1 row) 
Espansione di HSTORE in elementi key to value 
postgres=# SELECT * FROM each('a=>1,b=>2'); 
key | value 
-----+------- 
a | 1 
b | 2 
(2 rows) 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 14 / 34
The Big 
C'e' una dierenza sottile tra HSTORE e JSON. Poiche' HSTORE e' un 
estensione la manipolazione del dato avviene grazie ad una libreria esterna. 
Questo, combinato con il modo in cui PostgreSQL trasforma il datum quando 
viene caricato in memoria, puo avere eetti anche drammatici sulle performance. 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 15 / 34
Sommario 
1 PostgreSQL, una storia di eccellenza 
2 The Big 
3 The Fast 
4 The Ugly 
5 Conclusioni 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 16 / 34
The Fast 
Image by Hein Waschefort - 
http://commons.wikimedia.org/wiki/User:Hein waschefort 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 17 / 34
The Fast 
PostgreSQL memorizza i dati in blocchi di dimensione
ssa chiamate pagine. Ogni 
pagina e' solitamente di 8kb con un header usato per garantire la durabilita'. 
Figure : Data page 
Dopo l'header c'e' una lista di puntatori alle tuple
siche. Ogni tupla e' 
strutturata come un array di dati il cui tipo e' inizialmente sconosciuto. 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 18 / 34
The Fast 
Lo stream di dati in tale stato e' chiamato datum. Una volta caricato in memoria 
PostgreSQL risolve il tipo memorizzato usando il catalogo di sistema. 
Figure : Tuple structure 
Lo header di tupla e' parte dell'implementazione MVCC. 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 19 / 34
The Fast 
Per ogni tupla caricata in memoria il dato viene trasformato da datum a tipo 
reale. Le routine di conversione variano a seconda del tipo eettivo. 
Un elemento nativo come JSON esegue quindi le routine che sono codi
cate 
internamente al motore di database. 
Di contro una trasformazione HSTORE genera un accesso alla libreria esterna per 
ogni tupla esaminata in memoria. 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 20 / 34
The Fast 
Nonostante JSON sia un dato nativo non e' detto che le sue performance siano 
migliori di HSTORE. La validazione e il parsing al volo sono un potenziale 
bottleneck se la quantita' di dati e' importante. 
Questo problema viene risolto dal nuovo tipo binario JSONB introdotto con 
PostgreSQL 9.4. Tutte le routine di validazione e trasformazione avvengono 
durante le DML. 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 21 / 34
Sommario 
1 PostgreSQL, una storia di eccellenza 
2 The Big 
3 The Fast 
4 The Ugly 
5 Conclusioni 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 22 / 34
The Ugly 
Image by D. Gordon E. Robertson - 
http://commons.wikimedia.org/wiki/User:Dger 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 23 / 34
The Ugly 
Un caso reale, Brandwatch 
Social media analytics 
Dati real time e storici 
Core database PostgreSQL 
Big Data!!!!! 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 24 / 34
The Ugly 
Tanto tempo fa in un datacentre lontano lontano...(Ottobre 2012) 
1 database per analytics 
Dimensione di soltanto 1.2 TB 
Struttura denormalizzata 
Storage schemaless con HSTORE 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 25 / 34
The Ugly 
Qualche tempo dopo, Giugno 2014... 
10 shards per l'analisi dei dati 
Dimensione complessiva di 25 TB 
HSTORE e denormalizzazione 
Sistemi costantemente sovraccarichi 
Crescita storage di 300 GB al giorno 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 26 / 34
The Ugly 
Il problema... HSTORE 
Sovraccarica la CPU 
Storage poco eciente 
Dati a volte incoerenti 
Dicile da manutenere 
Estremamente pratico 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 27 / 34
The Ugly 
La soluzione... il buon vecchio storage columnar 
Riduzione dello spazio del 30% 
Carico di CPU ridotto ai minimi termini 
Dati consistenti 
Crescita ridotta a soli 50 GB al giorno 
HSTORE usato solo come input per le procedure 
Apertura a successivi miglioramenti 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 28 / 34
Sommario 
1 PostgreSQL, una storia di eccellenza 
2 The Big 
3 The Fast 
4 The Ugly 
5 Conclusioni 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 29 / 34
Conclusioni 
I dati schemaless sono molto comodi, permettono grande 
essibilita' se 
implementati correttamente. 
L'assenza di scalabilita' orizzontale in PostgreSQL ne limita l'utilizzo se la 
quantita' di dati e' importante. 
Un promettente progetto in tal senso e' PostgreSQL XL - 
http://www.postgres-xl.org/ 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 30 / 34
Domande 
Domande? 
Per favore siate semplici, dopo tutto sono soltanto un elettricista... 
Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 31 / 34

More Related Content

Viewers also liked

Course outline aacsb mba 839_global outsourcing_r kumar
Course outline  aacsb mba 839_global outsourcing_r kumarCourse outline  aacsb mba 839_global outsourcing_r kumar
Course outline aacsb mba 839_global outsourcing_r kumarShashank Gupta
 
My favorite movember mustaches
My favorite movember mustachesMy favorite movember mustaches
My favorite movember mustaches
jaybrock10
 
SISTEMA DE IDENTIDADE VISUAL - SIV - CANNIBAL Sex Shop
SISTEMA DE IDENTIDADE VISUAL - SIV - CANNIBAL Sex ShopSISTEMA DE IDENTIDADE VISUAL - SIV - CANNIBAL Sex Shop
SISTEMA DE IDENTIDADE VISUAL - SIV - CANNIBAL Sex ShopMarcio Lampert
 
Catálogo de loções - Cristal Cosmetic
Catálogo de loções - Cristal CosmeticCatálogo de loções - Cristal Cosmetic
Catálogo de loções - Cristal Cosmeticcatalagocristalcosmetic
 
Catálogo de maquiagens adulto cristal cosmetic
Catálogo de maquiagens adulto   cristal cosmeticCatálogo de maquiagens adulto   cristal cosmetic
Catálogo de maquiagens adulto cristal cosmeticcatalagocristalcosmetic
 

Viewers also liked (8)

Media planning f
Media planning fMedia planning f
Media planning f
 
καστορια
καστοριακαστορια
καστορια
 
Course outline aacsb mba 839_global outsourcing_r kumar
Course outline  aacsb mba 839_global outsourcing_r kumarCourse outline  aacsb mba 839_global outsourcing_r kumar
Course outline aacsb mba 839_global outsourcing_r kumar
 
Media planning
Media planningMedia planning
Media planning
 
My favorite movember mustaches
My favorite movember mustachesMy favorite movember mustaches
My favorite movember mustaches
 
SISTEMA DE IDENTIDADE VISUAL - SIV - CANNIBAL Sex Shop
SISTEMA DE IDENTIDADE VISUAL - SIV - CANNIBAL Sex ShopSISTEMA DE IDENTIDADE VISUAL - SIV - CANNIBAL Sex Shop
SISTEMA DE IDENTIDADE VISUAL - SIV - CANNIBAL Sex Shop
 
Catálogo de loções - Cristal Cosmetic
Catálogo de loções - Cristal CosmeticCatálogo de loções - Cristal Cosmetic
Catálogo de loções - Cristal Cosmetic
 
Catálogo de maquiagens adulto cristal cosmetic
Catálogo de maquiagens adulto   cristal cosmeticCatálogo de maquiagens adulto   cristal cosmetic
Catálogo de maquiagens adulto cristal cosmetic
 

Similar to PostgreSQL, The Big, The Fast and The Ugly

What's Big Data? - Big Data Tech - 2015 - Firenze
What's Big Data? - Big Data Tech - 2015 - FirenzeWhat's Big Data? - Big Data Tech - 2015 - Firenze
What's Big Data? - Big Data Tech - 2015 - Firenze
Alberto Paro
 
SCE2014 - Linked Open Data: come fare, cosa serve
SCE2014 - Linked Open Data: come fare, cosa serve SCE2014 - Linked Open Data: come fare, cosa serve
SCE2014 - Linked Open Data: come fare, cosa serve
Diego Valerio Camarda
 
LOD, SPARQL e dintorni
LOD, SPARQL e dintorniLOD, SPARQL e dintorni
LOD, SPARQL e dintorni
nvitucci
 
Software bill of materials: strumenti e analisi di progetti open source dell’...
Software bill of materials: strumenti e analisi di progetti open source dell’...Software bill of materials: strumenti e analisi di progetti open source dell’...
Software bill of materials: strumenti e analisi di progetti open source dell’...
FedericoBoni3
 
PostgreSQL : Architettura di storage
PostgreSQL : Architettura di storagePostgreSQL : Architettura di storage
PostgreSQL : Architettura di storage
Enrico Pirozzi
 
Da Oracle a PostgreSQL: l'evoluzione dei RDBMS
Da Oracle a PostgreSQL: l'evoluzione dei RDBMSDa Oracle a PostgreSQL: l'evoluzione dei RDBMS
Da Oracle a PostgreSQL: l'evoluzione dei RDBMS
AICQ Comitato Qualità del Software e Servizi ICT
 
Hpc per l'industria 4.0
Hpc per l'industria 4.0Hpc per l'industria 4.0
Hpc per l'industria 4.0
Eric Pascolo
 
Programmazione web libera dai framework
Programmazione web libera dai frameworkProgrammazione web libera dai framework
Programmazione web libera dai framework
Francesca1980
 
Numeri e nomi: il DNS
Numeri e nomi: il DNSNumeri e nomi: il DNS
Numeri e nomi: il DNS
Antonio Prado
 
xVelocity in Deep
xVelocity in DeepxVelocity in Deep
xVelocity in Deep
Marco Pozzan
 
Py a6 python-database
Py a6 python-databasePy a6 python-database
Py a6 python-databaseMajong DevJfu
 

Similar to PostgreSQL, The Big, The Fast and The Ugly (13)

What's Big Data? - Big Data Tech - 2015 - Firenze
What's Big Data? - Big Data Tech - 2015 - FirenzeWhat's Big Data? - Big Data Tech - 2015 - Firenze
What's Big Data? - Big Data Tech - 2015 - Firenze
 
SCE2014 - Linked Open Data: come fare, cosa serve
SCE2014 - Linked Open Data: come fare, cosa serve SCE2014 - Linked Open Data: come fare, cosa serve
SCE2014 - Linked Open Data: come fare, cosa serve
 
PostgreSQL
PostgreSQL PostgreSQL
PostgreSQL
 
LOD, SPARQL e dintorni
LOD, SPARQL e dintorniLOD, SPARQL e dintorni
LOD, SPARQL e dintorni
 
Presentazione
PresentazionePresentazione
Presentazione
 
Software bill of materials: strumenti e analisi di progetti open source dell’...
Software bill of materials: strumenti e analisi di progetti open source dell’...Software bill of materials: strumenti e analisi di progetti open source dell’...
Software bill of materials: strumenti e analisi di progetti open source dell’...
 
PostgreSQL : Architettura di storage
PostgreSQL : Architettura di storagePostgreSQL : Architettura di storage
PostgreSQL : Architettura di storage
 
Da Oracle a PostgreSQL: l'evoluzione dei RDBMS
Da Oracle a PostgreSQL: l'evoluzione dei RDBMSDa Oracle a PostgreSQL: l'evoluzione dei RDBMS
Da Oracle a PostgreSQL: l'evoluzione dei RDBMS
 
Hpc per l'industria 4.0
Hpc per l'industria 4.0Hpc per l'industria 4.0
Hpc per l'industria 4.0
 
Programmazione web libera dai framework
Programmazione web libera dai frameworkProgrammazione web libera dai framework
Programmazione web libera dai framework
 
Numeri e nomi: il DNS
Numeri e nomi: il DNSNumeri e nomi: il DNS
Numeri e nomi: il DNS
 
xVelocity in Deep
xVelocity in DeepxVelocity in Deep
xVelocity in Deep
 
Py a6 python-database
Py a6 python-databasePy a6 python-database
Py a6 python-database
 

More from Federico Campoli

Hitchikers guide handout
Hitchikers guide handoutHitchikers guide handout
Hitchikers guide handout
Federico Campoli
 
Pg chameleon, mysql to postgresql replica made easy
Pg chameleon, mysql to postgresql replica made easyPg chameleon, mysql to postgresql replica made easy
Pg chameleon, mysql to postgresql replica made easy
Federico Campoli
 
pg_chameleon MySQL to PostgreSQL replica made easy
pg_chameleon  MySQL to PostgreSQL replica made easypg_chameleon  MySQL to PostgreSQL replica made easy
pg_chameleon MySQL to PostgreSQL replica made easy
Federico Campoli
 
pg_chameleon a MySQL to PostgreSQL replica
pg_chameleon a MySQL to PostgreSQL replicapg_chameleon a MySQL to PostgreSQL replica
pg_chameleon a MySQL to PostgreSQL replica
Federico Campoli
 
The ninja elephant, scaling the analytics database in Transwerwise
The ninja elephant, scaling the analytics database in TranswerwiseThe ninja elephant, scaling the analytics database in Transwerwise
The ninja elephant, scaling the analytics database in Transwerwise
Federico Campoli
 
The ninja elephant, scaling the analytics database in Transwerwise
The ninja elephant, scaling the analytics database in TranswerwiseThe ninja elephant, scaling the analytics database in Transwerwise
The ninja elephant, scaling the analytics database in Transwerwise
Federico Campoli
 
Pg chameleon MySQL to PostgreSQL replica
Pg chameleon MySQL to PostgreSQL replicaPg chameleon MySQL to PostgreSQL replica
Pg chameleon MySQL to PostgreSQL replica
Federico Campoli
 
Life on a_rollercoaster
Life on a_rollercoasterLife on a_rollercoaster
Life on a_rollercoaster
Federico Campoli
 
PostgreSQL - backup and recovery with large databases
PostgreSQL - backup and recovery with large databasesPostgreSQL - backup and recovery with large databases
PostgreSQL - backup and recovery with large databases
Federico Campoli
 
Backup recovery with PostgreSQL
Backup recovery with PostgreSQLBackup recovery with PostgreSQL
Backup recovery with PostgreSQL
Federico Campoli
 
a look at the postgresql engine
a look at the postgresql enginea look at the postgresql engine
a look at the postgresql engine
Federico Campoli
 
Don't panic! - Postgres introduction
Don't panic! - Postgres introductionDon't panic! - Postgres introduction
Don't panic! - Postgres introduction
Federico Campoli
 
The hitchhiker's guide to PostgreSQL
The hitchhiker's guide to PostgreSQLThe hitchhiker's guide to PostgreSQL
The hitchhiker's guide to PostgreSQL
Federico Campoli
 
Pg big fast ugly acid
Pg big fast ugly acidPg big fast ugly acid
Pg big fast ugly acid
Federico Campoli
 
Streaming replication
Streaming replicationStreaming replication
Streaming replication
Federico Campoli
 
PostgreSql query planning and tuning
PostgreSql query planning and tuningPostgreSql query planning and tuning
PostgreSql query planning and tuning
Federico Campoli
 
PostgreSQL, the big the fast and the (NOSQL on) Acid
PostgreSQL, the big the fast and the (NOSQL on) AcidPostgreSQL, the big the fast and the (NOSQL on) Acid
PostgreSQL, the big the fast and the (NOSQL on) Acid
Federico Campoli
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1
Federico Campoli
 
A couple of things about PostgreSQL...
A couple of things  about PostgreSQL...A couple of things  about PostgreSQL...
A couple of things about PostgreSQL...
Federico Campoli
 

More from Federico Campoli (19)

Hitchikers guide handout
Hitchikers guide handoutHitchikers guide handout
Hitchikers guide handout
 
Pg chameleon, mysql to postgresql replica made easy
Pg chameleon, mysql to postgresql replica made easyPg chameleon, mysql to postgresql replica made easy
Pg chameleon, mysql to postgresql replica made easy
 
pg_chameleon MySQL to PostgreSQL replica made easy
pg_chameleon  MySQL to PostgreSQL replica made easypg_chameleon  MySQL to PostgreSQL replica made easy
pg_chameleon MySQL to PostgreSQL replica made easy
 
pg_chameleon a MySQL to PostgreSQL replica
pg_chameleon a MySQL to PostgreSQL replicapg_chameleon a MySQL to PostgreSQL replica
pg_chameleon a MySQL to PostgreSQL replica
 
The ninja elephant, scaling the analytics database in Transwerwise
The ninja elephant, scaling the analytics database in TranswerwiseThe ninja elephant, scaling the analytics database in Transwerwise
The ninja elephant, scaling the analytics database in Transwerwise
 
The ninja elephant, scaling the analytics database in Transwerwise
The ninja elephant, scaling the analytics database in TranswerwiseThe ninja elephant, scaling the analytics database in Transwerwise
The ninja elephant, scaling the analytics database in Transwerwise
 
Pg chameleon MySQL to PostgreSQL replica
Pg chameleon MySQL to PostgreSQL replicaPg chameleon MySQL to PostgreSQL replica
Pg chameleon MySQL to PostgreSQL replica
 
Life on a_rollercoaster
Life on a_rollercoasterLife on a_rollercoaster
Life on a_rollercoaster
 
PostgreSQL - backup and recovery with large databases
PostgreSQL - backup and recovery with large databasesPostgreSQL - backup and recovery with large databases
PostgreSQL - backup and recovery with large databases
 
Backup recovery with PostgreSQL
Backup recovery with PostgreSQLBackup recovery with PostgreSQL
Backup recovery with PostgreSQL
 
a look at the postgresql engine
a look at the postgresql enginea look at the postgresql engine
a look at the postgresql engine
 
Don't panic! - Postgres introduction
Don't panic! - Postgres introductionDon't panic! - Postgres introduction
Don't panic! - Postgres introduction
 
The hitchhiker's guide to PostgreSQL
The hitchhiker's guide to PostgreSQLThe hitchhiker's guide to PostgreSQL
The hitchhiker's guide to PostgreSQL
 
Pg big fast ugly acid
Pg big fast ugly acidPg big fast ugly acid
Pg big fast ugly acid
 
Streaming replication
Streaming replicationStreaming replication
Streaming replication
 
PostgreSql query planning and tuning
PostgreSql query planning and tuningPostgreSql query planning and tuning
PostgreSql query planning and tuning
 
PostgreSQL, the big the fast and the (NOSQL on) Acid
PostgreSQL, the big the fast and the (NOSQL on) AcidPostgreSQL, the big the fast and the (NOSQL on) Acid
PostgreSQL, the big the fast and the (NOSQL on) Acid
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1
 
A couple of things about PostgreSQL...
A couple of things  about PostgreSQL...A couple of things  about PostgreSQL...
A couple of things about PostgreSQL...
 

PostgreSQL, The Big, The Fast and The Ugly

  • 1. PostgreSQL, The Big, The Fast and The Ugly Il piu' avanzato database open source come big data player Federico Campoli Brandwatch.com 25 Ottobre 2014 Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 1 / 34
  • 2. Sommario 1 PostgreSQL, una storia di eccellenza 2 The Big 3 The Fast 4 The Ugly 5 Conclusioni Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 2 / 34
  • 3. Sommario 1 PostgreSQL, una storia di eccellenza 2 The Big 3 The Fast 4 The Ugly 5 Conclusioni Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 3 / 34
  • 4. PostgreSQL, una storia di eccellenza Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 4 / 34
  • 5. PostgreSQL, una storia di eccellenza Creato all'universita' di Berkeley nel 1982 dal Prof. Stonebraker Nel 1994 Andrew Yu e Jolly Chen aggiungono l'interprete SQL Nel 1996 diventa un progetto Open Source prendendo il nome di PostgreSQL Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 5 / 34
  • 6. PostgreSQL, una storia di eccellenza Creato all'universita' di Berkeley nel 1982 dal Prof. Stonebraker Nel 1994 Andrew Yu e Jolly Chen aggiungono l'interprete SQL Nel 1996 diventa un progetto Open Source prendendo il nome di PostgreSQL Totalmente ACID compliant Alta scalabilita' con MVCC Tablespace Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 5 / 34
  • 7. PostgreSQL, una storia di eccellenza Creato all'universita' di Berkeley nel 1982 dal Prof. Stonebraker Nel 1994 Andrew Yu e Jolly Chen aggiungono l'interprete SQL Nel 1996 diventa un progetto Open Source prendendo il nome di PostgreSQL Totalmente ACID compliant Alta scalabilita' con MVCC Tablespace Disponibile per numerosi unix avours Dalla versione 8.0 e' nativo su *cough* MS Windows *cough* High Availability fornita da hot standby e streaming replication Federation verso fonti dati eterogenee Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 5 / 34
  • 8. PostgreSQL, una storia di eccellenza Creato all'universita' di Berkeley nel 1982 dal Prof. Stonebraker Nel 1994 Andrew Yu e Jolly Chen aggiungono l'interprete SQL Nel 1996 diventa un progetto Open Source prendendo il nome di PostgreSQL Totalmente ACID compliant Alta scalabilita' con MVCC Tablespace Disponibile per numerosi unix avours Dalla versione 8.0 e' nativo su *cough* MS Windows *cough* High Availability fornita da hot standby e streaming replication Federation verso fonti dati eterogenee Numerosi linguaggi procedurali (pl/pgsql, pl/python, pl/perl...) Supporto per tipi dato schemaless come HSTORE e JSON Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 5 / 34
  • 9. PostgreSQL, una storia di eccellenza Sviluppo Programmato in linguaggio C Numerose versioni supportate Versioni supportate a lungo termine (almeno 5 anni) Espandibile con l'uso di librerie esterne Supporto per le estensioni (dalla versione 9.1) Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 6 / 34
  • 10. PostgreSQL, una storia di eccellenza Limiti Dimensione massima database. Illimitata. Dimensione massima singola tabella, 32 TB Dimensione massima singola riga 1.6 TB Numero massimo di righe per tabella. Illimitate. Numero massimo di campi per tabella, 250 1600 a seconda del tipo dati. Numero massimo tabelle. Illimitato. Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 7 / 34
  • 11. PostgreSQL, una storia di eccellenza Insieme ai tipi dato comuni, PostgreSQL fornisce alcuni tipi decisamente esotici. Range Dati geometrici Indirizzi di rete XML JSON HSTORE (extension) Gli ultimi due sono oggetto della presentazione in quanto molto popolari nell'universo NOSQL. Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 8 / 34
  • 12. Sommario 1 PostgreSQL, una storia di eccellenza 2 The Big 3 The Fast 4 The Ugly 5 Conclusioni Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 9 / 34
  • 13. The Big Image by Caitlin - https://www. ickr.com/people/50194168@N00 Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 10 / 34
  • 14. The Big JSON - JavaScript Object Notation JSON supportato come tipo nativo dalla versione 9.2 La 9.3 introduce numerose funzioni di supporto Lo storage e' praticamente testo La sintassi JSON viene validata al volo La struttura JSON viene gestita dal database Dalla versione 9.4 appare JSONB (binario) che migliora notevolmente le performance Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 11 / 34
  • 15. The Big JSON - Esempi Da record a JSON postgres=# SELECT row_to_json(ROW(1,'foo')); row_to_json --------------------- {"f1":1,"f2":"foo"} (1 row) Espansione di JSON in elementi key to value postgres=# SELECT * from json_each('{"a":"foo", "b":"bar"}'); key | value -----+------- a | "foo" b | "bar" (2 rows) Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 12 / 34
  • 16. The Big HSTORE e' un tipo dato per elementi key to value Supportato come estensione I dati sono memorizzati come testo Una libreria condivisa transforma il testo nel tipo HSTORE Simile a json ma senza elementi annidati Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 13 / 34
  • 17. The Big HSTORE - Esempi Da record a HSTORE postgres=# SELECT hstore(ROW(1,2)); hstore ---------------------- "f1"=>"1", "f2"=>"2" (1 row) Espansione di HSTORE in elementi key to value postgres=# SELECT * FROM each('a=>1,b=>2'); key | value -----+------- a | 1 b | 2 (2 rows) Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 14 / 34
  • 18. The Big C'e' una dierenza sottile tra HSTORE e JSON. Poiche' HSTORE e' un estensione la manipolazione del dato avviene grazie ad una libreria esterna. Questo, combinato con il modo in cui PostgreSQL trasforma il datum quando viene caricato in memoria, puo avere eetti anche drammatici sulle performance. Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 15 / 34
  • 19. Sommario 1 PostgreSQL, una storia di eccellenza 2 The Big 3 The Fast 4 The Ugly 5 Conclusioni Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 16 / 34
  • 20. The Fast Image by Hein Waschefort - http://commons.wikimedia.org/wiki/User:Hein waschefort Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 17 / 34
  • 21. The Fast PostgreSQL memorizza i dati in blocchi di dimensione
  • 22. ssa chiamate pagine. Ogni pagina e' solitamente di 8kb con un header usato per garantire la durabilita'. Figure : Data page Dopo l'header c'e' una lista di puntatori alle tuple
  • 23. siche. Ogni tupla e' strutturata come un array di dati il cui tipo e' inizialmente sconosciuto. Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 18 / 34
  • 24. The Fast Lo stream di dati in tale stato e' chiamato datum. Una volta caricato in memoria PostgreSQL risolve il tipo memorizzato usando il catalogo di sistema. Figure : Tuple structure Lo header di tupla e' parte dell'implementazione MVCC. Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 19 / 34
  • 25. The Fast Per ogni tupla caricata in memoria il dato viene trasformato da datum a tipo reale. Le routine di conversione variano a seconda del tipo eettivo. Un elemento nativo come JSON esegue quindi le routine che sono codi
  • 26. cate internamente al motore di database. Di contro una trasformazione HSTORE genera un accesso alla libreria esterna per ogni tupla esaminata in memoria. Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 20 / 34
  • 27. The Fast Nonostante JSON sia un dato nativo non e' detto che le sue performance siano migliori di HSTORE. La validazione e il parsing al volo sono un potenziale bottleneck se la quantita' di dati e' importante. Questo problema viene risolto dal nuovo tipo binario JSONB introdotto con PostgreSQL 9.4. Tutte le routine di validazione e trasformazione avvengono durante le DML. Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 21 / 34
  • 28. Sommario 1 PostgreSQL, una storia di eccellenza 2 The Big 3 The Fast 4 The Ugly 5 Conclusioni Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 22 / 34
  • 29. The Ugly Image by D. Gordon E. Robertson - http://commons.wikimedia.org/wiki/User:Dger Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 23 / 34
  • 30. The Ugly Un caso reale, Brandwatch Social media analytics Dati real time e storici Core database PostgreSQL Big Data!!!!! Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 24 / 34
  • 31. The Ugly Tanto tempo fa in un datacentre lontano lontano...(Ottobre 2012) 1 database per analytics Dimensione di soltanto 1.2 TB Struttura denormalizzata Storage schemaless con HSTORE Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 25 / 34
  • 32. The Ugly Qualche tempo dopo, Giugno 2014... 10 shards per l'analisi dei dati Dimensione complessiva di 25 TB HSTORE e denormalizzazione Sistemi costantemente sovraccarichi Crescita storage di 300 GB al giorno Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 26 / 34
  • 33. The Ugly Il problema... HSTORE Sovraccarica la CPU Storage poco eciente Dati a volte incoerenti Dicile da manutenere Estremamente pratico Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 27 / 34
  • 34. The Ugly La soluzione... il buon vecchio storage columnar Riduzione dello spazio del 30% Carico di CPU ridotto ai minimi termini Dati consistenti Crescita ridotta a soli 50 GB al giorno HSTORE usato solo come input per le procedure Apertura a successivi miglioramenti Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 28 / 34
  • 35. Sommario 1 PostgreSQL, una storia di eccellenza 2 The Big 3 The Fast 4 The Ugly 5 Conclusioni Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 29 / 34
  • 36. Conclusioni I dati schemaless sono molto comodi, permettono grande essibilita' se implementati correttamente. L'assenza di scalabilita' orizzontale in PostgreSQL ne limita l'utilizzo se la quantita' di dati e' importante. Un promettente progetto in tal senso e' PostgreSQL XL - http://www.postgres-xl.org/ Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 30 / 34
  • 37. Domande Domande? Per favore siate semplici, dopo tutto sono soltanto un elettricista... Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 31 / 34
  • 38. Contatti Twitter: 4thdoctor scarf Blog su PostgreSQL: http://www.pgdba.co.uk PostgreSQL Book: http://www.slideshare.net/FedericoCampoli/postgresql-dba-01 Lavoro: http://www.brandwatch.com/ Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 32 / 34
  • 39. Licenza Licenza CC Attribuzione - Non commerciale - Condividi allo stesso modo 3.0 http://creativecommons.org/licenses/by-nc-sa/3.0/it/deed.it Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 33 / 34
  • 40. PostgreSQL, The Big, The Fast and The Ugly Il piu' avanzato database open source come big data player Federico Campoli Brandwatch.com 25 Ottobre 2014 Federico Campoli (Brandwatch.com) PostgreSQL, The Big, The Fast and The Ugly 25 Ottobre 2014 34 / 34