9.1 Tour   Mystery           Josh Berkus            pgCon 2011       May 2011, Ottawa
Home                           Replication                               Tools             Synchronous             Replica...
Synchronous Replication
Synchronous Replication
Synchronous Replicationstandby Paul:primary_conninfo = host=john port=5432 user=replication application_name=paulmaster Jo...
Synchronous Replicationpostgres=# select application_name as appname, state,sync_state, sync_priority as prty, replay_loca...
Transaction Control# set synchronous_commit = on;# begin;# update user_balance# set balance = balance - 300# where user = ...
Transaction Control#   set synchronous_commit = local;#   insert into user_messages#   values ( 14301, 13221,#   hello a/s...
New Replication Tools●   pg_stat_replication view    ●   shows all replicas and their statuses●   pg_basebackup    ●   sin...
Per-Column CollationsID     english       日本語787    error         エラー12     unique        ユニークな456    index         インデックス...
Per-Column Collations$ create table collated_polish (some_texttext collate "pl_PL.utf8");$ copy collated_polish from /tmp/...
Psycadelic Queries
Writable CTEsWITH deleted_posts AS (  DELETE FROM posts  WHERE created < now()     - 6 months::INTERVAL  RETURNING *)SELEC...
See                                     T           Writable CTEs                 he                                      ...
Serialized Snapshot              Isolation●   Allows true serialization of concurrent    transactions●   No more explicit ...
See                                   T                SSI                    he                                          ...
Unlogged TablesCREATE UNLOGGED TABLEcleaned_log_importAS SELECT hit_time, pageFROM raw_hits, hit_watermarkWHERE hit_time >...
SE-Postgres●   Now a contrib module!    ●   uses “hooks” enabled at build time●   Integrates with SE-Linux    ●   SE-Linux...
SE-Postgres
See                  TSE-Postgres           he                         T   alk                                 !
K-Nearest Neighbor
K-Nearest NeighborSELECT *,  position <-> $my_current_location  as distanceFROM ben_n_jerryORDER BY position <-> $my_curre...
SQL-MEDFDR      FDRFDR
SQL-MEDCREATE FOREIGN TABLE raw_hits( hit_time TIMESTAMP,  page TEXT )SERVER file_fdwOPTIONS (format csv, delimiter;, file...
See                                T           SQL-MED                  he                                       T   alk  ...
Extensions
ExtensionsCREATE EXTENSION IF NOT EXISTS citextWITH SCHEMA ext;dxSchema | Name   | Version   | Description-------+--------...
ExtensionsALTER EXTENSION citext UPDATE TO 9.2;DROP EXTENSION citext;
See                 TExtensions           he                        T   alk                                !
Other Features●   PL/Python overhaul●   Valid-on-creation Foreign Keys●   Extensible ENUMs●   Triggers on Views●   New Tri...
9.1 Sessions at pgCon●   Real Federation Database System leveraging    PostgreSQL FDW - Thursday 13:30●   Label-based Mand...
Contact●   Josh Berkus: josh@pgexperts.com    ●   blog: blogs.ittoolbox.com/database/soup●   PostgreSQL: www.postgresql.or...
Upcoming SlideShare
Loading in …5
×

9.1 Mystery Tour

1,466 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,466
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
2
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

9.1 Mystery Tour

  1. 1. 9.1 Tour Mystery Josh Berkus pgCon 2011 May 2011, Ottawa
  2. 2. Home Replication Tools Synchronous Replication Per-Column CollationsOtherFeatures SE-Postgres wCTEsExtensions SSI K-Nearest Neighbor SQL/MED Unlogged Tables
  3. 3. Synchronous Replication
  4. 4. Synchronous Replication
  5. 5. Synchronous Replicationstandby Paul:primary_conninfo = host=john port=5432 user=replication application_name=paulmaster John:synchronous_commit = onsynchronous_standby_names = paul,george,ringo
  6. 6. Synchronous Replicationpostgres=# select application_name as appname, state,sync_state, sync_priority as prty, replay_locationfrom pg_stat_replication; appname | state | sync_state | prty | replay_loc---------+-----------+------------+------+------------ paul | STREAMING | SYNC | 1 | 0/29154EB8 george | STREAMING | POTENTIAL | 2 | 0/291452F0 ringo | STREAMING | POTENTIAL | 3 | 0/29154EB8
  7. 7. Transaction Control# set synchronous_commit = on;# begin;# update user_balance# set balance = balance - 300# where user = 14301;# update user_balance# set balance = balance + 300# where user = 13221;# commit;
  8. 8. Transaction Control# set synchronous_commit = local;# insert into user_messages# values ( 14301, 13221,# hello a/s/l? );
  9. 9. New Replication Tools● pg_stat_replication view ● shows all replicas and their statuses● pg_basebackup ● single-command cloning over port 5432● re-mastering ● promote a replica to be the new master● new functions ● pg_last_xact_replay_timestamp() ● pg_xlog_replay_pause()
  10. 10. Per-Column CollationsID english 日本語787 error エラー12 unique ユニークな456 index インデックス333 documentation ドキュメンテーション217 open source オープンソース2134 penguin ペンギン
  11. 11. Per-Column Collations$ create table collated_polish (some_texttext collate "pl_PL.utf8");$ copy collated_polish from /tmp/polish;$ select * from collated_polish order bysome_text;some_text-----------alfacarcośćmalamałódka
  12. 12. Psycadelic Queries
  13. 13. Writable CTEsWITH deleted_posts AS ( DELETE FROM posts WHERE created < now() - 6 months::INTERVAL RETURNING *)SELECT user_id, count(*) FROMdeleted_posts group BY 1;
  14. 14. See T Writable CTEs he T alkWITH deleted_posts AS ( ! DELETE FROM posts WHERE created < now() - 6 months::INTERVAL RETURNING *),deleted_per_user as ( SELECT user_id, count(*) FROM deleted_posts GROUP BY 1)UPDATE countsSET posts_count = posts_count - d.countFROM deleted_per_user dWHERE d.user_id = counts.user_id;
  15. 15. Serialized Snapshot Isolation● Allows true serialization of concurrent transactions● No more explicit locking!● No more deadlocks!● As long as each transaction works, all will work.● Including limited predicate locking.
  16. 16. See T SSI he T alkupdate othello set !pieces = white update othello setwhere pieces = pieces = blackblack; where pieces = white; commit;commit;ERROR: could notserialize accessdue to read/writedependencies amongtransactions
  17. 17. Unlogged TablesCREATE UNLOGGED TABLEcleaned_log_importAS SELECT hit_time, pageFROM raw_hits, hit_watermarkWHERE hit_time > last_watermark AND is_valid(page);
  18. 18. SE-Postgres● Now a contrib module! ● uses “hooks” enabled at build time● Integrates with SE-Linux ● SE-Linux “security labels” become object permissions ● covers all database object permissions● row-level access control not implemented yet
  19. 19. SE-Postgres
  20. 20. See TSE-Postgres he T alk !
  21. 21. K-Nearest Neighbor
  22. 22. K-Nearest NeighborSELECT *, position <-> $my_current_location as distanceFROM ben_n_jerryORDER BY position <-> $my_current_locationLIMIT 3;
  23. 23. SQL-MEDFDR FDRFDR
  24. 24. SQL-MEDCREATE FOREIGN TABLE raw_hits( hit_time TIMESTAMP, page TEXT )SERVER file_fdwOPTIONS (format csv, delimiter;, filename /var/log/hits.log);
  25. 25. See T SQL-MED he T alk !SELECT page, count(*)FROM raw_hitsWHERE hit_time > 2011-04-16 16:00:00 AND hit_time <= 2011-04-16 17:00:00GROUP BY page;
  26. 26. Extensions
  27. 27. ExtensionsCREATE EXTENSION IF NOT EXISTS citextWITH SCHEMA ext;dxSchema | Name | Version | Description-------+--------+----------+------------ext | citext | 9.1devel | case- insensitive character string type
  28. 28. ExtensionsALTER EXTENSION citext UPDATE TO 9.2;DROP EXTENSION citext;
  29. 29. See TExtensions he T alk !
  30. 30. Other Features● PL/Python overhaul● Valid-on-creation Foreign Keys● Extensible ENUMs● Triggers on Views● New Trigram implementation● Reduced NUMERIC size● ALTER TYPE without rewrite● pg_dump directory format
  31. 31. 9.1 Sessions at pgCon● Real Federation Database System leveraging PostgreSQL FDW - Thursday 13:30● Label-based Mandatory Access Control: Friday 10:00● Writeable CTEs: Friday 11:00● Distributing Extensions on PGXN: Friday 15:00● Extensions Development: Friday 16:00● Serializable Snapshot Isolation: Friday 16:00
  32. 32. Contact● Josh Berkus: josh@pgexperts.com ● blog: blogs.ittoolbox.com/database/soup● PostgreSQL: www.postgresql.org ● pgexperts: www.pgexperts.com● Upcoming Events ● pgOpen: September 14-16, Chicago ● OpenSourceBridge: Portland, June This talk is copyright 2010 Josh Berkus and is licensed under the creative commons attribution license. Special thanks for materials to: Hubert Lubaczewski (wCTE, collation examples), Andrew Dunstan (file_FDW)

×