Postgres 9.3
Postgres
OmniTI
RemoteDBA
Postgres Consulting
OVERVIEW
History
- Branch 9.2 ==> 2012-06-01
- Commit Fest 1 --> June 2012
- Commit Fest 2 --> Sept 2012
- Commit Fest 3 --> Nov 2012
- Commit Fest 4 --> Jan 2013
IN THEORY
"Moses Mode"
Changes?
- 1901 Files Changed
- 69730 Additions
- 187838 Deletions
SO WHEN?!?!
- May => 0%
- June => 3%
- July => 21%
- August => 27%
- September => 34%
- October => 14%
September 9th
Outline
- "FOR FREE"
- REPLICATION
- VIEWS
-
TYPES
- FDW
- QUERIES
No Work Required
With every new release, we get performance enhancements that do not require changes to your application. These are changes under the hood that you get
"for free"
No More SYSV Memory
$ 2013-04-28 12:00:33 EDT [6429]: [1-1] FATAL: XX000: could not
create shared memory segment: Cannot allocate memory
2012-04-28 12:00:33 EDT [6429]: [2-1] DETAIL: Failed system call was shmget(key=5432001, size=7700914176, 03600).
2012-04-28 12:00:33 EDT [6429]: [3-1] HINT: This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory or swap space. To reduce the request size (currently 7700914176 bytes), reduce PostgreSQL's shared_buffers parameter (currently 917504) and/or its max_connections parameter (currently 503).
The PostgreSQL documentation contains more information about shared memory configuration.
- move from sysv to mmap
- no more shmmax tom-foolery!
Better CONCURRENCY for FK Locking
OLD:
- UPDATE to parent required "for update" row lock
- UPDATE to child required "for share" row lock
NEW
- UPDATE to parent of NON-Keys == "for no key update"
- UPDATE to child == "for key share"
no blocking unless a foreign key column is changed
Cache Local Locks
speeds lock release at statement completion in transactions that hold many locks
(pg_dump)
(complex queries)
Split "pg_Stat_tmp" File
info now stored:
-
file per database
- global file
Constraint Violation Details
Constraint Violations Now Report Separately
- table
- column
- data type
- constraint name
Replication
- Performance
- Ease of Use
- Enhance Functionality
Fail Fast
- Improve performance of streaming log shipping w/ synchronous commit
- Allow much faster promotion of streaming standby to primary
Easier
- pg_is_in_backup()
- pg_backup_start_time()
- Add checkpoint's last REDO location to pg_controldata output (used to determine WAL files needed for restore)
- Allow tools like pg_receivexlog to run on computers with different architectures
- "pg_basebackup --write-recovery-conf" outputs a minimal recovery.conf
TIMELINE SWITCHING!
Views
-
MALLEABLE
- UPDATEABLE
- MATERIALIZEABLE
UPDATEABLE VIEWS
- "always" been possible using
- rules for insert/delete/update
- triggers (9.1+)
- no longer needed for simple views
- simple == SQL92 definition
- can still create your own if you want (or need)
Materialized Views
- combines rule definition of view (for updating)
- with heap properties of a table (used by planner)
CREATE MATERIALIZED VIEW
- builds copy of table
REFRESH MATERIALIZED VIEW
- rebuilds table
- requires exclusive lock
- play tricks with rename?
Types
changes to types
working with types easier
Large Objects
- increase maximum length of large objects from 2GB to 4TB
-
includes new libpq and server-side 64-bit-enabled functions
JSON operators / Functions
JSON: { "rush":[2,4,6,9] }
- "->", extract data from JSON
SELECT '{"rush":[2,4,6,9]}'::json -> 'rush' -> 2
returns:: 6
- "#>", extract chained data from JSON
SELECT '{"rush":[2,4,6,9]}'::json #> ARRAY['rush','2']
returns:: 6
JSON_OBJECT_KEYS
SELECT * FROM json_object_keys(
'{"name":"dylan","game":"put put","score":[2,1,1,2]}'
);
json_object_keys
----------------
name
game
score
json_each_text
SELECT * FROM json_each_text(
'{"name":"dylan","game":"put put","score":[2,1,1,2]}'
);
key | value
-------+-------
name | dylan
game | put put
score | [2,1,1,2]
lots more JSON!
- json_array_elements
- json_array_length
- json_each
- json_extract_path
- json_populate_recordset
- json_agg
- to_json
- hstore_to_json
- hstore_to_json_loose
Arrays
array_remove
SELECT array_remove('{rick,phil,keith}'::text[],'phil');
returns: {rick,keith}
array_replace
SELECT array_replace('{rick,phil,keith}'::text[],'phil','payal');
returns: {rick,payal,keith}
#syntacticsugar
Foreign data Wrappers
- csv
- oracle
- mysql
- redis
- mongodb
- odbc
- even twitter (!)
POSTGRES FDW
- access remote postgres databases
- supports remote cost estimates
- basic qual pushdown support
- reference implementation
- replaces dblink (but still there)
writable FDW
- ability to write to foreign tables
- insert/update/delete
- transaction aware (!)
- speed can be an issue
NOTE:
- fdw driver implementation specific
- postgres_fdw supports writes
psql
- new commands
- new options
- performance improvements
performance
\Watch [seconds]
\watch SELECT now();
defaults to every 1 second
SELECT now(); \watch 5
runs every n seconds
psql \l *
allows the use of database name patterns in \l
pagila=# \l template*
List of databases
Name | Owner | Encoding | Collate | Ctype |
-----------+----------+----------+-------------+-------------+
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(2 rows)
Lateral Queries
- Attaching SELECT in FROM to sub-SELECT in FROM
SELECT
c.relname, p.increment
FROM
pg_class c,
pg_sequence_parameters(c.oid) p
WHERE
c.relkind = 'S' limit 3
relname | increment --------------------------+----------- actor_actor_id_seq | 1 category_category_id_seq | 1 film_film_id_seq | 1
Lateral Queries For Humans
SELECT
customer_id, rentals
FROM
customer c,
LATERAL(select count(distinct(rental_date)) as rentals
from rental where customer_id = c.customer_id) as x
WHERE
store_id = 1
ORDER BY rentals desc LIMIT 5
first_name | last_name | rentals ------------+-----------+--------- ELEANOR | HUNT | 46 MARCIA | DEAN | 42 CLARA | SHAW | 42 TIM | CARY | 39 DAISY | BATES | 38
event triggers
CREATE OR REPLACE FUNCTION snitch( )
RETURNS event_trigger
AS $$
BEGIN
RAISE NOTICE 'snitch: % %' , tg_event, tg_tag;
END;
$$ LANGUAGE plpgsql;
CREATE EVENT TRIGGER snitch ON ddl_command_start EXECUTE PROCEDURE snitch();
Dev Tools
background Worker Processes
- postmaster subprocesses
- run arbitrary C code
- access shared memory
- use backend database connections
- includes sample implementation
- disconnect automatically idle connections
- customized statistics / logging info
- automated reindex / cluster / etc...
You CoulD ALSO
MORE!
- parallel pg_dump
- parallel pg_upgrade
-
pg_xlogdump
- COPY FREEZE
- page level checksums
- index based regex searches
Additional Resources
http://www.depesz.com/tag/pg93/
http://michael.otacoo.com/tag/9-3/
http://wiki.postgresql.org/wiki/What%27s_new_in_PostgreSQL_9.3
http://wiki.postgresql.org/wiki/PostgreSQL_9.3_Blog_Posts
Quiz
Postgres 9.3
By xzilla
Postgres 9.3
An Overview of New Goodies Coming in Postgres 9.3. Versions of this talk have been delivered at BWPUG May 2013, PGCON 2013, PGConf EU 2013, and PGConf DE 2013.
- 8,160