Download - 9.1 Mystery Tour
![Page 1: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/1.jpg)
9.1MysteryTour
Josh BerkuspgCon 2011
May 2011, Ottawa
![Page 2: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/2.jpg)
Home
SynchronousReplication
ReplicationTools
Per-ColumnCollations
wCTEsSE-Postgres
SSI
UnloggedTables
SQL/MED
K-NearestNeighbor
Extensions
OtherFeatures
![Page 3: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/3.jpg)
Synchronous Replication
![Page 4: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/4.jpg)
Synchronous Replication
![Page 5: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/5.jpg)
Synchronous Replicationstandby Paul:primary_conninfo = 'host=john port=5432 user=replication application_name=paul'
master John:synchronous_commit = onsynchronous_standby_names = 'paul,george,ringo'
![Page 6: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/6.jpg)
Synchronous Replicationpostgres=# select application_name as appname, state, sync_state, sync_priority as prty, replay_location from 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
![Page 7: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/7.jpg)
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;
![Page 8: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/8.jpg)
Transaction Control
# set synchronous_commit = 'local';# insert into user_messages # values ( 14301, 13221, # 'hello a/s/l?' );
![Page 9: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/9.jpg)
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()
![Page 10: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/10.jpg)
Per-Column Collations
ID english 日本語787 error エラー12 unique ユニークな456 index インデックス333 documentation ドキュメンテーション217 open source オープンソース2134 penguin ペンギン
![Page 11: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/11.jpg)
Per-Column Collations$ create table collated_polish (some_text text collate "pl_PL.utf8");$ copy collated_polish from '/tmp/polish'; $ select * from collated_polish order by some_text;some_text-----------alfacarcośmać
lamaódkał
mama
![Page 12: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/12.jpg)
PsycadelicQueries
![Page 13: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/13.jpg)
Writable CTEs
WITH deleted_posts AS ( DELETE FROM posts WHERE created < now() - '6 months'::INTERVAL RETURNING *)SELECT user_id, count(*) FROM deleted_posts group BY 1;
![Page 14: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/14.jpg)
Writable CTEsWITH 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;
See The Talk!
![Page 15: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/15.jpg)
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.
![Page 16: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/16.jpg)
SSIupdate othello set pieces = 'white' where pieces = 'black';
commit;
ERROR: could not serialize access due to read/write dependencies among transactions
update othello set pieces = 'black' where pieces = 'white';
commit;
See The Talk!
![Page 17: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/17.jpg)
Unlogged TablesCREATE UNLOGGED TABLE cleaned_log_importAS SELECT hit_time, pageFROM raw_hits, hit_watermarkWHERE hit_time > last_watermark AND is_valid(page);
![Page 18: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/18.jpg)
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
![Page 19: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/19.jpg)
SE-Postgres
![Page 20: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/20.jpg)
SE-PostgresSee The Talk!
![Page 21: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/21.jpg)
K-Nearest Neighbor
![Page 22: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/22.jpg)
K-Nearest NeighborSELECT *,
position <-> $my_current_location as distanceFROM ben_n_jerryORDER BY position <-> $my_current_location LIMIT 3;
![Page 23: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/23.jpg)
FDR
FDR
FDR
FDR
SQL-MED
![Page 24: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/24.jpg)
SQL-MED
CREATE FOREIGN TABLE raw_hits ( hit_time TIMESTAMP,page TEXT )
SERVER file_fdwOPTIONS (format 'csv', delimiter ';', filename '/var/log/hits.log');
![Page 25: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/25.jpg)
SQL-MED
SELECT page, count(*)FROM raw_hitsWHERE hit_time > '2011-04-16 16:00:00' ANDhit_time <= '2011-04-16 17:00:00'
GROUP BY page;
See The Talk!
![Page 26: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/26.jpg)
Extensions
![Page 27: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/27.jpg)
ExtensionsCREATE EXTENSION IF NOT EXISTS citext WITH SCHEMA ext;
\dxSchema | Name | Version | Description -------+--------+----------+------------ext | citext | 9.1devel | case- insensitive character string type
![Page 28: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/28.jpg)
Extensions
ALTER EXTENSION citext UPDATE TO 9.2;
DROP EXTENSION citext;
![Page 29: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/29.jpg)
ExtensionsSee The Talk!
![Page 30: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/30.jpg)
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
![Page 31: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/31.jpg)
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
![Page 32: 9.1 Mystery Tour](https://reader033.vdocument.in/reader033/viewer/2022051013/5495b095ac7959482e8b4e34/html5/thumbnails/32.jpg)
Contact● Josh Berkus: [email protected]
● 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)