PostgreSQL's is one of the finest database systems available.
The talk will cover the history, the basic concepts of the PostgreSQL's architecture and the how the community behind the "the most advanced open source database" works.
IT since 1982 Joined the Oracle DBA secret society in 2004 In love with PostgreSQL since 2006 PostgreSQL tattoo on the right shoulder Freelance devops and data engineer Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 2 / 55
or support for your infrastructure, we can help you to improve. Devops PostgreSQL Support Training Audit Migrations https://kamedata.com Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 3 / 55
gargle blaster 3 The Ravenous Bugblatter Beast of Traal 4 Time is an illusion. Lunchtime doubly so 5 Mostly harmless 6 Wrap up Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 4 / 55
BSD-like or MIT-like license. Started by Professor M. Stonebraker at Berkeley Follow up of Ingres hence the chosen name was POSTinGRES Managed by the PostgreSQL Global Development Group (PGDG) A new release each year, latest version is 12 Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 6 / 55
of life date 12 Yes 3 October 2019 14 November 2024 11 Yes 18 October 2018 9 November 2023 10 Yes 5 October 2017 10 November 2022 9.6 Yes 29 September 2016 11 November 2021 9.5 Yes 7 January 2016 11 February 2021 9.4 EOL 18 December 2014 13 February 2020 9.3 No 9 September 2013 8 November 2018 Table: End Of Life (EOL) dates The PostgreSQL project aims to fully support a major release for five years. The policy is applied on a best-effort basis. The complete list of versions is available at https://www.postgresql.org/support/versioning/ Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 7 / 55
minor releases for each supported version. The target date for these releases are, unless otherwise stated, the second Thursday of February, May, August, and November. The current schedule for upcoming releases is: 7th November 2019 13th February 2020 14th May 2020 13th August 2020 The up to date release schedule is available here: https://www.postgresql.org/developer/roadmap/ Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 8 / 55
on almost any unix... And on *cough* MS Windows *cough* Foreign tables Procedural languages (pl/pgsql, pl/python, pl/perl...) Supports for NOSQL data type (HSTORE, JSON) Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 10 / 55
Btree improvements, size, deduplication, vacuum efficiency Statistics, most-common-value statistics for multiple columns CTE inline, no materialisation slowness when using WITH Prepared plan control, it’s possible to determine whether to use the generic or custom execution plan Just-in-time Compilation, rewrites the execution plan for complex queries. Designed to improve analytics queries. Checksum Control, allow to enable/disable the checksums while the cluster is offline REINDEX CONCURRENTLY, allows REINDEX with minimal locking Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 12 / 55
from the PostgreSQL community. Mailing lists organised by topics: https://www.postgresql.org/list/ IRC on freenode: channel #postgresql Slack: https://postgres-slack.herokuapp.com/ Telegram: https://t.me/pg sql The community is informal, friendly and respectful. There is a Code of Conduct to follow https://www.postgresql.org/about/policies/coc/ Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 13 / 55
have a quick look to some of the cool features included in PostgreSQL JSON and JSONB Transaction snapshot exports Table inheritance and partitioning Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 14 / 55
types PostgreSQL have some exotic types. Range types Geometric types Network address types XML type JSON type HSTORE type (extension) Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 16 / 55
datatype in PostgreSQL with two flavours JSON The data is stored as text, parsed and validated when the data is accessed JSONB parsed and converted in binary representation during the insert and update Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 17 / 55
SELECT * from json_each(’{"a":" foo", "b":" bar "}’); key | value -- ---+------- a | "foo" b | "bar" (2 rows) Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 19 / 55
and validated on the fly JSONB is parsed, validated and transformed during INSERT/UPDATE JSONB allows a single index on the field. All the keys are indexed automatically. If you don’t use the json functions in PostgreSQL then just use text Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 20 / 55
IF EXISTS t_jsonb ; DROP TABLE IF EXISTS t_text ; \timing CREATE TABLE t_json as SELECT ’<JSON ELEMENT >’:: json as js_value FROM generate_series (1 ,100000); SELECT 100000 Time: 27350.758 ms (00:27.351) Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 22 / 55
text as t_value FROM generate_series (1 ,100000); SELECT 100000 Time: 29713.060 ms (00:29.713) Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 23 / 55
jsonb as jsb_value FROM generate_series (1 ,100000); SELECT 100000 Time: 27109.003 ms (00:27.109) Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 24 / 55
WHERE relname LIKE ’t\_%’ ; pg_size_pretty | relname -- --------------+--------- 270 MB | t_json 322 MB | t_jsonb 270 MB | t_text (3 rows) JSONB use more space than the json and text1 1Sizing may vary depending on the json size Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 25 / 55
or a transaction access the database for the first time acquires a snapshot which includes the transactions that have been committed at that moment. Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 34 / 55
to other sessions A session which import an exported snapshot sees the same data of the exporting session Useful when multiple sessions need to see a consistent data set frozen in time (e.g. parallel execution) pg dump use this feature to backup the database in parallel Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 35 / 55
text) FROM ( SELECT i_counter FROM generate_series (1 ,200) as i_counter ) t_series; Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 37 / 55
the table inheritance. The table inheritance is a logical relationship between a parent table and its child tables. A child table inherits parent’s attributes. However the physical storage is not shared. Multiple level of inheritance are allowed. Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 42 / 55
tables, the unique constraints can’t be globally enforced on the inheritance tree preventing the creation of any global foreign key. There is no built in mechanism for distributing the data across the child tables. Query optimisation is made via CHECK constraint exclusion which need to be created and maintained. Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 43 / 55
partitioning. Global foreign keys are allowed PostgreSQL to and from the partitioned table. Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 44 / 55
Partitioning: The table is partitioned into “ranges” defined by a key column or set of columns, with no overlap between the ranges of values assigned to different partitions. List Partitioning: The table is partitioned by explicitly listing which key values appear in each partition. Hash Partitioning: The table is partitioned by specifying a modulus and a remainder for each partition. Each partition will hold the rows for which the hash value of the partition key divided by the specified modulus will produce the specified remainder. Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 45 / 55
id integer NOT NULL , value text , CONSTRAINT pk_t_rng_part primary key (id) ) PARTITION BY RANGE (id) ; Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 46 / 55
not inclusive. CREATE TABLE t_rng_part_0001_1000 PARTITION OF t_rng_part FOR VALUES FROM (’0’) TO (’1000 ’); CREATE TABLE t_rng_part_1000_2000 PARTITION OF t_rng_part FOR VALUES FROM (’1000 ’) TO (’2000 ’); CREATE TABLE t_rng_part_2000_3000 PARTITION OF t_rng_part FOR VALUES FROM (’2000 ’) TO (’3000 ’); CREATE TABLE t_rng_part_default PARTITION OF t_rng_part DEFAULT; Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 47 / 55
rules still apply. However there are some differences. CHECK and NOT NULL constraints on a partitioned table are always inherited by all the partitions. CHECK constraints marked as NO INHERIT cannot be created on the partitioned tables. A partitioned table does not have any data directly therefore using TRUNCATE ONLY on a partitioned table will always generate an error. Differently from the table inheritance partitions cannot have columns that are not present in the parent. Is not possible to drop the NOT NULL constraint on a partition’s column if the constraint is present in the parent table. Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 50 / 55
by dan232323 http://dan232323.deviantart.com/art/Pinkie-Pie-Thats-All-Folks-454693000 Federico Campoli (Kamedata) The hitchiker’s guide to PostgreSQL Plone Conf, Ferrara, 24 October 2019 54 / 55