Professional Documents
Culture Documents
Postgresql
,
2011
Creative Commons Attribution-Noncommercial 2.5
(, )
:
PostgreSQL Slony-I,
Eugene Kuzin eugene@kuzin.net,
http://www.kuzin.net/work/sloniki-privet.html
PostgreSQL PL/Proxy,
dmitry.chirkin@gmail.com,
http://habrahabr.ru/blogs/postgresql/45475/
Hadoop, wordpress@insight-it.ru,
http://www.insight-it.ru/masshtabiruemost/hadoop/
PostgreSQL: Skype, ,
http://postgresmen.ru/articles/view/25
Streaming Replication,
http://wiki.postgresql.org/wiki/Streaming_Replication
, , - ?, Den Golotyuk,
http://highload.com.ua/index.php/2009/05/06/-/
2
2.1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . .
2.2
2.3
2.4
. . . . . . . .
10
. . . . . . . . . . . . . . . . . . . . . . . . .
10
. . . . . . . . . . . . . . . . . . . . . . .
11
. . . . . . . . . . .
15
. . . . . . . . . . . . . . . . . . . . . .
17
. . . . . . . . . . . . . . . . . . . . . . . . . .
18
. . . . . . . . . . . . . . . . . . .
19
. . . . . . .
19
. . . . . . . . . . . . . . . . . . . . . . . . .
20
. . . . . . . . . . . . . . . . . . . . . . .
20
(1), 2 . . . . . . . . . . . . . . . . . . . . .
20
Web , 2
. . . . . . . . . . . . . . . . . . . . . . . . . . .
21
Web , 8
. . . . . . . . . . . . . . . . . . . . . . . . . . .
21
2.5
: pgtune
. .
21
2.6
. . . . . . . . . . . . . . . . .
22
2.7
. . . . . . . . . . . . . . . . . . .
22
23
. . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
26
. . . . . . . . . . . . . . .
26
pgFouine
. . . . . . . . . .
28
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
29
30
3.1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
31
3.3
. . . . . . . . . . . . . . . . . . . . .
32
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
32
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
34
35
. . . . . . . . . . . . . . . . . . . . .
constraint_exclusion
3.4
30
. .
36
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
38
39
4.1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
39
4.2
Slony-I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
41
4.3
4.4
4.5
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
41
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
42
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
42
. . . . . . . . . . . . . . . . . . . . . . . . . . .
47
. . . . . . . . . . . . . . . . . . . .
49
Londiste . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
52
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
52
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
52
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
54
58
. . . . . . . . . . . . . . . . . . . .
59
Streaming Replication ( ) . . . . . . . . .
60
60
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
60
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
60
Bucardo
. . . . . . . . . . . . . . . . . . . . . . . . . . .
66
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
67
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
67
4.6
4.7
. . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
67
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
67
70
. . . . . . . . . . . . . . . . . . . . . . . . . . .
RubyRep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
70
70
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
71
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
72
. . . . . . . . . . . . . . . . . . . .
73
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
74
76
5.1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
76
5.2
PL/Proxy
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
78
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
78
5.3
5.4
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
79
? . . . . . . . . . . . . . . . . . . . . . . . . .
82
HadoopDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
83
87
. . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
98
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
99
6 PgPool-II
100
6.1
6.2
! . . . . . . . . . . . . . . . . . . . . . . . . . . 101
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
pgpool-II
. . . . . . . . . . . . . . . . . . . . . . . . 101
. . . . . . . . . . . . . . . . . . . . . . . 102
PCP . . . . . . . . . . . . . . . . . . . . . . 103
/ pgpool-II
6.3
. . . . . . . . . . . . . . . . . . 104
. . . . . . . . . . . . . . . . . . . 104
. . . . . . . . . . . . . . . . . . . . . 105
. . . . . . . . . . . . . . . . . . . . . . 105
. . . . . . . . . . . . . . . . . . . . . . . 106
6.4
. . . . . . . . . . . . . . . . 107
. . . . . . . . . . . . . . . . 107
SystemDB
. . . . . . . . . . . . . . . . . . . . . . . 108
. . . . . . . . . . . . 111
. . . . . . . . . . . . . . . . . . 112
6.5
Master-slave
. . . . . . . . . . . . . . . . 113
. . . . . . . . . . . . . . . . . . . . . . . . 114
. . . . . . . . . . . . . . . . . . . . . . . 115
Streaming Replication ( ) . . . . . . . . . 116
6.7
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
119
7.1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
7.2
PgBouncer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
7.3
PgPool-II vs PgBouncer
. . . . . . . . . . . . . . . . . . . . . . 120
8 PostgreSQL
122
8.1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
8.2
Pgmemcache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
9
9.1
130
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
9.2
PostGIS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
9.3
PostPic
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
9.4
OpenFTS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
9.5
PL/Proxy
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
9.6
Texcaller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
9.7
Pgmemcache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
9.8
Prex
9.9
pgSphere . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
9.10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
10 PostgreSQL
10.1
133
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
. . . . . . . . . . . . . . . . . 135
. . . . . . . . . . . . . . . . 136
10.4
. . . . . . . . . . . . . . 137
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
10.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
11 PostgreSQL
11.1
139
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
. . . . . . . . . . . . . . . . . . . . . . . . . . . 139
11.2 . . . . . . . . . . . . . . . . . . . . . 140
. . . . . . . . . . . . . . . . . . . . . . . . . . 140
11.3 . . . . . . . . . . . . . . . . . . . . . 141
. . . . . . . . . . . . . . . . . . . . . . . . . . 141
12 (Performance Snippets)
12.1
12.2
142
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
. . . . . . . . . . . . . . . . . 143
. . . . . . . . . . . . . . . . . . 143
count . . . . . . . . . . . . . . . . . . . . . . . . . . 144
-
. . . . . . . 145
. . . . . . . . . . . . . . . . . . 146
. . . . . . . . . . . . . . . . . . . . . . . . . . . 146
,
. . . . . . 149
. . . . . . . . . . . 149
LIKE . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
,
, .
PostgreSQL.
PostgreSQL, . ,
.
2
,
.
2.1
, , . ,
.
;
.
,
.
, ,
?
, ?
,
.
PostgreSQL. , PostgreSQL
, , FAQ. postgresql-performance, . , ,
. : - .
2.1.
PostgreSQL ,
. . : ,
PostgreSQL, . (
) , . PostgreSQL, ,
. , , ..
PostgreSQL :
;
, ;
;
, (, ).
PostgreSQL, , .
.
7.1 ,
.
7.2 :
VACUUM, ;
ANALYZE, ,
;
.
8.1
, MIN() MAX(),
pg_autovacuum (), .
8.2 SQL , .
2.2.
8.3 , SQL/XML
, .
, 8.4.
, ,
,
. , ,
. ,
, , ? , ,
.
,
, .
, , :
.
(
).
(, ,
).
(.
3.4).
2.2
, . postgresql.conf
.
10
2.2.
: shared_buers
PostgreSQL
. ,
,
, .
,
. , , . , ,
.
,
, .
: , PostgreSQL, PostgreSQL ,
. , PostgreSQL
, , . ,
, , .
, shared_buers,
, ,
, .
8
2 . ,
, , , ,
. , , .
, .
:
4 (512)
256512 : 1632
(20484096)
14 : 64256
(819232768)
11
2.2.
ipcs (, free
vmstat). 1,2 2
, . ,
, . , .
PostgreSQL , :
http://developer.postgresql.org/docs/postgres/kernel-resources.html
, :
: work_mem
sort_mem, ,
, , . , work_mem (
). :
( , ,
, shared_buers) ,
.
, .
, .
work_mem postgresql.conf.
1 . 1024.
24% . -
work_mem, , , 512 2048 . ,
work_mem 500
. , , ,
, -
12
2.2.
VACUUM:
maintenance_work_mem
PostgreSQL 7.x vacuum_mem.
, VACUUM, ANALYZE, CREATE
INDEX, .
, ,
.
50 75% , , 32 256 .
, work_mem.
. , 14
128512 MB.
, , , , ( );
( UPDATE DELETE)
( ).
, PostgreSQL
VACUUM ( 3.1.1).
7.2 VACUUM . 7.2, VACUUM , SELECT, INSERT,
UPDATE DELETE . VACUUM FULL.
, , , ,
.
:
max_fsm_relations
,
.
VACUUM. max_fsm_relations
( ).
/
13
2.2.
max_fsm_pages
,
,
.
, ,
VACUUM. ,
VACUUM VERBOSE ANALYZE ,
. max_fsm_pages , .
FSM, VACUUM
, VACUUM FULL,
.
8.4 fsm ,
temp_buers
, .
16 .
max_prepared_transactions
(PREPARE
TRANSACTION). 5.
vacuum_cost_delay
,
, , I/O VACUUM, .
,
vacuum_cost_delay 0. 50
200 . vacuum_cost_page_hit
vacuum_cost_page_limit. VACUUM,
. (Jan Wieck) , delay 200,
page_hit 6 100 VACUUM
80%, .
max_stack_depth
, , . , , . 24 MB.
14
2.2.
max_les_per_process
,
. , Too many open
les.
PostgreSQL : ( ) , ,
.
: . ,
:
( checkpoint_segments, 3)
, ( checkpoint_timeout, ,
300).
,
, .
:
checkpoint_segments
,
.
- .
(checkpoint_segments).
( 16 )
. ,
, .
12 256 , (warning) , , .
, , (checkpoint_segments
.
checkpoint_warning ( ):
, .
2
15
2.2.
* 2 + 1) * 16 , , . , 32, 1
.
, ,
.
fsync
o fsync.
,
. : ,
, !
,
.
.
commit_delay ( , 0 ) commit_sib-
lings (5 )
.
commit_siblings ,
commit_delay. ,
, . , .
wal_sync_method
,
. fsync=o, .
:
open_datasync open()
O_DSYNC
fdatasync fdatasync() commit
fsync_writethrough fsync() commit
fsync fsync() commit
open_sync open() O_SYNC
. , .
16
2.2.
full_page_writes
o, fsync=o. ,
on, PostgreSQL
. , ,
. ,
. ,
. full_page_writes , (
checkpoint_interval).
wal_buers
SHARED MEMORY
. 256512 ,
. ,
14 2561024 .
. 3 ,
:
default_statistics_target
, ANALYZE
(. 3.1.2). , , .
ALTER TABLE . . . SET STATISTICS.
eective_cache_size
PostgreSQL
,
.
1,5 , shared_buers
32 , eective_cache_size 800 .
,
3
4
17
2.2.
700 , PostgreSQL ,
merge joins. eective_cache_size
200 , , .
eective_cache_size
2/3 ; RAM
, .
random_page_cost
, . 3.0, 2.5
2.0.
, .
. , , (sequential scans) (index
scans), . , , ,
. . random_page_cost 2.0;
, random_page_cost ,
.
PostgreSQL , .
, ,
. , true/false:
track_counts
. -
, autovacuum . , (
autovacuum).
track_functions
track_activities
18
2.3.
. ,
, ,
.
, , .
, : , (
autovacuum ).
2.3
, . , , , .
PostgreSQL , ,
. ,
, .
, ,
, noatime .
, .
, .
, , ,
, .
:
(!).
, , :
5
6
19
2.4.
pg_clog pg_xlog,
, .
.
.
, , ,
, , , .
2.4
.
PostgreSQL .
RAM ;
random_page_cost = 2 cpu, 4 ;
cpu_tuple_cost = 0.001 cpu, 0.01 ;
cpu_index_tuple_cost = 0.0005 cpu, 0.005 ;
autovacuum = on;
autovacuum_vacuum_threshold = 1800;
autovacuum_analyze_threshold = 900;
(1), 2
maintenance_work_mem = 128MB
eective_cache_size = 512MB
work_mem = 640kB
20
2.5.
: pgtune
wal_buers = 1536kB
shared_buers = 128MB
max_connections = 500
Web
, 2
maintenance_work_mem = 128MB;
checkpoint_completion_target = 0.7
eective_cache_size = 1536MB
work_mem = 4MB
wal_buers = 4MB
checkpoint_segments = 8
shared_buers = 512MB
max_connections = 500
Web
, 8
maintenance_work_mem = 512MB
checkpoint_completion_target = 0.7
eective_cache_size = 6GB
work_mem = 16MB
wal_buers = 4MB
checkpoint_segments = 8
shared_buers = 2GB
max_connections = 500
2.5
: pgtune
PostgreSQL Gregory Smith -
pgtune
. Linux .
, . :
Listing 2.1: Pgtune
1
2
http://pgtune.projects.postgresql.org/
21
2.6.
-o,
-M, --memory
. , pgtune
.
-T, --type
Mixed, Desktop.
-c, --connections
, .
, pgtune PostgreSQL.
, , , .
2.6
:
1. , . :
a) . .
b) , .
2. .
3. .
4. .
,
. ( cron)
.
ANALYZE
.
.
22
2.6.
VACUUM ANALYZE.
, ,
,
ANALYZE.
.
REINDEX
REINDEX . :
;
.
. , ,
. PostgreSQL
, . ,
.
- , REINDEX. :
REINDEX, VACUUM FULL, ,
, .
, . , ,
, . .
, , :
, ,
. , ,
.
. ,
.
,
, , ,
, .
EXPLAIN [ANALYZE]
EXPLAIN [] , PostgreSQL . EXPLAIN ANALYZE []
23
2.6.
.
, .
:
(seq scan).
(nested loop).
EXPLAIN ANALYZE: ?
,
.
,
. , ,
, - ,
,
. 80%
,
.
EXPLAIN ANALYZE
, . ,
SET enable_seqscan=false;
,
, , .
postgresql.conf ! ,
!
. :
pg_stat_user_tables
, ,
, ,
.
2.6.
pg_stat_user_indexes ,
, , ( , ,
).
pg_statio_user_tables
, , , (. 2.1.1), , , TOAST.
,
).
.
, , , ,
, , .
PostgreSQL
/ , ,
. , , foo foo_name,
foo_name = '',
.
(partial indexes)
WHERE. , ,
scheta uplocheno boolean. ,
uplocheno = false , uplocheno = true,
.
25
2.6.
PostrgeSQL , PostgreSQL ,
.
, ,
, ,
;
.
, : ,
.
, , . ,
, .
26
2.6.
, .
, , .
- :
10
1. ,
, ANALYZE:
Listing 2.3: SQL
2. , , ,
. ,
. ,
.
3. , (cron).
DISTINCT
DISTINCT .
GROUP BY DISTINCT. GROUP BY
, ,
DISTINCT.
Listing 2.4: DISTINCT
1
2
3
4
5
7
10000 ,
50000 !
10
27
2.6.
10
11
12
13
14
16
1
2
3
4
5
7
10
11
12
13
14
16
pgFouine
pgFouine
11
log- PostgreSQL,
syslog
Listing 2.6: pgFouine
11
http://pgfouine.projects.postgresql.org/
28
2.7.
1
2
3
1
2
3
log_min_duration_statement = n
log_duration = off
log_statement = ' none '
log_min_duration_statement
0. , -1.
pgFouine .
HTML- :
Listing 2.8: pgFouine
pgfouine . php - file your / log / file . log > your - report . html
10 :
Listing 2.9: pgFouine
pgfouine . php - file your / log / file . log - top 10 - format text
, ,
http://pgfouine.projects.postgresql.org.
2.7
, PostgreSQL .
, . .
29
- ,
. , ,
.
3.1
(partitioning, )
(, ) .
, .
( ).
(.. ,
). ( 5. . . 10 ) 40. . . 50% ,
( ), . . .
. , ( )
, ( ). , ,
. SELECT *
FROM articles ORDER BY id DESC LIMIT 10
, .
, :
(, ,
) -
.
(DROP TABLE , DELETE).
30
3.2.
3.2
PostgreSQL :
(range) , ,
. , .
(list)
.
,
:
, . .
,
.
, .
,
. ,
. :
Listing 3.1:
1
2
( ), .
, .
, constraint_exclusion postgresql.conf.
, .
31
3.3.
3.3
. , ,
.
. , , ()
(). ,
3 . ,
. , , , ,
( ). .
.
, :
Listing 3.2:
1
2
3
4
5
6
7
1
2
3
4
5
6
7
8
9
10
11
(
' 2010 -10 -01 ' AND logdate < DATE
(
' 2010 -11 -01 ' AND logdate < DATE
(
' 2010 -12 -01 ' AND logdate < DATE
(
' 2011 -01 -01 ' AND logdate < DATE
32
3.3.
12
) INHERITS ( my_logs ) ;
my_logs2010m10, my_logs2010m11
.., ( ).
CHECK , ( , !).
logdate,
:
Listing 3.4:
1
2
3
4
ON my_logs2010m10
ON my_logs2010m11
ON my_logs2010m12
ON my_logs2011m01
,
.
Listing 3.5:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
33
3.3.
.
:
Listing 3.6:
1
2
3
my_logs:
Listing 3.7:
1
2
3
1
2
3
4
1
2
3
4
5
6
7
34
3.3.
Listing 3.10:
1
2
3
4
5
7
8
9
10
11
1
2
3
4
5
7
8
9
10
11
12
. . ,
2008 , 10 . :
Listing 3.12:
3.3.
constraint_exclusion
constraint_exclusion ,
. , :
Listing 3.14: constraint_exclusion OFF
1
2
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
3.3.
19
20
21
22
23
24
25
26
27
28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
3.4.
, ,
, . constraint_exclusion
, , CHECK , , . 8.4 PostgreSQL
constraint_exclusion on, o partition. ( ) constraint_exclusion on, o,
partition, CHECK .
3.4
.
, . ,
, ( ) 50%
.
38
, .
,
.
4.1
(. replication) (, ). ,
. , ,
. .
, ,
. , . (,
).
,
, - ( , , ).
, .
, , , ( ,
). , . ,
39
4.1.
,
.
,
( ). ,
, , , ,
.
(, , ). ,
, ( )
. ,
, . , ,
X, B , , Y X.
Y, Y (, - ), B
Y , , ,
.
, Y , X .
. , ,
,
( ) .
: ,
. , , .
,
. , . ,
, ,
.
,
.
PostgreSQL , , . (, ).
40
4.2.
Slony-I
PGCluster2
Multi-Master .
, .
pgpool-I/II3 PostgreSQL ( II ). :
( ,
stand-by );
online-;
pooling ;
;
SELECT- postgresql-;
.
Bucardo4
, Multi-
Master Master-Slave , .
Londiste5
6
Master-Slave .
Skytools . , Slony-I.
4.2 Slony-I
http://www.slony.info/
http://pgfoundry.org/projects/pgcluster/
3 http://pgpool.projects.postgresql.org/
4 http://bucardo.org/
5 http://skytools.projects.postgresql.org/doc/londiste.ref.html
6 http://pgfoundry.org/projects/skytools/
7 http://www.commandprompt.com/products/mammothreplicator/
8 http://www.postgres-r.org/
9 http://www.rubyrep.org/
1
2
41
4.2.
Slony-I
slonik-e
slonik stdin.
slonik-a , , ,
slonik syntax error, .
. .
Ubuntu :
Listing 4.1:
customers
( , ).
: customers
master_host: customers_master.com
slave_host_1: customers_slave.com
cluster name ( ): customers_rep
master-
Postgres,
Slony. , ,
slony.
Listing 4.2: master-
1
2
3
42
4.2.
Slony-I
slony, slon. , ( slon)
.
slave-
,
Internet ( ), PostgreSQL , . , :
Listing 4.3: slave-
1
2
1
2
3
4
5
6
pgsql@customers_slave$ rm - rf $PGDATA
pgsql@customers_slave$ mkdir $PGDATA
pgsql@customers_slave$ initdb -E UTF8 -D $PGDATA
pgsql@customers_slave$ createuser -a -d slony
pgsql@customers_slave$ psql -d template1 -c " alter \
user slony with password ' slony_user_password '; "
postmaster.
! . !
Listing 4.5: slave-
1
2
3
43
4.2.
Slony-I
plpgsql slave
slony.
(slony_user_password).
:
Listing 4.6: plpgsql slave
1
2
3
4
1
2
( 5)
:-) slave :
Listing 4.8: plpgsql slave
1
2
3
4
5
6
7
4.2.
Slony-I
Y . . : , cluster
name - , T1 (default).
uninstall.
( ), uninstall ( master slave).
PgSQL
, - ,
.
- :
Listing 4.9:
1
3
5
6
8
9
11
12
14
16
17
18
19
20
21
22
23
25
27
28
30
32
33
34
35
# !/ bin / sh
CLUSTER = customers_rep
DBNAME1 = customers
DBNAME2 = customers
HOST1 = customers_master . com
HOST2 = customers_slave . com
PORT1 =5432
PORT2 =5432
SLONY_USER = slony
slonik << EOF
cluster name = $CLUSTER ;
node 1 admin conninfo = ' dbname = $DBNAME1 host = $HOST1
port = $PORT1
user = slony password = slony_user_password ';
node 2 admin conninfo = ' dbname = $DBNAME2 host = $HOST2
port = $PORT2 user = slony password = slony_user_password ';
init cluster ( id = 1 , comment = ' Customers DB
replication cluster ' ) ;
echo ' Create set ';
create set ( id = 1 , origin = 1 , comment = ' Customers
DB replication set ' ) ;
echo ' Adding tables to the subscription set ';
echo ' Adding table public . customers_sales ... ';
set add table ( set id = 1 , origin = 1 , id = 4 , full qualified
name = ' public . customers_sales ' , comment = ' Table
public . customers_sales ' ) ;
echo ' done ';
45
4.2.
37
38
39
40
41
43
44
45
46
47
48
49
50
52
53
54
Slony-I
1
3
5
6
8
9
11
12
14
# !/ bin / sh
CLUSTER = customers_rep
DBNAME1 = customers
DBNAME2 = customers
HOST1 = customers_master . com
HOST2 = customers_slave . com
PORT1 =5432
PORT2 =5432
SLONY_USER = slony
46
4.2.
16
17
18
19
20
21
23
24
26
Slony-I
, .
Listing 4.11:
1
2
Listing 4.12:
1
2
4.2.1 4.2.2.
id = 3. customers_slave3.com,
- PgSQL.
( 4.2.2) :
Listing 4.13:
1
2
3
4.2.
4
5
6
7
Slony-I
1
3
5
6
8
9
11
12
14
16
17
18
19
20
21
23
25
26
27
28
29
30
31
33
34
35
37
# !/ bin / sh
CLUSTER = customers_rep
DBNAME1 = customers
DBNAME3 = customers
HOST1 = customers_master . com
HOST3 = customers_slave3 . com
PORT1 =5432
PORT2 =5432
SLONY_USER = slony
slonik << EOF
cluster name = $CLUSTER ;
node 1 admin conninfo = ' dbname = $DBNAME1 host = $HOST1
port = $PORT1 user = slony password = slony_user_pass ';
node 3 admin conninfo = ' dbname = $DBNAME3
host = $HOST3 port = $PORT2 user = slony password = slony_user_pass ';
echo ' done adding ';
store node ( id = 3 , comment = ' Node 3 , $HOST3 ' ) ;
echo ' sored node ';
store path ( server = 1 , client = 3 , conninfo =
' dbname = $DBNAME1
host = $HOST1 port = $PORT1 user = slony password = slony_user_pass ' ) ;
echo ' stored path ';
store path ( server = 3 , client = 1 , conninfo =
' dbname = $DBNAME3
host = $HOST3 port = $PORT2 user = slony password = slony_user_pass ' ) ;
echo ' again ';
store listen ( origin = 1 , provider = 1 , receiver = 3 ) ;
store listen ( origin = 3 , provider = 3 , receiver = 1 ) ;
EOF
48
4.2.
Slony-I
id 3, 2 .
3 replication set:
Listing 4.15:
1
3
5
6
8
9
11
12
14
16
17
18
19
20
21
23
24
26
# !/ bin / sh
CLUSTER = customers_rep
DBNAME1 = customers
DBNAME3 = customers
HOST1 = customers_master . com
HOST3 = customers_slave3 . com
PORT1 =5432
PORT2 =5432
SLONY_USER = slony
slonik << EOF
cluster name = $CLUSTER ;
node 1 admin conninfo = ' dbname = $DBNAME1 host = $HOST1
port = $PORT1 user = slony password = slony_user_pass ';
node 3 admin conninfo = ' dbname = $DBNAME3 host = $HOST3
port = $PORT2 user = slony password = slony_user_pass ';
echo ' subscribing ';
subscribe set ( id = 1 , provider = 1 , receiver = 3 , forward =
no ) ;
EOF
slon , . slon .
Listing 4.16:
1
2
, : , :
Listing 4.17:
49
4.2.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Slony-I
50
4.2.
Slony-I
1
2
3
4
master-, SELECT-
. pg_stat_activity :
Listing 4.19:
1
2
3
4
5
6
7
8
9
10
11
12
13
51
4.3.
Londiste
sl_event - , .
:
Listing 4.20:
1
2
4.3 Londiste
Londiste , python. :
. - , Slony-I. Londiste PgQ (
,
, PostgreSQL). :
, (failover)
(switchover) ( 3
10
, Linux,
Ubuntu Server. , ( Windows) ,
10
http://skytools.projects.postgresql.org/skytools-3.0/doc/skytools3.html
52
4.3.
Londiste
PostgreSQL Windows, , .
Londiste Skytools,
. , Debian Ubuntu skytools
:
Listing 4.21:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
./ configure
make
make install
,
Listing 4.24:
1
2
3
4
$londiste . py -V
Skytools version 2.1.11
$pgqadm . py -V
Skytools version 2.1.11
53
4.3.
Londiste
, .
host1 ;
host2 ;
ticker-
Londiste ticker ,
. , , , . ticker- ( /etc/skytools/db1ticker.ini):
Listing 4.25: ticker-
1
2
3
5
6
8
9
10
12
13
14
16
17
18
[ pgqadm ]
#
job_name = db1 - ticker
#
db = dbname = P host = host1
#
# ( ..)
maint_delay = 600
#
# ( )
loop_delay = 0.1
# log pid
logfile = / var / log /%( job_name ) s . log
pidfile = / var / pid /%( job_name ) s . pid
(SQL)
ticker .
pgqadm.py :
Listing 4.26: ticker-
1
2
54
4.3.
Londiste
ticker,
:
Listing 4.27: ticker-
Londiste . slave
, .
( /etc/skytools/db1-londiste.ini):
Listing 4.29:
1
2
3
5
6
7
8
10
11
12
13
14
15
17
18
19
21
22
23
[ londiste ]
#
job_name = db1 - londiste
#
provider_db = dbname = db1 port =5432 host = host1
#
subscriber_db = dbname = db1 host = host2
#
# SQL - , ..
# .
# ! ,
# pgq_queue_name = db1 - londiste - queue
# log pid
logfile = / var / log /%( job_name ) s . log
pidfile = / var / run /%( job_name ) s . pid
#
log_size = 5242880
log_count = 3
55
4.3.
Londiste
Londiste
SQL .
:
Listing 4.30: Londiste
Londiste
:
Listing 4.32:
:
Listing 4.33:
56
4.3.
Londiste
(sequence)
. :
Listing 4.35:
, . Londiste
bulk copy , ( COPY) ,
.
:
Listing 4.37:
1
3
4
5
6
7
8
9
10
ok
ok
in - copy
-
( ):
Listing 4.39:
(
57
4.3.
2
3
4
5
6
Londiste
while [ $ (
python londiste . py / etc / skytools / db1 - londiste . ini subscriber
tables |
tail -n +2 | awk '{ print $2 } ' | grep -v ok | wc -l ) - ne 0 ];
do sleep 60; done ; echo '' | mail -s ' Replication done EOM '
user@domain . com
) &
:
Listing 4.40:
.
Listing 4.41:
1
2
Londiste
, . PGQ, , API:
Listing 4.42:
58
4.3.
Londiste
:
1.
2. BEGIN;
3.
4. SELECT londiste.provider_refresh_trigger('queue_name', 'tablename');
5. COMMIT;
1. BEGIN;
2.
3. SELECT londiste.provider_refresh_trigger('queue_name', 'tablename');
4. COMMIT;
5. lag, londiste
6.
, ,
.
Londiste lag
, , ticker. UPDATE DELETE
,
. . .
,
pgq.subscription sub_last_tick sub_next_tick.
Listing 4.44:
1
2
3
4
5
6
7
59
4.4.
Streaming Replication ( )
Listing 4.45:
pgq_lazy_fetch = 500
Londiste 500 . .
PostgreSQL
-
PostgreSQL
(
, ,
,
, Hot Standby)
PostgreSQL 9 .
9.0.1 . , , Linux.
masterdb(192.168.0.10)
slavedb(192.168.0.20).
60
4.4.
Streaming Replication ( )
ssh. postgres . ,
:
Listing 4.46: userssh
1
2
3
su postgres
RSA- :
Listing 4.48: RSA-
1
2
3
4
5
6
7
8
ssh localhost
sshd:
Listing 4.51: sshd
4.4.
Streaming Replication ( )
$HOME/.ssh slavedb.
ssh.
pg_hba.conf ,
(trust):
Listing 4.52: pg_hba.conf
host
replication
all
192.168.0.20/32
trust
host
replication
all
192.168.0.10/32
trust
postgresql .
masterdb. postgresql.conf
:
Listing 4.54:
1
2
3
4
6
7
9
10
11
12
13
14
15
16
18
62
4.4.
19
20
21
22
Streaming Replication ( )
max_wal_senders = 5 .
wal_keep_segments = 32 c WAL
pg_xlog .
postgresql .
slavedb.
slavedb masterdb.
.
masterdb . :
Listing 4.55:
1
2
3
63
4.4.
Streaming Replication ( )
, . :
Listing 4.57:
hot_standby = on
! wal_level = archive, (hot_standby = o ).
slavedb PostgreSQL
recovery.conf :
Listing 4.59: recovery.conf
1
2
3
5
6
7
9
10
11
13
14
15
16
17
18
standby_mode='on'
64
4.4.
Streaming Replication ( )
primary_conninfo
trigger_le -, .
restore_command , WAL
. scp masterdb (masterdb_host
- masterdb).
PostgreSQL slavedb.
:
Listing 4.60:
1
2
3
4
5
7
8
9
10
11
13
14
15
16
17
1
2
4
5
65
4.4.
1
2
3
4
5
6
7
Streaming Replication ( )
$psql test_db
test_db =# create table test3 ( id int not null primary key , name
varchar (20) ) ;
NOTICE : CREATE TABLE / PRIMARY KEY will create implicit index
" test3_pkey " for table " test3 "
CREATE TABLE
test_db =# insert into test3 ( id , name ) values ( '1 ' , ' test1 ') ;
INSERT 0 1
test_db =#
:
Listing 4.63:
1
2
3
4
5
6
$psql test_db
test_db =# select * from test3 ;
id | name
-- - -+ - - - - - - 1 | test1
(1 row )
,
.
- (trigger_le) , .
- (trigger_le) .
. , .
PostgreSQL .
, ,
. PostgreSQL .
66
4.5.
Bucardo
4.5 Bucardo
Listing 4.65:
1
2
3
4
12
Listing 4.66:
1
2
3
4
5
Bucardo
:
11
12
http://search.cpan.org/CPAN/authors/id/T/TU/TURNSTEP/
http://bucardo.org/wiki/Bucardo#Obtaining_Bucardo
67
4.5.
Bucardo
bucardo_ctl install
Bucardo PostgreSQL, :
Listing 4.69: Bucardo
1
2
3
5
6
8
9
10
11
12
13
, Bucardo. master_db slave_db.
:
Listing 4.70:
1
2
3
4.5.
Bucardo
replica Bucardo.
. (master-slave):
Listing 4.72:
type
. 3 :
Fullcopy. .
Pushdelta. Master-slave .
Swap. Master-master .
Bucardo
. goat ( ) standard_conict
(
):
).
target target (slave_db
).
skip . -
.
random , -
.
latest ,
.
abort .
source
.
targetdb
, .
master-master:
Listing 4.73:
69
4.6.
RubyRep
/
:
Listing 4.74:
bucardo_ctl start
:
Listing 4.75:
bucardo_ctl stop
:
Listing 4.76:
Listing 4.77:
Listing 4.79:
bucardo_ctl reload_config
http://bucardo.org/wiki/Bucardo_ctl
4.6 RubyRep
70
4.6.
RubyRep
MySQL
RubyRep : Ruby
JRuby. JRuby .
JRuby
Java ( 1.6).
13
Ruby
1. Ruby, Rubygems.
2. .
Mysql:
Listing 4.80:
3. rubyrep:
Listing 4.82:
1
13
http://rubyforge.org/frs/?group_id=7932, ZIP
71
4.6.
RubyRep
:
Listing 4.83:
1
2
3
4
5
6
7
8
10
11
12
13
14
15
16
18
19
20
21
= {
' postgresql ' ,
' SCOTT ' ,
' scott ' ,
' tiger ' ,
'172.16.1.2 '
:
Listing 4.85:
1
2
4.6.
RubyRep
dept , emp
.
:
Listing 4.87:
:
Listing 4.89:
rubyrep Ruby :
Listing 4.91:
1
2
4.7.
3
4
5
6
1
2
3
4
6
7
8
9
10
11
12
13
15
16
17
18
19
20
21
22
23
24
25
26
27
--- / Library / Ruby / Gems /1.8/ gems / rubyrep -1.1.2/ lib / rubyrep /
replication_runner . rb 2010 -07 -16 15:17:16.000000000 -0400
+++ ./ replication_runner . rb 2010 -07 -16 17:38:03.000000000
-0400
@@ -2 ,6 +2 ,12 @@
require ' optparse '
require ' thread '
+ require ' monitor '
+
+ class Monitor
+ alias lock mon_enter
+ alias unlock mon_exit
+ end
module RR
# This class implements the functionality of the
' replicate ' command .
@@ -94 ,7 +100 ,7 @@
# Initializes the waiter thread used for replication
pauses
# and processing
# the process TERM signal .
def init_waiter
- @termination_mutex = Mutex . new
+ @termination_mutex = Monitor . new
@termination_mutex . lock
@waiter_thread ||= Thread . new
{ @termination_mutex . lock ;
self . termination_requested = true }
% w ( TERM INT ) . each do | signal |
4.7
, PostgreSQL.
74
4.7.
, , ..
PostgreSQL.
.
, 9.0 PostgreSQL. Slony-I
, , , (failover) (switchover).
Londiste ,
. Bucardo mastermaster, master-slave ,
, (failover) (switchover). RubyRep, master-master ,
, ( ).
75
,
.
5.1
. .
. , . .
,
(, 90% ). , ( !)
, ().
, , , ..
.
, , . ..
. ? . ,
. ,
10 , 10 - ..
.. - ,
, .
, ID
(user_id) -
76
5.1.
. .. :
,
user_id
- =. , ,
.
, .
=
() . , ,
( , ).
.
,
.. .
, ,
, (, ,
). . , ,
, ID , 100 .
. PostgreSQL
:
Greenplum Database1
GridSQL for EnterpriseDB Advanced Server2
Sequoia3
PL/Proxy4
HadoopDB5 (Shared-nothing clustering)
http://www.greenplum.com/index.php?page=greenplum-database
http://www.enterprisedb.com/products/gridsql.do
3 http://www.continuent.com/community/lab-projects/sequoia
4 http://plproxy.projects.postgresql.org/doc/tutorial.html
5 http://db.cs.yale.edu/hadoopdb/hadoopdb.html
1
2
77
5.2.
PL/Proxy
5.2 PL/Proxy
PL/Proxy - .
, , , (,
, , - ).
PL/Proxy ? .
, ,
26 . ,
-, : , , - . .
PL/Proxy
OLTP . failover-
, -, .
:
autocommit-
SELECT;
- ;
-,
PgBouncer
( , )
-
1. PL/Proxy
http://pgfoundry.org/projects/plproxy
78
5.2.
PL/Proxy
3 PostgreSQL. 2
node1 node2, ,
proxy. pl/proxy
.
plproxytest, users. !
node1 node2.
.
plproxytest( ):
Listing 5.2:
1
2
3
1
2
3
4
5
6
7
1
2
3
4
5
6
7
8
9
1
2
3
5.2.
PL/Proxy
pl/proxy:
Listing 5.6:
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
1
2
3
4
5
6
7
5.2.
8
9
10
11
12
13
14
15
16
17
18
PL/Proxy
RETURN NEXT ' dbname = plproxytest host = node2 user = postgres ';
RETURN ;
END IF ;
RAISE EXCEPTION ' Unknown cluster ';
END ;
$BODY$
LANGUAGE ' plpgsql ' VOLATILE
COST 100
ROWS 1000;
ALTER FUNCTION public . get_cluster_partitions ( text )
OWNER TO postgres ;
:
Listing 5.9:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1
2
3
4
5
6
7
8
9
10
11
5.2.
2
3
PL/Proxy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
?
pl/proxy
. ,
. 16 .
- . ?
Highload++ 2008,
Skype,
opensource.
,
. ,
,
get_cluster_partitions.
82
5.3.
HadoopDB
5.3 HadoopDB
Hadoop ,
. ,
:
Hadoop -
, ;
: , .
;
,
;
, .
;
, Java,
, JVM.
HDFS
Hadoop Distributed File System.
,
:
, , ;
;
;
;
:
;
: , ;
HDFS
Namenode
.
.
83
5.3.
HadoopDB
. 5.1: HDFS
, . .
Datanode
.
. Rack, , , .
, . .
HDFS : .
( , ; - 64 mb) , Datanode'.
,
. , -
,
84
5.3.
HadoopDB
/trash
. ,
.
- , Datanode
Namenode' . Namenode
, - . ,
.
, TCP/IP.
Namenode ClientProtocol,
DatanodeProtocol,
Remote Procedure Call (RPC).
, DFSShell, DFSAdmin,
, -. API : Java API, C pipeline,
WebDAV .
MapReduce
, Hadoop framework
,
. Job ()
, , :
Map
(
-) -.
.
Reduce
map .
, .
, ,
( ).
JobTracker, TaskTracker. JobTracker' , ,
.
85
5.3.
HadoopDB
, framework',
map reduce,
.
JobTracker .
, , , .
HBase
Hadoop ,
.
Google
BigTable.
HBase
. , .
HQL ( Hadoop Query
Language), SQL.
.
HBase
, --, .
,
, , . , .
,
.
HQL , SQL,
help;, .
SELECT, INSERT, UPDATE, DROP , .
HBase Shell, HBase
API : Java, Jython, REST Thrift.
HadoopDB
86
5.3.
HadoopDB
. SQL,
MapReduce, . MapReduce ,
.
Ubuntu Server .
Hadoop
, Hadoop,
, :
ssh ,
[hadoop]:
Listing 5.14:
1
2
3
su hadoop
RSA- :
Listing 5.16: RSA-
1
2
3
4
5
6
7
5.3.
HadoopDB
:
Listing 5.17:
ssh localhost
sshd:
Listing 5.19: sshd
Hadoop:
Listing 5.21: Hadoop
1
2
3
4
5
6
7
8
cd / opt
sudo wget http :// www . gtlib . gatech . edu / pub / apache / hadoop
/ core / hadoop -0.20.2/ hadoop -0.20.2. tar . gz
sudo tar zxvf hadoop -0.20.2. tar . gz
sudo ln -s / opt / hadoop -0.20.2 / opt / hadoop
sudo chown -R hadoop : hadoop / opt / hadoop / opt / hadoop -0.20.2
sudo mkdir -p / opt / hadoop - data / tmp - base
sudo chown -R hadoop : hadoop / opt / hadoop - data /
/opt/hadoop/conf/hadoop-env.sh :
Listing 5.22:
1
2
3
4
5
6
export
export
export
export
export
export
5.3.
HadoopDB
1
2
3
4
5
6
8
9
10
11
12
13
14
16
17
18
19
20
21
22
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5.3.
5
6
7
8
9
HadoopDB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1
2
3
4
5
6
7
8
9
10
11
$ start - all . sh
starting namenode , logging to / opt / hadoop / bin /..
/ logs / hadoop - hadoop - namenode - hadoop1 . out
localhost : starting datanode , logging to
/ opt / hadoop / bin /../ logs / hadoop - hadoop - datanode - hadoop1 . out
localhost : starting secondarynamenode , logging to
/ opt / hadoop / bin /../ logs / hadoop - hadoop - secondarynamenode - hadoop1 . out
starting jobtracker , logging to
/ opt / hadoop / bin /../ logs / hadoop - hadoop - jobtracker - hadoop1 . out
localhost : starting tasktracker , logging to
/ opt / hadoop / bin /../ logs / hadoop - hadoop - tasktracker - hadoop1 . out
Hadoop stop-all.sh.
90
5.3.
HadoopDB
HadoopDB Hive
7
PostgreSQL JDBC .
$HADOOP_HOME/lib.
Hive HadoopDB SQL . HDFS Hive:
Listing 5.29: HadoopDB
1
2
3
4
hadoop
hadoop
hadoop
hadoop
fs
fs
fs
fs
- mkdir
- mkdir
- chmod
- chmod
/ tmp
/ user / hive / warehouse
g + w / tmp
g + w / user / hive / warehouse
HadoopDB SMS_dist. :
Listing 5.30: HadoopDB
1
2
3
1
2
3
4
6
$ hive
Hive history file =/ tmp / hadoop /
hive_job_log_hadoop_201005081717_1990651345 . txt
hive >
hive > quit ;
. :
Listing 5.32:
1
2
7
8
http://sourceforge.net/projects/hadoopdb/les/
http://jdbc.postgresql.org/download.html
91
5.3.
HadoopDB
Listing 5.33:
1
2
4
5
7
8
9
10
11
12
13
15
16
17
18
19
20
21
22
23
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use strict ;
use warnings ;
my $CUR_HOSTNAME = ` hostname -s `;
chomp ( $CUR_HOSTNAME ) ;
my
my
my
my
my
my
my
$NUM_OF_RECORDS_1TB
= 10000000000;
$NUM_OF_RECORDS_535MB = 100;
$BASE_OUTPUT_DIR
= " / data " ;
$PATTERN_STRING
= " XYZ " ;
$PATTERN_FREQUENCY = 108299;
$TERAGEN_JAR
= " teragen . jar " ;
$HADOOP_COMMAND
= $ENV { ' HADOOP_HOME ' }. " / bin / hadoop " ;
1
2
3
5.3.
4
5
6
7
8
9
HadoopDB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
93
5.3.
HadoopDB
:
Listing 5.37:
1
2
1
2
3
1
2
3
4
5
6
7
8
9
10
11
12
5.3.
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
HadoopDB
95
5.3.
51
52
53
54
55
56
57
58
59
HadoopDB
1
2
3
$ cd padraig
$ cat part -00000
some data
PostgreSQL:
Listing 5.42:
1
2
3
4
5
6
8
10
psql > select * from grep where field like '% wo % ';
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+ - - - - - - - - - - - - - - - - - - -+
| key1
| field
|
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+ - - - - - - - - - - - - - - - - - - -+
some data
1 rows in set (0.00 sec )
psql >
. .
. PostgreSQL:
Listing 5.43:
1
2
3
4
HadoopDB:
Listing 5.44:
5.3.
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
HadoopDB
padraig
01.11.2010 23:14:45 edu . yale . cs . hadoopdb . exec . DBJobBase
initConf
INFO : SELECT key1 , field FROM grep WHERE field LIKE '%% May %% ';
01.11.2010 23:14:46 org . apache . hadoop . metrics . jvm . JvmMetrics
init
INFO : Initializing JVM Metrics with processName = JobTracker ,
sessionId =
01.11.2010 23:14:46 org . apache . hadoop . mapred . JobClient
configureCommandLineOptions
WARNING : Use GenericOptionsParser for parsing the arguments .
Applications should implement Tool for the same .
01.11.2010 23:14:46 org . apache . hadoop . mapred . JobClient
monitorAndPrintJob
INFO : Running job : job_local_0001
01.11.2010 23:14:46
edu . yale . cs . hadoopdb . connector . AbstractDBRecordReader
getConnection
INFO : Data locality failed for leo - pgsql
01.11.2010 23:14:46
edu . yale . cs . hadoopdb . connector . AbstractDBRecordReader
getConnection
INFO : Task from leo - pgsql is connecting to chunk 0 on host
localhost with db url jdbc : postgresql :// localhost :5434/ grep0
01.11.2010 23:14:47 org . apache . hadoop . mapred . MapTask
runOldMapper
INFO : numReduceTasks : 0
01.11.2010 23:14:47
edu . yale . cs . hadoopdb . connector . AbstractDBRecordReader close
INFO : DB times ( ms ) : connection = 181 , query execution = 22 ,
row retrieval = 96
01.11.2010 23:14:47
edu . yale . cs . hadoopdb . connector . AbstractDBRecordReader close
INFO : Rows retrieved = 4
01.11.2010 23:14:47 org . apache . hadoop . mapred . Task done
INFO : Task : attempt_local_0001_m_000000_0 is done . And is in
the process of commiting
01.11.2010 23:14:47
org . apache . hadoop . mapred . LocalJobRunner$Job statusUpdate
INFO :
01.11.2010 23:14:47 org . apache . hadoop . mapred . Task commit
INFO : Task attempt_local_0001_m_000000_0 is allowed to commit
now
01.11.2010 23:14:47
org . apache . hadoop . mapred . FileOutputCommitter commitTask
INFO : Saved output of task ' attempt_local_0001_m_000000_0 ' to
file :/ home / hadoop / padraig
01.11.2010 23:14:47
org . apache . hadoop . mapred . LocalJobRunner$Job statusUpdate
INFO :
01.11.2010 23:14:47 org . apache . hadoop . mapred . Task sendDone
INFO : Task ' attempt_local_0001_m_000000_0 ' done .
97
5.3.
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
HadoopDB
1
2
3
4
5
6
$ cd padraig
$ cat part -00000
I am live ! Maybe
I am live ! Maybewqe
I am live ! Maybewqesad
:) May cool string !
PostgreSQL . HadoopDB
PostgreSQL,
PostgreSQL, shared-nothing .
HadoopDB
http://hadoopdb.sourceforge.net/guide/quick_start_guide.html.
, Hive,
HadoopDB. ,
98
5.4.
c Hadoop.
Hadoop HaddopDB.
HadoopDB Hadoop. ,
.
HadoopDB , , Hadoop. HadoopDB,
, , , PostgreSQL
, , PostgreSQL . , Hadoop Hive
.
HadoopDB
Hadoop , , , ,
MapReduce. HadoopDB Hadoop
( ) HadoopDB
.
5.4
.
PostgreSQL , , . ,
, .
99
6
PgPool-II
.
6.1
pgpool-II , PostgreSQL
PostgreSQL. :
pgpool-II PostgreSQL
(.. , , ).
.
pgpool-II PostgreSQL. 2 , .
, SELECT
. pgpool-II
PostgreSQL SELECT
,
.
PostgreSQL. .
100
6.2.
PostgreSQL,
. ,
, . pgpool-II
, .
,
.
.
pgpool-II PostgreSQL
. , () pgpool-II PostgreSQL, () pgpool-II . pgpool-II
, , ,
, pgpool-II .
http://pgpool.projects.postgresql.org/pgpoolII/doc/tutorial-en.html.
6.2 !
pgpool-II
.
pgpool-II
pgpool-II . , , .
Listing 6.1: pgpool-II
1
2
3
./ configure
make
make install
congure
.
101
6.2.
pgpool-II pgpool.conf. : = .
pgpool-II pgpool.conf.sample. pgpool.conf, .
Listing 6.4:
cp / usr / local / etc / pgpool . conf . sample / usr / local / etc / pgpool . conf
pgpool-II localhost 9999.
, listen_addresses *.
Listing 6.5:
1
2
6.2.
- .
Ubuntu Linux /etc/pgpool.conf.
PCP
pgpool-II
, pgpool-II .. . PCP, . PostgreSQL.
pcp.conf. , (:). .
md5.
Listing 6.6: PCP
postgres : e8a48653851e28c69d0506508fb27fc5
pgpool-II pcp.conf.sample.
pcp.conf .
Listing 6.7: PCP
$ cp / usr / local / etc / pcp . conf . sample / usr / local / etc / pcp . conf
Ubuntu Linux /etc/pcp.conf.
md5 pg_md5,
pgpool-II. pg_md5
md5 .
, postgres
pg_md5 md5 .
Listing 6.8: PCP
1
2
pcp_port = 9898
103
6.2.
PostgreSQL pgpoolII. pgpool-II
. ,
.
,
pgpool-II.
pgpool-II 5432, 5433, 5434 . pgpool-II pgpool.conf
.
Listing 6.10:
1
2
3
4
5
6
7
8
9
/ pgpool-II
pgpool-II .
Listing 6.11:
pgpool
, ,
pgpool .
pgpool, -n
pgpool. pgpool-II -
.
Listing 6.12:
pgpool -n &
104
6.3.
, , , .
Listing 6.13:
1
2
3
pgpool stop
- , pgpool-II .
pgpool-II , .
Listing 6.16:
6.3
.
, 6.2. !,
.
pgbench.
true replication_mode pgpool.conf.
105
6.3.
Listing 6.17:
replication_mode = true
replication_mode true, pgpool-II
.
load_balance_mode true, pgpool-II SELECT .
Listing 6.18:
load_balance_mode = true
replication_mode load_balance_mode.
, pgpool.conf, pgpoolII . / pgpool-II.
pgpool.conf pgpool-II,
.
, . bench_replication.
. createdb pgpool-II
.
Listing 6.19:
branches
tellers
10
accounts
100000
history
shell.
106
6.4.
1
2
3
4
5
6
7
8
6.4
. ( partitioning . ). ,
.
pgpool-II ,
(System Database) ( SystemDB).
SystemDB , . SystemDB
dblink.
,
6.2. !,
.
pgbench.
parallel_mode true pgpool.conf.
Listing 6.22:
parallel_mode = true
parallel_mode true . pgpool-II SystemDB
.
107
6.4.
1
2
replication_mode = true
load_balance_mode = false
Listing 6.25:
1
2
replication_mode = false
load_balance_mode = true
parallel_mode load_balance_mode
true, listen_addresses *, replication_mode false.
SystemDB
, .
, dblink , .
dist_def . ,
, pgpool-II .
SystemDB 5432.
SystemDB
Listing 6.26: SystemDB
1
2
3
4
5
6
108
6.4.
,
- pgpool.conf. pgpool pgpool
pgpool.
Listing 6.27: SystemDB
1
2
dblink
dblink pgpool. dblink
contrib PostgreSQL.
dblink .
Listing 6.28: dblink
1
2
dist_def
dist_def, . pgpool-II
, system_db.sql
/usr/local/share/system_db.sql ( - /usr/local).
system_db.sql , dist_def.
dist_def.
Listing 6.30: dist_def
109
6.4.
system_db.sql, dist_def,
pgpool_catalog. system_db_schema
, , system_db.sql.
dist_def .
.
Listing 6.31: dist_def
1
2
3
4
5
6
7
8
9
10
11
12
(col_name, dist_def_func)
- (dbname, schema_name, table_name,
col_list, type_list)
.
col_name. dist_def_func
, col_name
,
, .
- .
, -,
.
replicate_def
,
SQL, dist_def
, , ,
replicate_def. replicate_def system_db.sql dist_def.
replicate_def .
110
6.4.
1
2
3
4
5
6
7
8
, pgbench, . pgbench -i -s 3 (.. 3).
bench_parallel.
sample pgpool-II
dist_def_pgbench.sql.
pgbench. pgpool-II.
Listing 6.33:
1
2
3
4
5
6
7
8
9
10
111
6.4.
accounts
3, aid 1 300000.
.
SQL- .
Listing 6.35:
1
2
3
4
5
6
7
8
.
pgbench branches tellers.
, accounts , branches tellers.
Listing 6.36:
1
2
3
4
5
6
7
9
10
11
12
13
14
15
6.4.
, pgpool.conf, pgpoolII . / pgpool-II.
pgpool.conf pgpool-II,
.
, .
bench_parallel.
. createdb pgpool-II
.
Listing 6.38:
branches
tellers
30
accounts
300000
history
pgpool-II shell.
accounts
5432, 5433, 5434 9999.
Listing 6.40:
1
2
3
4
5
113
6.5.
Master-slave
6.5 Master-slave
pgpool-II ( Slony-I, Londiste).
. master_slave_mode load_balance_mode true. pgpool-II INSERT/UPDATE/DELETE
Master DB (1 ), SELECT , .
, DDL DML . SELECT ,
/*NO LOAD BALANCE*/
SELECT.
Master/Slave replication_mode false,
master_slave_mode true.
Streaming Replication ( )
master-slave ,
, pgpoolII. PostgreSQL, pgpool-II ( ),
( ).
, , ( recovery.conf, trigger_le),
PostgreSQL .
:
Listing 6.41: PostgreSQL
1
2
3
4
5
6
7
8
9
11
12
13
15
16
17
# ! / bin / sh
# Failover command for streming replication .
# This script assumes that DB node 0 is primary , and 1 is
standby .
#
# If standby goes down , does nothing . If primary goes down ,
create a
# trigger file so that standby take over primary node .
#
# Arguments : $1 : failed node id . $2 : new master hostname . $3 :
path to
# trigger file .
failed_node = $1
new_master = $2
trigger_file = $3
# Do nothing if standby goes down .
if [ $failed_node = 1 ]; then
exit 0;
114
6.6.
18
20
21
23
fi
# Create trigger file .
/ usr / bin / ssh -T $new_master / bin / touch $trigger_file
exit 0;
: ,
.
failover_stream.sh pgpool.conf :
Listing 6.42:
6.6
pgpool-II, ,
pgpool. . ,
.
. pgpool, .
:
CHECKPOINT;
;
, ;
CHECKPOINT;
;
postmaster ( pgpool_remote_start);
;
backend_data_directory
PostgreSQL .
recovery_user
PostgreSQL.
115
6.6.
recovery_password
PostgreSQL.
recovery_1st_stage_command
.
- . ,
recovery_1st_stage_command = 'some_script', pgpool-II
$PGDATA/some_script. , pgpool-II recovery_1st_stage.
recovery_2nd_stage_command
.
- . ,
recovery_2st_stage_command = 'some_script', pgpool-II
$PGDATA/some_script. , pgpool-II recovery_2st_stage.
, pgpool-II ,
.
Streaming Replication ( )
master-slave , PostgreSQL.
, . PostgreSQL
pgpool-II ( ).
:
recovery_user. postgres.
Listing 6.43: recovery_user
116
6.6.
1
2
3
4
5
6
7
9
11
12
13
15
17
# ! / bin / sh
# Recovery script for streaming replication .
# This script assumes that DB node 0 is primary , and 1 is
standby .
#
datadir = $1
desthost = $2
destdir = $3
psql -c " SELECT pg_start_backup ( ' Streaming Replication ' ,
true ) " postgres
rsync -C -a -- delete -e ssh -- exclude postgresql . conf
-- exclude postmaster . pid \
-- exclude postmaster . opts -- exclude pg_log -- exclude
pg_xlog \
-- exclude recovery . conf $datadir / $desthost : $destdir /
ssh -T localhost mv $destdir / recovery . done
$destdir / recovery . conf
psql -c " SELECT pg_stop_backup () " postgres
,
rsync .
SSH , recovery_user
.
:
Listing 6.46: recovery_1st_stage_command
C SQL
.
Listing 6.47: C SQL
1
2
3
4
$
$
$
$
6.7.
. pcp_recovery_node
.
6.7
PgPool-II , PostgreSQL.
118
7
,
. .
?
7.1
( ) , ,
PostgreSQL. Windows,
.
-, .
, :
PgBouncer
Pgpool
7.2 PgBouncer
PostgreSQL Skype.
.
Session Pooling.
;
.
119
7.3.
PgPool-II vs PgBouncer
Statement Pooling. . .
, .
(prepared statements) .
PgBouncer :
( 2 );
;
.
:
Listing 7.1: PgBouncer
1
2
3
4
5
6
7
8
9
10
[ databases ]
template1 = host =127.0.0.1 port =5432 dbname = template1
[ pgbouncer ]
listen_port = 6543
listen_addr = 127.0.0.1
auth_type = md5
auth_file = userlist . txt
logfile = pgbouncer . log
pidfile = pgbouncer . pid
admin_users = someuser
userlist.txt :someuser same_password_as_in_server
pgbouncer:
Listing 7.3: PgBouncer
120
7.3.
PgPool-II vs PgBouncer
PgBouncer , PgPool-II
PgBouncer
PgBouncer (
)
PgBouncer PgPool-II .
121
8
PostgreSQL
- , - .
8.1
, , . SELECT PostgreSQL.
, , , .
SQL ,
, , . PostgreSQL
. ? -,
. ? (MVCC MultiVersion Concurrency
Control) , , ,
. , ,
. , , . -, , ,
, .
( ),
.
122
8.2.
Pgmemcache
, , . PostgreSQL:
Pgmemcache ( memcached)
Pgpool-II (query cache)
8.2 Pgmemcache
1
Memcached
, -
-.
.
-.
.
,
memcached .
2.0.4 pgmemcache .
Pgmemcache PostgreSQL
8.4 ( 9.0 ), Ubuntu Server
10.10. Pgmemcache , PostgreSQL
PGXS ( , Linux PGXS). memcached libmemcached
0.38.
,
Pgmemcache:
:
Listing 8.1:
http://memcached.org/
http://pgfoundry.org/projects/pgmemcache/
3 http://pgfoundry.org/frs/download.php/2672/pgmemcache_2.0.4.tar.bz2
1
2
123
8.2.
1
2
Pgmemcache
$ make
$ sudo make install
1
2
3
4
1
2
1
2
4
Pgmemcache ( Pgmemcache)
:
Listing 8.5:
124
8.2.
1
2
3
4
5
Pgmemcache
pgmemcache custom_variable_classes (
pgmemcache)
pgmemcache.default_servers, host:port
(port - ) . :
Listing 8.6: default_servers
PostgreSQL
memcached.
pgmemcache, memcached :
. memcached :
Listing 8.8: memcache_stats
1
2
3
8.2.
Pgmemcache
8.1: pgmemcache
5
6
7
8
9
10
11
memcached .
. NULL,
,
.
.
=.
,
( ).
.
.
memcache_set(key::TEXT, value::TEXT,
expire::TIMESTAMPTZ)
memcache_set(key::TEXT, value::TEXT,
expire::INTERVAL)
memcache_set(key::TEXT, value::TEXT)
.
.
stats = memcache_stats()
memcached.
126
8.2.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
29
Pgmemcache
rusage_system : 0.24001
curr_items : 0
total_items : 0
bytes : 0
curr_connections : 5
total_connections : 7
connection_structures : 6
cmd_get : 0
cmd_set : 0
get_hits : 0
get_misses : 0
evictions : 0
bytes_read : 20
bytes_written : 782
limit_maxbytes : 67108864
threads : 4
(1 row )
memcached :
Listing 8.9:
1
2
3
4
5
7
8
9
10
11
1
2
3
4
5
7
8
9
10
11
13
14
8.2.
15
16
17
19
20
21
22
23
25
26
27
28
29
31
32
33
34
35
37
38
39
40
41
Pgmemcache
--------------12
(1 row )
pgmemcache = # SELECT memcache_incr ( ' some_seq ' , 10) ;
memcache_incr
--------------22
(1 row )
pgmemcache = # SELECT memcache_decr ( ' some_seq ') ;
memcache_decr
--------------21
(1 row )
pgmemcache = # SELECT memcache_decr ( ' some_seq ') ;
memcache_decr
--------------20
(1 row )
pgmemcache = # SELECT memcache_decr ( ' some_seq ' , 6) ;
memcache_decr
--------------14
(1 row )
pgmemcache , ,
.
, memcached ( ),
, .
:
Listing 8.11:
1
2
3
4
5
6
7
8
8.2.
Pgmemcache
(!!!) .
:
Listing 8.13:
1
2
3
4
5
6
7
PostgreSQL Pgmemcache
memcached ,
. memcached,
SQL , PostgreSQL.
129
9.1
PostgreSQL
.
.
9.2 PostGIS
: Open Source
: http://www.postgis.org/
PostGIS PostgreSQL.
PostGIS PostgreSQL
(),
, ESRI SDE Oracle. PostGIS
OpenGIS " SQL"
.
9.3 PostPic
: Open Source
: http://github.com/drotiro/postpic
PostPic PostgreSQL, , PostGIS . image,
(, , ..) (, , ).
130
9.4.
OpenFTS
9.4 OpenFTS
: Open Source
: http://openfts.sourceforge.net/
OpenFTS (Open Source Full Text Search engine)
PostgreSQL , . , .
9.5 PL/Proxy
: Open Source
: http://pgfoundry.org/projects/plproxy/
PL/Proxy - . 5.2 .
9.6 Texcaller
: Open Source
: http://www.profv.de/texcaller/
Texcaller TeX, . C,
, , TeX.
TeX NULL,
. , , NOTICEs.
9.7 Pgmemcache
: Open Source
: http://pgfoundry.org/projects/pgmemcache/
Pgmemcache PostgreSQL API libmemcached
memcached. PostgreSQL
, , memcached.
8.2 .
9.8 Prex
: Open Source
: http://pgfoundry.org/projects/prex
131
9.9.
pgSphere
9.9 pgSphere
: Open Source
: http://pgsphere.projects.postgresql.org/
pgSphere PostgreSQL ,
.
( PostGIS) .
9.10
PostgreSQL . PostgreSQL , , ,
.
132
10
PostgreSQL
,
, ,
- ,
.
10.1
.
, ,
, - .
PostgreSQL . !
, ,
, PostgreSQL .
, , (DELETE, DROP),
( ).
PostgreSQL:
SQL ;
;
;
10.2 SQL
SQL.
133
10.2.
SQL
, . PostgreSQL
pg_dump.
pg_dump:
Listing 10.1: pg_dump
134
10.2.
SQL
SQL
, pg_dump. , pg_dump
. Unix, . :
.
, GZIP:
Listing 10.7: PostgreSQL
split.
split , . , 1 :
Listing 10.10: PostgreSQL
pg_dump
PostgreSQL Zlib,
.
GZIP, :
135
10.3.
, split
.
10.3
, PostgreSQL
. :
Listing 10.14: PostgreSQL
PostgreSQL , ,
(PostgreSQL , ). ,
PostgreSQL.
, (snapshot)
( PostgreSQL). PostgreSQL
. , , , ,
. PostgreSQL , ,
WAL. ,
( WAL ). ,
PostgreSQL ,
136
10.4.
(!!!). ,
.
rsync.
rsync PostgreSQL (PostgreSQL
). PostgreSQL
rsync. rsync , ,
, .
.
10.4
PostgreSQL (Write Ahead
Log, WAL) pg_xlog , . .
PostgreSQL: ,
. ,
:
WAL . ,
, WAL .
, , :
.
( , ).
WAL
, ,
PostgreSQL
( ).
, . ,
WAL .
137
10.5.
. WAL pg_xlog.
postgresql.conf:
Listing 10.15:
1
2
3
1
2
10.5
, , , . ,
PostgreSQL (, ).
138
11
PostgreSQL
, (),
.
-
, , .
11.1
,
. -
( , ).
, SQL , , PostgreSQL ,
. , . :
?
( ..),
, , .
, ,
.
, - - , . ,
:
139
11.2.
;
;
,
, ( Twitter Facebook
). , .
11.2
, , .
, .. ,
,
.
PgPool-II v.3 + Postgresql v.9 Streaming Replication ,
. :
(failover)
.
pgpool-II
, Slony. :
1
2
(failover)
.
pgpool-II
Postgresql 9
http://pgpool.projects.postgresql.org/contrib_docs/simple_sr_setting/index.html
http://www.slideshare.net/leopard_me/postgresql-5845499
140
11.3.
11.3
,
( Google Analytics).
( ).
. PgQ.
PgQ , PostgreSQL. Skype. Londiste ( 4.3).
:
PostgreSQL
,
PgQ , ,
(batches)
API SQL
RabbitMQ. RabbitMQ
, (Message Oriented Middleware) AMQP (Advanced Message Queuing Protocol). RabbitMQ
Mozilla Public License. RabbitMQ Open
Telecom Platform, Erlang.
141
12
(Performance Snippets)
.
. -
.
, ,
.
(House M.D.), 1 1
12.1
PostgreSQL,
, ( ).
, PostgreSQL.
, PostgreSQL ,
.
,
https://github.com/le0pard/postgresql_book/issues
142
12.2.
12.2
( ). PostgreSQL >= 8.1.
1
2
3
4
5
6
7
1
2
3
4
5
6
7
8
9
relation
|
size
- - - - - - - - - - - - - - - - - - - - - - - -+ - - - - - - - - - - - public . accounts
| 326 MB
public . accounts_pkey
| 44 MB
public . history
| 592 kB
public . tellers_pkey
| 16 kB
public . branches_pkey
| 16 kB
public . tellers
| 16 kB
public . branches
| 8192 bytes
. PostgreSQL >= 8.1.
1
2
3
4
5
6
7
8
9
12.2.
: https://gist.github.com/910696
:
Listing 12.4: .
1
2
3
4
5
6
7
8
relation
| total_size
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+ - - - - - - - - - - - public . actions
| 4249 MB
public . product_history_records | 197 MB
public . product_updates
| 52 MB
public . import_products
| 34 MB
public . products
| 29 MB
public . visits
| 25 MB
count
. ,
count.
1
2
3
4
5
6
7
8
9
10
12
13
14
RETURN rows ;
END ;
$$ LANGUAGE plpgsql VOLATILE STRICT ;
17
Testing :
20
21
22
24
25
26
27
12.2.
28
30
31
32
33
34
(1 row )
# SELECT count_estimate ( ' SELECT * FROM foo WHERE r < 0.1 ') ;
count_estimate
---------------94
(1 row )
: https://gist.github.com/910728
-
-
( DEFAULT).
1
2
3
4
5
6
7
8
9
1
3
4
5
6
7
9
10
11
13
# SELECT ret_def ( ' schema ' , ' table ' , ' column ') ;
SELECT ret_def ( ' public ' , ' image_files ' , ' id ') ;
ret_def
----------------------------------------nextval ( ' image_files_id_seq ':: regclass )
(1 row )
SELECT ret_def ( ' public ' , ' schema_migrations ' , ' version ') ;
ret_def
--------(1 row )
145
12.2.
(random) ( ).
1
2
3
4
5
1
2
3
4
5
7
8
9
10
11
, . , , , .
IBM 1960 .
,
.
http://en.wikipedia.org/wiki/Luhn_algorithm
SQL. ,
.
146
12.2.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
27
28
29
31
32
33
34
35
36
37
38
12.2.
39
40
41
42
43
44
45
46
47
48
49
50
52
53
54
56
57
58
59
60
61
62
64
65
66
67
68
69
70
71
73
74
75
1
2
12.2.
3
4
5
7
8
9
10
11
------------t
(1 row )
Select luhn_verify (49927398714) ;
luhn_verify
------------f
(1 row )
IN. , . :
: (2,6,4,10,25,7,9)
.. 2 2 2 6 6 4 4
1
2
3
4
VALUES(3),(2),(6),(1),(4)
foo ,
foo.catalog_id ( foo.catalog_id
IN(3,2,6,1,4))
,
, (. quine) (
), .
SQL PostgreSQL.
Listing 12.13:
1
2
12.2.
quine ' ' ':: text as a , ':: text as a ':: text as b ) as quine ;
: https://gist.github.com/972335
LIKE
web2.0 .
LIKE some%, some ,
. ,
( ) .
LIKE 'bla%'
text_pattern_ops ( varchar_pattern_ops varchar). .
1
2
3
4
5
6
7
8
9
10
11
12
14
15
16
17
18
19
20
21
22
23
27
28
29
30
31
150
12.2.
33
34
35
36
37
41
44
45
46
47
48
49
50
52
53
54
55
56
57
58
62
65
66
67
68
69
70
71
72
73
75
151
12.2.
76
77
78
79
80
81
82
83
QUERY
PLAN
- -- -- - -- -- - -- -- - -- -- -- - -- -- - -- -- - -- -- - -- -- -- - -- -- - -- -- - -- -- - -- -- - -- -- -- - -- -- - Bitmap Heap Scan on tags ( cost =5.49..97.75 rows =121
width =26) ( actual time =0.025..0.025 rows =1 loops =1)
Filter : ( lower ( tag ) ~~ '0146% ':: text )
-> Bitmap Index Scan on i_tag ( cost =0.00..5.46 rows =120
width =0) ( actual time =0.016..0.016 rows =1 loops =1)
Index Cond : (( lower ( tag ) ~ >=~ '0146 ':: text ) AND
( lower ( tag ) ~ <~ '0147 ':: text ) )
Total runtime : 0.050 ms
(5 rows )
: https://gist.github.com/972713
152