postgresql v9.4features

12
Performance, Reliability, Flexibility – Pick Any Three!

Upload: sameer-kumar

Post on 08-Jul-2015

256 views

Category:

Technology


0 download

DESCRIPTION

This is the presentation used at Dec 2014 Meetup event for Postgres User Group, Singapore. I discussed on key highlight features of v9.4 of PostgreSQL.

TRANSCRIPT

Page 1: PostgreSQL v9.4features

Performance, Reliability, Flexibility – Pick Any Three!

Page 2: PostgreSQL v9.4features

• JSONB- json Binary Storage

• Replication improvements- Replication Slots

• Logical Decoding in WAL log

• Time Lagging Replica

• pg_prewarm

• ALTER SYSTEM Command

• Great new enhancements in aggregation features

Page 3: PostgreSQL v9.4features

Wasn’t JSON was introduced in v9.2? Well it just got better

JSONB is much more optimized and faster for lookup

New functions to extract and manipulate the json data

You have the flexibility without compromising on Reliability!

Non-relational data with ACID compliance!

Page 4: PostgreSQL v9.4features

row_to_json – to convert a row to json

json_object – Create json object out of text array

json_build_object – Create json object out of variadic argument list

array_to_json – to conver an array to JSON

json_each and json_each_text – convert json objects in key-value pair

json_extract_path- Get value of a json object

json_populate_record and json_populate_recordset - Convert json object to records

Page 5: PostgreSQL v9.4features

Operator Operand Type Purpose

-> int Get JSON arrary element

-> text Get JSON object field

->> int Get JSON array element as text

->> text Get JSON object field as text

#> array of text Get JSON object at specified path

#>> array of text Get JSON object at specified path as text

@> jsonb Does the left JSON value contain within it the right value?

<@ jsonb Is the left JSON value contained within the right value?

? text Does the key/element string exist within the JSON value?

?| text[] Do any of these key/element strings exist?

?& text[] Do all of these key/element strings exist?

Page 6: PostgreSQL v9.4features

JSONB in action!

Page 7: PostgreSQL v9.4features

select data from Table as a json object-

SELECT

JSON_BUILD_OBJECT( 'name',name )

FROM books;

Convert a row to json

SELECT ROW_TO_JSON(my_row)

FROM ( SELECT ROW(books.*)

FROM books )my_row;

Page 8: PostgreSQL v9.4features

Select output of join as a json object-

SELECT JSON_BUILD_OBJECT( 'name', name, 'author', name_arr )

FROM(

SELECT ARRAY_AGG( a.name ) AS name_arr, b.name AS name

FROM authors a JOIN author_book_map ab ON a.id=ab.author_id

JOIN books b ON b.id=ab.book_id

GROUP BY b.name ) books_authors_join;

Page 9: PostgreSQL v9.4features

Now you need to guess “wal_keep_segment” to avoid wal files from getting removed

Simply create a replication slot and WAL which are yet not replicated to the slot will not be removed from live WAL location

Time Lagging Replica- You can define a lag period for your replica

This can be used for back-dated reporting

Or recover from a user error – an accidentally dropped table or a truncated table

Page 10: PostgreSQL v9.4features

Set WAL level to ‘logical’ to do more verbose recoding in WAL files

This will also record table and relation level details in each WAL entry

These WAL files can be used for logical decoding and logical replication to replicate changes on a particular table

There are commercial and open source solutions which are in beta stage and are based on this approach

Page 11: PostgreSQL v9.4features

ALTER SYSTEM Command- Now a DBA can alter the configuration with ALTER SYSTEM command and avoid changing it in postgresql.conf

pg_prewarm- now a DBA can load certain relations and blocks in cache after startup and avoid performance issues due to cold-reboot

Page 12: PostgreSQL v9.4features

https://wiki.postgresql.org/wiki/What's_new_in_PostgreSQL_9.4

Hangout Recording for Replication Features in v9.4-https://www.youtube.com/watch?v=-HkrXwaWCb8

EnterpriseDB Whitepaper- http://www.enterprisedb.com/nosql-for-enterprise

http://www.craigkerstiens.com/2014/03/24/Postgres-9.4-Looking-up/

Or just mail me…

[email protected]

[email protected]