PostgreSQL 9.2 新機能 - OSC 2012 Kansai@Kyoto

Embed Size (px)

DESCRIPTION

OSC 2012 Kansai@Kyotoでの日本PostgreSQLユーザ会の講演資料です。

Citation preview

  • 1. PostgreSQL9.2 Kansai@Kyoto2012-08-04PostgreSQL

2. SRA OSS, Inc. PostgreSQL2 3. Twitter: @s87 Mail: [email protected] PostgreSQL 2003 2009PostgreSQL(SQL/MED) 2011PostgreSQL 3 4. PostgreSQL PostgreSQL 4 5. PostgreSQL RDBMS Ingres(1970 UCB) PostgreSQL 6.0 (1996 ) 5 BSD PostgreSQL Global Development Gruop University of California PostgreSQL PostgreSQL5 6. PostgreSQL Contributors Major Contributors Core Team Josh Berkus Tom Lane Peter Eisentraut Magnus Hagander Bruce Momjian Dave PagePostgreSQL 6 7. PostgreSQLPostgreSQL 120000 100000 (byte) 80000 60000 Windows 64bit VACUUM JOIN 40000 CPUSQL PITR 20000 Windows 0 PG 7.0 PG 7.1 PG 7.2 PG 7.3 PG 7.4 PG 8.0 PG 8.1 PG 8.2 PG 8.3 PG 8.4 PG 9.0 PG 9.1 | |||||2001 20022005200620092011 4111 127 9 PostgreSQL 7 8. 9.1 PostgreSQL 8 9. 9.1 9.0 pg_basebackup Postgres WALPostgres WAL WAL PostgreSQL 9 10. 9.1 2 SQL/MED CSV CREATEEXTENSION UNLOGGED k-NN GiST SE-PostgresSE-Linux N-gram SERIALIZABLEWITHetcPostgreSQL 10 11. PostgreSQL 9.2 PostgreSQL 11 12. CPU Read 64 PostgreSQL 8.2 812 Fast Path WALPgCon 2012Robert Haas (2012/5/18) PostgreSQL 12 13. Index Only Scan(1) SELECTWHEREEtc. DBMS MySQLCovering Index OracleINDEX (FAST) FULL SCANPostgreSQL13 14. Index Only Scan(2) PostgreSQLMVCC 9.2Visibility Map Visibility Map _vm 11PostgreSQL 14 VACUUM 15. Index Only Scan(3) Index Only Scan Visibility Map Visibility Map PostgreSQL15 16. Index Only Scan(4) enable_indexonlyscan=offpostgres=# EXPLAIN (ANALYZE, BUFFERS)postgres-# SELECT count(*) FROM pgbench_accounts; QUERY PLAN----------------------------------------------------------- Aggregate (cost=288935.08..288935.09 rows=1 width=4)(actual time=13486.255..13486.255 rows=1 loops=1) Buffers: shared hit=32 read=163903 -> Seq Scan on pgbench_accounts (cost=0.00..263935.06 rows=10000006 width=4) (actual time=23.478..12261.668 rows=10000000 loops=1) Buffers: shared hit=32 read=163903 Total runtime: 13486.385 ms(5 rows)PostgreSQL 16 17. Index Only Scan(5) enable_indexonlyscan=onpostgres=# EXPLAIN (ANALYZE, BUFFERS)postgres-# SELECT count(*) FROM pgbench_accounts;QUERY PLAN-------------------------------------------------------------- Aggregate (cost=284699.32..284699.33 rows=1 width=0)(actual time=2466.584..2466.585 rows=1 loops=1) Buffers: shared read=27328 -> Index Only Scan using pgbench_accounts_pkey on pgbench_accounts (cost=0.00..259699.31 rows=10000006 width=0) (actual time=0.093..1516.373 rows=10000000 loops=1) Heap Fetches: 0 Buffers: shared read=27328 Total runtime: 2466.709 ms(6 rows)Seq Scan 5.5 PostgreSQL17 18. Index Only Scan(5) VACUUM autovacuumOK ANALYZEVisibility Map postgres executor Visibility Map count(*)visibility mapPostgreSQL18 19. (1) Postgres PostgresPostgresPostgresPostgreSQL 19 20. (1) Postgres Postgres Postgres Postgres PostgreSQL 20 21. (2) remote_write GUCsynchronous_commit on on remote_write local off PostgreSQL21 22. (2) remote_write WAL WALWAL WAL COMMIT WALWALWAL Postgres Postgres COMMITWALPostgreSQL22 23. (3) pg_receivexlog WAL WAL WALWAL pg_xlog_location_diff() PostgreSQL 23 24. (1) / [1,3)13 NULL CREATE TYPE AS RANGE int4range intA && Bbool AB int8range bigint A @> Bbool AB numrangenumeric A -|- Bbool AB tsrange timestamp A*B AB tstzrange timestamptz A+B AB daterange dateA-B AB PostgreSQL 24 25. (2) 8.4postgres=# d reservationTable "public.reservation" Column | Type| Modifiers-------------+-----------+----------- id | integer | not null room_id| integer | not null during | tstzrange | not null Note reserver_id | integer|GiSTint memo | text| contrib/btree_gistIndexes: "reservation_pkey" PRIMARY KEY, btree (id)"reservation_during_excl"EXCLUDE USING gist (room_id WITH =, during WITH &&)PostgreSQL 25 26. (3) 8.4postgres=# INSERT INTO reservation (room_id, during, reserver)postgres-# VALUESpostgres-# (2, [2012-06-16 14:00,2012-06-16 14:45)::tstzrange, 1);INSERT 0 1postgres=# INSERT INTO reservation (room_id, during, reserver)postgres-# VALUESpostgres-# (2, [2012-06-16 14:30,2012-06-16 14:45)::tstzrange, 1);ERROR: conflicting key value violates exclusion constraint "reservation_during_excl"DETAIL: Key (room, during)=(2, ["2012-06-16 14:30:00+09", "2012-06-16 17:00:00+09")) conflicts with existing key (room, during)=(2, ["2012-06-16 14:00:00+09","2012-06-16 14:45:00+09")).PostgreSQL 26 27. JSON(1) text PostgreSQL array_to_json() row_to_json() Beta3? pl/v8*1JavaScript*1 http://code.google.com/p/plv8js/wiki/PLV8PostgreSQL 27 28. JSON(2) postgres=# d users Table "public.users" Column | Type | Modifiers--------+---------+----------- id| integer | not null name| text| not null data| json|Indexes:"users_pkey" PRIMARY KEY, btree (id)postgres=# SELECT * FROM users ORDER BY id; id | name |data----+------+------------------------------------------------------------1 | foo | {"last_access":"2012-01-01 12:34:56","features":"[1,3,5]"}2 | bar | {"last_access":"2011-11-25 23:42:41","features":"[2,3,6]"}(2 rows)PostgreSQL28 29. JSON(3) array_to_json()postgres=# SELECT array_to_json({1,2,3}::int[]); array_to_json--------------- [1,2,3](1 row)postgres=# PostgreSQL29 30. JSON(4) row_to_json()postgres=# SELECT row_to_json(row(id, name))postgres-# FROM foo WHERE id = 1;row_to_json-------------------------- {"f1":1,"f2":"name_1"}(1 row)postgres=# SELECT row_to_json(t) FROMpostgres-# (SELECT id, name FROM t WHERE id = 1) t;row_to_json-------------------------- {"id":1,"name":"name_1"}(1 row) PostgreSQL 30 31. (1) Unbalanced treeSP-GiST(Space-Partitioned GiST) VIEWsecurity_barrierLEAKPROOF CREATE DROP SE-Postgres ALTER TABLE .. ALTER TYPE PostgreSQL31 32. (2) contrib/pg_stat_statement SQL I/O pg_stat_bgwriter pg_stat_database libpq PostgreSQL 32 33. (3) 11/0.4/ executor Parameterized Paths PostgreSQL 33 34. Parameterized Paths(1) postgres=# PREPARE s(int) AS SELECT * FROM t WHERE id < $1;PREPAREpostgres=# EXPLAIN (COSTS off) EXECUTE s(1);QUERY PLAN------------------------------ Index Scan using t_pkey on t Index Cond: (id < 1)(2 rows)postgres=# EXPLAIN (COSTS off) EXECUTE s(1000000); QUERY PLAN-------------------------- Seq Scan on t Filter: (id < 1000000)(2 rows) PostgreSQL34 35. PostgreSQL 9.2 2010.7 2011.62012.6HEAD2011.92012.62011.9? 2010.9 2012.6 9.0 9.0.8 9.1 9.1.49.2 2012 2012-06-04Beta2 2012-08-03Beta3 PostgreSQL 35 36. PostgreSQL 36 37. PostgreSQL NPO http://www.postgresql.jp/ PostgreSQL PostgreSQL Lets Postgreshttp://lets.postgresql.jp/ PostgreSQL37