7. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
PARTITIONNEMENT
Poursuite des efforts dans le partitionnement logique (syntaxe)
Modi cations internes pour plus de performances
8. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
PARTITIONNEMENT
Partitionnement par Hashage
V10 : par RANGE, LIST
V11 : par hashage HASH
9. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
PARTITIONNEMENT
Partitionnement par Hashage
-- PARTITION BY HASH(colonne)
CREATE TABLE tbl (col1 bigserial primary key, val bigint) PARTITION BY HASH (col1);
CREATE TABLE tbl_1 PARTITION OF tbl FOR VALUES WITH (MODULUS 4, REMAINDER 0);
CREATE TABLE tbl_2 PARTITION OF tbl FOR VALUES WITH (MODULUS 4, REMAINDER 1);
CREATE TABLE tbl_3 PARTITION OF tbl FOR VALUES WITH (MODULUS 4, REMAINDER 2);
CREATE TABLE tbl_4 PARTITION OF tbl FOR VALUES WITH (MODULUS 4, REMAINDER 3);
9 / 45
10. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
PARTITIONNEMENT
UPDATE : changement de données entre partitions
CREATE TABLE events (event_ts TIMESTAMPTZ, event_name text) PARTITION BY RANGE (event_ts);
CREATE TABLE events_may PARTITION OF events FOR VALUES
FROM ('2018-05-01T00:00:00.0000') TO ('2018-06-01T00:00:00');
CREATE TABLE events_june PARTITION OF events FOR VALUES
FROM ('2018-06-01T00:00:00.0000') TO ('2018-07-01T00:00:00');
-- Test
INSERT INTO events VALUES ('2018-05-26T09:00:00.0000','PgDay.fr Marseille');
postgres=# select * from events_may;
event_ts | event_name
------------------------+--------------------
2018-05-26 09:00:00+02 | PgDay.fr Marseille
(1 row)
-- Déplacement
UPDATE events SET event_ts='2018-06-26T09:00:00.000' WHERE event_name='PgDay.fr Marseille';
postgres=# select * from events_june;
event_ts | event_name
------------------------+--------------------
2018-06-26 09:00:00+02 | PgDay.fr Marseille
(1 row)
10 / 45
11. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
PARTITIONNEMENT
Propagation des index de la table parente aux partitions
CREATE INDEX events_event_ts_idx ON events(event_ts);
postgres=# d events
Table "public.events"
Column | Type | Collation | Nullable | Default
------------+--------------------------+-----------+----------+---------
event_ts | timestamp with time zone | | |
event_name | text | | |
Partition key: RANGE (event_ts)
Indexes:
"events_event_ts_idx" btree (event_ts)
Number of partitions: 2 (Use d+ to list them.)
postgres=# d events_juin
Table "public.events_juin"
Column | Type | Collation | Nullable | Default
------------+--------------------------+-----------+----------+---------
event_ts | timestamp with time zone | | |
event_name | text | | |
Partition of: events FOR VALUES FROM ('2018-06-01 00:00:00+02')
TO ('2018-07-01 00:00:00+02')
Indexes:
"events_juin_event_ts_idx" btree (event_ts)
11 / 45
12. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
PARTITIONNEMENT
Partition par défaut
CREATE TABLE events_default PARTITION OF events DEFAULT;
INSERT INTO events VALUES ('2018-10-23 09:00:00','PGConf Europe Lisbonne');
postgres=# select * from events_default ;
event_ts | event_name
------------------------+------------------------
2018-10-23 09:00:00+01 | PGConf Europe Lisbonne
(1 row)
postgres=# d events_default
Table "public.events_default"
Column | Type | Collation | Nullable | Default
------------+--------------------------+-----------+----------+---------
event_ts | timestamp with time zone | | |
event_name | text | | |
Partition of: events DEFAULT
Indexes:
"events_default_event_ts_idx" btree (event_ts)
12 / 45
13. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
Clés primaires et étrangères
Clé primaire ou UNIQUE uniquement
si elle comprend la clé de
partitionnement
Clés étrangères prises en charge
Propagation des clés aux partitions
PARTITIONNEMENT
13 / 45
14. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
INSERT ON CONFLICT
Fonctionne également sur les tables
partitionnées
Ne permet pas l'update entre
partitions
PARTITIONNEMENT
14 / 45
15. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
PARTITIONNEMENT
Contrôle des plans d'exécution avec des partitions :
enable_partitionwise_join (off) jointures sur partitions
enable_partitionwise_aggregate (off) agrégats sur partitions
enable_partition_pruning (on) éviction en 2 passes : planner et
executor
15 / 45
16. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
PARTITIONNEMENT
Améliorations dans le moteur de PostgreSQL :
Triggers FOR EACH ROW sur tables partitionnées (seulement AFTER et
sans WHEN)
Prise en charge dans postgres_fdw : le routage s'effectue vers les
partitions étrangères
16 / 45
20. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
PARALLÉLISME / INDEX
Construction parallèle d'index BTree
Index BTree incluant des colonnes "Include"
Possible d'ajouter des statistiques sur une colonne d'index en particulier :
CREATE UNIQUE INDEX terroir_idx ON terroir
USING BTREE (terroir_id) INCLUDE (millesime, cepage);
ALTER INDEX ... ALTER COLUMN <n° colonne> SET STATISTICS 2000;
20 / 45
23. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
JIT
Basée sur LLVM
Pour les gros volumes de données (notamment OLAP)
Fonctionne sur le principe de dépassement de seuils :
jit Active/désactive jit
jit_above_cost Déclenchement jit sur une requête > seuil coût
jit_{inline,optimize}_above_cost Seuils inline et optimisation
23 / 45
24. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
JIT
Sans JIT :
postgres=# EXPLAIN ANALYZE SELECT is_available, COUNT(*) FROM jit_table GROUP BY is_availabl
QUERY PLAN
------------------------------------------------------------------------------------------
...
Planning Time: 0.138 ms
JIT:
Functions: 13
Generation Time: 4.027 ms
Inlining: false
Inlining Time: 0.000 ms
Optimization: false
Optimization Time: 1.356 ms
Emission Time: 43.928 ms
Execution Time: 584.373 ms
(23 rows)
Planning Time: 0.194 ms
Execution Time: 712.831 ms
24 / 45
25. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
TAILLE DES WAL
Taille des WAL dans initdb:
Lors de la création du cluster :
initdb -D mydata --wal-segsize=64
pg_resetwal a aussi l'option
25 / 45
26. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
PG_STAT_STATEMENTS
Le hash queryid passe à 64 bits
26 / 45
27. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
RÉPLICATION
Réplication de TRUNCATE dans la réplication logique (CREATE
PUBLICATION)
27 / 45
29. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
REQUÊTES DE FENÊTRAGE
Support de toutes les options SQL:2011 dans les clauses de fenêtrage
GROUPS et EXCLUDE {CURRENT ROW,GROUP,TIES,NO OTHERS}
29 / 45
30. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
REQUÊTES
LOCK TABLE sur une vue possible
Statistiques sur une fonction dans un index
Possibilité d'indiquer la mise à jour d'un index sur fonction (WITH (
recheck_on_update = on ))
30 / 45
31. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
REQUÊTES
Push down de la clause LIMIT sur les sous-requêtes
Push down des jointures sur UPDATE et DELETE (postgres_fdw)
Possibilité d'indiquer le seuil de passage en TOAST dans un CREATE TABLE
(WITH ( toast_tuple_target = 4096 ))
VACUUM et ANALYZE peuvent prendre plusieurs tables en paramètre.
31 / 45
32. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
JSONB
Interaction jsonb avec PL/Python et PL/Perl
Modules jsonb_plpython{u} et json_plperl
TRANSFORM FOR TYPE jsonb et paramètres de type jsonb
32 / 45
33. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
RECHERCHE TEXTE ET HASHAGE
FTS : websearch_to_tsquery()
JSON/B : json_to_tsvector() et jsonb_to_tsvector()
Opérateur ^@ 'texte' identique à like 'texte%'
Fonctions de hash : sha224(), sha256(), sha384() et sha512()
33 / 45
34. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
PROCÉDURES STOCKÉES ET FONCTIONS
Procédures :
Peuvent contrôler la transaction : COMMIT et ROLLBACK
Appel avec CALL procedure() conforme au standard SQL
Fonctionne dans les autres langages (plpy.commit(),
spi_commit()...)
Nouveau mot clé CONSTANT
SET TRANSACTION dans PL/pgSQL
35. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
ALTER TABLE, COPY ET LOCKS
ALTER TABLE... ADD COLUMN ... DEFAULT non null ne réécrit pas la
table
Nouveaux rôles : pg_{read,write}_server_files pour autoriser
l'utilisation de COPY
Verrouillage au niveau page sur les index GIN GiST et HASH sur prédicat
35 / 45
37. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
PSQL
sf procedure af che le code d'une procédure ou fonction
Ajout des variables :ERROR :SQLSTATE :ROWCOUNT et
:LAST_ERROR_MESSAGE
gdesc af che les colonnes du résultat et leurs types
ET La killer feature : exit et quit : q
=# SELECT id,dt,name FROM (SELECT * FROM jit1 ORDER BY 2) AS a LIMIT 5 gdesc
Column | Type
--------+--------------------------
id | bigint
dt | timestamp with time zone
name | text
(3 rows)
37 / 45
38. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
BACKUP
pg_dump et pg_restore:
Indiquer si on dumpe à partir d'une partition ou d'une table partitionnée
Option --no-comments
pg_dumpall dispose maintenant de l'option d'encodage -E
pg_basebackup
Checksum de validation des backups par défaut dans pg_basebackup
Table "UNLOGGED" et "TEMP" sont exclues du backup
--slot et --create-slot
38 / 45
39. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
POSTGRESQL 12
Pluggable Storage API : zHeap, mais aussi d'autres
MERGE (rejeté en V11 mais INSERT ON CONFLICT)
Plus de parallélisme (encore!)
Plus de JIT !
39 / 45
44. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
All we need is love!
: last friday of July
: 256th day of the year
: rst friday of July
Sysadmin appreciation day
Day of the Programmer
DBA appreciation day
44 / 45
45. LOXODATA
PostgreSQL 11- PgDay.fr 2018 - Marseille - 2018-06-26 - - cc-by-nc@jcarnu jc.arnu@loxodata.com
C'EST FINI !
Vraiment ni ?
Nous recrutons !
QUESTIONS ?
MERCI ! :-)
recrutement@loxodata.com
45 / 45