5. Hello
“for companies who need to build scalable and efficient
web services, OmniTI is the leading cross-disciplinary
provider of consulting, development, and operational
resources to help your company grow”
15% of Alexa Top 100
postgres consulting | web development
Thursday, May 22, 14
11. Performance
reduce WAL for updates
Reduce the size of WAL records generated for UPDATE
operations
Less WAL volume should mean less I/O & resource usage
Thursday, May 22, 14
13. Performance
pg_prewarm
Contrib module for loading relation data into memory.
Can choose from OS cache (async or sync) or
shared_buffers.
SELECT pg_prewarm('actor');
Thursday, May 22, 14
14. Performance
GIN Index improvements
friday @ 4:15 | GIN stronger than ever
compact page format
2x - 10x reduced index size
fast scan improvements
queries w/ some freq. some rare items
Thursday, May 22, 14
15. Performance
separate planning / exec time in EXPLAIN ANALYZE
pagila=#explain analyze select count(*) from payment where payment_date<='2007-02-01'::date;
QUERY PLAN
--------------------------------------------------------------------------------------------
Aggregate (cost=72.26..72.27 rows=1 width=0) (actual time=11.712..11.712 rows=1 loops=1)
-> Append (cost=0.00..69.36 rows=1159 width=0) (actual time=2.256..11.416 rows=1157
loops=1)
-> Seq Scan on payment (cost=0.00..0.00 rows=1 width=0) (actual time=0.002..0.002
rows=0 loops=1)
Filter: (payment_date <= '2007-02-01'::date)
-> Seq Scan on payment_p2007_01 (cost=0.00..23.46 rows=1157 width=0) (actual
time=2.253..5.728 rows=1157 loops=1)
Filter: (payment_date <= '2007-02-01'::date)
-> Seq Scan on payment_p2007_02 (cost=0.00..45.90 rows=1 width=0) (actual
time=5.380..5.380 rows=0 loops=1)
Filter: (payment_date <= '2007-02-01'::date)
Rows Removed by Filter: 2312
Planning time: 140.555 ms
Execution time: 12.562 ms
(11 rows)
Thursday, May 22, 14
16. Performance
add “grouping columns” to EXPLAIN output
pagila=# explain select postal_code, count(*)
pagila-# from address group by postal_code;
QUERY PLAN
----------------------------------------------------------------
HashAggregate (cost=17.05..23.02 rows=597 width=5)
Group Key: postal_code
-> Seq Scan on address (cost=0.00..14.03 rows=603 width=5)
Thursday, May 22, 14
17. Performance
lock wait context
LOG: process 11367 still waiting for ShareLock on transaction 717 after 1000.108 ms
DETAIL: Process holding the lock: 11366. Wait queue: 11367.
CONTEXT: while updating tuple (0,2) in relation "foo"
STATEMENT: UPDATE foo SET value = 3;
Thursday, May 22, 14
19. Administration
ALTER SYSTEM
provide a mechanism to alter system level
configuration from SQL
ALTER SYSTEM SET work_mem='42MB';
SELECT pg_reload_conf();
Thursday, May 22, 14
20. Administration
pset improvements
pagila=# pset
Border style (border) is 1.
Target width (columns) unset.
Expanded display (expanded) is off.
Field separator (fieldsep) is "|".
Default footer (footer) is on.
Output format (format) is aligned.
Line style (linestyle) is ascii.
Null display (null) is "".
Locale-adjusted numeric output (numericlocale) is off.
Pager (pager) is used for long output.
Record separator (recordsep) is <newline>.
Table attributes (tableattr) unset.
Title (title) unset.
Tuples only (tuples_only) is off.
also now works with tab completion
Thursday, May 22, 14
21. Administration
set tablespace options at create time
CREATE TABLESPACE rmd
LOCATION '/ramdisk'
WITH (random_page_cost = 0.9);
use to require create + alter
Thursday, May 22, 14
25. Administration
SSL / TLS improvements
‣ add TLS v1.1/1.2 support
‣ remove SSL v3 support
‣ change default cipher suite to HIGH:!aNULL
‣ HIGH: Contains only secure and well-research algorithms
‣ !aNULL: Needed to disable suites that do not
authenticate server
Thursday, May 22, 14
29. SQL
“moving aggregates”
‣ optimization for aggregates called within moving window of
window function call
‣ initial support for count(), sum(), avg(), stddev(), variance(),
and boolean aggregates
Thursday, May 22, 14
32. SQL
ordered-set aggregates
pagila=# SELECT
count(*), min(amount), max(amount),
percentile_cont(0.5) WITHIN GROUP (ORDER BY
amount)
FROM payment;
count | min | max | percentile_disc
-------+------+-------+-----------------
16049 | 0.00 | 11.99 | 3.99
(1 row)
median amount
Thursday, May 22, 14
33. SQL
ordered-set aggregates
pagila=# SELECT
count(*), min(amount), max(amount),
percentile_cont(array[0.5,0.9])
WITHIN GROUP (ORDER BY amount)
FROM payment;
count | min | max | percentile_disc
-------+------+-------+-----------------
16049 | 0.00 | 11.99 | {3.99,6.99}
(1 row)
Thursday, May 22, 14
36. SQL
FILTER aggregates
pagila=# SELECT customer_id, count(*),
count(*) FILTER (WHERE amount > 5)
FROM payment WHERE customer_id = 148 GROUP BY
customer_id;
customer_id | count | count
-------------+-------+-------
148 | 46 | 13
(1 row)
‣ add support for FILTER clause in aggregates
‣ no more case-then-null / case
Thursday, May 22, 14
38. Backend
plpgsql stack traces
CREATE OR REPLACE FUNCTION
public.inner_func() RETURNS integer AS $$
DECLARE
stack text;
BEGIN
GET DIAGNOSTICS stack = PG_CONTEXT;
RAISE NOTICE E'--- Call Stack ---n%',
stack;
RETURN 1;
END;
$$ LANGUAGE plpgsql;
Thursday, May 22, 14
39. Backend
refresh materialized views concurrently
REFRESH MATERIALIZED VIEW CONCURRENTLY <view>
* requires unique index
Thursday, May 22, 14
40. Backend
“with check” option for auto-updateable views
‣ given an updateable view
‣ only allow visible rows within the view
‣ LOCAL
‣ checking conditions only on the view itself
‣ CASCADE
‣ recursively check on parents (default)
Thursday, May 22, 14
42. Backend
jsonb
new storage format for json text data
“binary json”
pros:
✓no need to re-parse data
✓improved indexing support
✓allows for equality checking
Thursday, May 22, 14
43. Backend
jsonb
new storage format for json text data
“binary json”
pros:
✓no need to re-parse data
✓improved indexing support
✓allows for equality checking
cons:
- whitespace munging
- json/jsonb quirkiness
- more disk space on small
json objects
tomorrow afternoon - morissette 256
Thursday, May 22, 14
44. Backend
jsonb
tomorrow afternoon - morissette 256
json jsonb mongodb
table size 1322MB 1375MB 1666MB
index size 630MB 283MB N/A
single key
index
79MB 58MB 96MB
speed 18.759ms 1.111ms 2ms
https://plus.google.com/+ThomBrownUK/posts/1JizRBGPYBq
Thursday, May 22, 14
45. Backend
recovery target “immediate”
recovery target tells postgres when to launch
- target time, target xid, target name, all
immediate allows start up as soon as
consistent state reached
Thursday, May 22, 14
47. Future
dynamic background workers
9.3 added background workers
available only at startup
9.4 gives you the ability to start
background workers dynamically, from
SQL
Thursday, May 22, 14
49. Future
dynamic shared memory
allows the server to create new shared memory
segments on the fly, for example when
requested by a background worker. also adds
some message passing infrastructure.
not dynamic shared_buffers! :-(
Thursday, May 22, 14