+ All Categories
Home > Data & Analytics > An evening with Postgresql

An evening with Postgresql

Date post: 02-Jul-2015
Category:
Upload: joshua-drake
View: 1,222 times
Download: 3 times
Share this document with a friend
Description:
A gentle introduction to PostgreSQL and all that is cool about it. Includes discussion on JSON/JSONB, composite types, replication and community
34
An Evening with PostgreSQL Command Prompt, Inc.
Transcript
Page 1: An evening with Postgresql

An Evening with PostgreSQL

Command Prompt, Inc.

Page 2: An evening with Postgresql

Who Am I

● @linuxhiker

● +JoshuaDrakeLinuxHiker

[email protected]

● Lead Consultant – Command Prompt, Inc.

● Director – Software in the Public Interest

● President – United States PostgreSQL

Page 3: An evening with Postgresql

Rated: Pg-13

● I do this for fun. This is not my day job.

● East Coast from the West Coast

● Your ego is not my concern

● To to take offense is to not be comfortable in oneself.

● Hopefully you laugh and learn

Page 4: An evening with Postgresql

Help control license costs

If you are selling licenses to software, you are not helping control license costs.

Page 5: An evening with Postgresql

Proactive SLA

● Remote DBA / Sysadmin

● Proactive Response

● 4 Hours of DBA (minimum)

● SLA / 24x7 / 365

● No Emergency/After Hours rates

● Flat, discounted rate

From 1350.00/mo

Page 6: An evening with Postgresql

What are we talking about

● What is PostgreSQL?

● Community Structure

● Comparison to other databases

● Awesome PostgreSQL stuff + 9.4 features

● WTH were they thinking!

● Guaranteed not to be in order

Page 7: An evening with Postgresql

What is PostgreSQL?

● The oldest of the open source databases (derived from University Ingres 1974)

● The most advanced Open Source (possibly of closed too) database

● A full ACID compliant, relational, object-relational, document, modern, scalable database.

Page 8: An evening with Postgresql

Community Structure

● Everyone Welcome● Meritocracy● INTL: Postgresql.org● Japan: Postgresql.jp● EU: Postgresql.eu● US: Postgresql.us● Smaller ones (Brazil, France, Italy)

Page 9: An evening with Postgresql

Comparison to other databases

● Licensing● Community● No single point of failure● Feature parity with all databases, more advanced than some

● Best of both worlds, relational or document

Page 10: An evening with Postgresql

Licensing

BSD not GPL

● Important for commercial providers

Page 11: An evening with Postgresql

Community

● Large● Vibrant● Active● All walks of life● Driven by the ecosystem, not a company

Page 12: An evening with Postgresql

No single point of failure

● Can not be bought● Can not go out of business● Can not be co-opted● Many known and qualified support/services

companies (CMD, PgExperts, OmniTI, BullInfoSys, Consistent State, 2nd Quadrant)

Page 13: An evening with Postgresql

Feature Parity

● We have reached a point of... oh PostgreSQL● Like MSSQL, Oracle, Sybase, just another SQL

database but with neat stuff● No longer a fringe product (thanks to Oracle)

Page 14: An evening with Postgresql

Standard Features

● SQL Compliance● Partitioning● Replication● Tablespaces● ACID

Page 15: An evening with Postgresql

AWESOME Stuff

BEGIN;

ALTER TABLE foo ADD COLUMN bar text;

\d foo

COMMIT/ROLLBACK;

(Mysql can't do this)

Page 16: An evening with Postgresql

Craziness

BEGIN;

CREATE TABLE foo (id serial, test text);

CREATE TABLE bar (a foo);

insert into bar values (row(1,'this is a test'));

postgres=# select * from bar;

a

----------------------

(1,"this is a test")

– Say what?

Page 17: An evening with Postgresql

It gets better

postgres=# select (a).id from bar;

id

----

1

Page 18: An evening with Postgresql

Wooohaa!

postgres=# select row_to_json(row((a).id),true) from bar; row_to_json ------------- {"f1":1}

Page 19: An evening with Postgresql

Enough of that, let's talk 9.4

● JSONB● Logical Decoding (Including Logical

Replication)● BDR● Wal Bouncer● Other 9.4 stuff

Page 20: An evening with Postgresql

JSON● Added in 9.2

● Input is validated

● Stored as text representation

– Slower on retrieval due to per row parse (per value?)

● Preserves key order and duplicates

● Mature support in 9.3

– Better Functions

– Operators

● Advanced support in 9.4

– Type building functions

● About 15% storage overhead

● Expression only indexes (WHERE foo)

Page 21: An evening with Postgresql

When to use JSON

● Document storage● Duplicate preservation● Key order preservation

Page 22: An evening with Postgresql

JSONB

● 9.4+

● Full JSON Implementation

● Stored as binary (unlike JSON)

● Works with all JSON operators

● HSTORE-style query operators

● No key order

● No duplicate preservation

● Faster access

● GIN Indexing (and expression), for containment ops use json_path_ops

● About 35% storage overhead

● Much faster than JSON for retrieval (slower than HSTORE)

Page 23: An evening with Postgresql

JSONB Features

● Equality operator

– SELECT '{“a”: 1, “b”: 2}'::jsonb = '{“b”:2, “a”:1}'::jsonb

● Containment operator (Softserve)

– SELECT '{“a”: 1, “b”: 2}'::jsonb @> {“b”:2}::jsonb

● Existence

– SELECT '{“a”: 1, “b”: 2}'::jsonb ? 'b';

● Nested operators (softserve works as well)

– SELECT '{“a”: [1,2]}'::jsonb = '{“a”:[1,2]}'::jsonb

● Existence (any) - ?|

● Existence (all) - ?&

Page 24: An evening with Postgresql

JSON/JSBON thanks

Information retrieved from PDXPUG day in 2014 via David Wheeler

● http://vimeo.com/105491487

Page 25: An evening with Postgresql

Logical Decoding

PostgreSQL provides infrastructure to stream the modifications performed via SQL to external consumers.

The format in which those changes are streamed is determined by the output plugin used.

Every output plugin has access to each individual new row produced by INSERT and the new row version created by UPDATE. Availability of old row versions for UPDATE and DELETE depends on the configured REPLICA IDENTITY.

It is also possible to write additional methods of consuming the output of a replication slot without modifying core code.

(http://www.postgresql.org/docs/9.4/static/logicaldecoding.html)

Page 26: An evening with Postgresql

What does Logical Decoding Mean?

● You now have backend access to INSERT/UPDATE/DELETE mechanisms.

● Is used to implement new features such as:– BDR: https://wiki.postgresql.org/wiki/BDR_User_Guide

– Auditing

– Walbouncer: http://www.cybertec.at/en/products/walbouncer-enterprise-grade-partial-replication/

Page 27: An evening with Postgresql

BDR

● Multi-Master without triggers! (Sorry Bucardo)● Uses LLSR (From Logical Decoding)● Supports distributed Sequences● Supports synchronisation functions● Supports conflict handlers● Highly performant● Eventually consistent● Up to 48 nodes

Page 28: An evening with Postgresql

WalBouncer

● Requires 9.4

● Allows partial replication to remote replicas

– Each replica can have a different data set

● Filters based on WAL

● Single master to many slave

● Can be disconcerting to the novice

● http://www.cybertec.at/postgresql_produkte/walbouncer/

Page 29: An evening with Postgresql

Other 9.4 Stuff

● GIN indexes now faster and smaller● pg_prewarm● ALTER SYSTEM● Concurrent materialized view refresh● Update Views with different columns

Page 30: An evening with Postgresql

ALTER SYSTEM

● Commands such as:– ALTER SYSTEM SET log_min_duration_statement

= '5s';

Are now saved to postgresql.auto.conf which is always read last and saved between restarts.

Page 31: An evening with Postgresql

Better updateable views

CREATE TABLE products (

product_id SERIAL PRIMARY KEY,

product_name TEXT NOT NULL,

quantity INT,

reserved INT DEFAULT 0);

CREATE VIEW products_view AS

SELECT product_id,

product_name,

quantity,

(quantity - reserved) AS available

FROM products

WHERE quantity IS NOT NULL;

Page 32: An evening with Postgresql

Views Continued

postgres=# INSERT INTO products_view (product_name, quantity) VALUES

('Budget laptop', 100),

('Premium laptop', 10);

INSERT 0 2

postgres=# SELECT * FROM products;

product_id | product_name | quantity | reserved

------------+----------------+----------+----------

1 | Budget laptop | 100 | 0

2 | Premium laptop | 10 | 0

(2 rows)

Page 33: An evening with Postgresql

Donate

http://www.postgresql.org/about/donate

Page 34: An evening with Postgresql

Questions?

● Political● Community● Technical● Why the hell not?


Recommended