2. Who Am I
● @linuxhiker
● +JoshuaDrakeLinuxHiker
● jd@commandprompt.com
● Lead Consultant – Command Prompt, Inc.
● Director – Software in the Public Interest
● President – United States PostgreSQL
3. 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
4. Help control license costs
If you are selling licenses to software, you are
not helping control license costs.
6. 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
7. 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.
9. 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
11. Community
● Large
● Vibrant
● Active
● All walks of life
● Driven by the ecosystem, not a company
12. 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)
13. 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)
14. Standard Features
● SQL Compliance
● Partitioning
● Replication
● Tablespaces
● ACID
15. AWESOME Stuff
BEGIN;
ALTER TABLE foo ADD COLUMN bar text;
d foo
COMMIT/ROLLBACK;
(Mysql can't do this)
16. 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?
17. It gets better
postgres=# select (a).id from bar;
id
----
1
20. 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)
21. When to use JSON
● Document storage
● Duplicate preservation
● Key order preservation
22. 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)
23. 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) - ?&
25. 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)
26. 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/
27. 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
28. 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/
29. Other 9.4 Stuff
● GIN indexes now faster and smaller
● pg_prewarm
● ALTER SYSTEM
● Concurrent materialized view refresh
● Update Views with different columns
30. 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.
31. 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;