The Best of Bruce's Postgres Slides: Ruce Omjian
The Best of Bruce's Postgres Slides: Ruce Omjian
BRUCE MOMJIAN
This talk has the best slides from my 25+ Postgres presentations.
Creative Commons Attribution License http://momjian.us/presentations
Last updated: May, 2017
1 / 26
Postgres System Architecture
Main
Libpq
Postmaster
Postgres Postgres
Parse Statement
utility Utility
Traffic Cop
Command
Query e.g. CREATE TABLE, COPY
SELECT, INSERT, UPDATE, DELETE
Rewrite Query
Generate Paths
Optimal Path
Generate Plan
Plan
Execute Plan
()
rk
postmaster fo postgres postgres
../administration/buffer_stack.eps
Parse Statement
utility Utility
Traffic Cop Command
Query e.g. CREATE TABLE, COPY
SELECT, INSERT, UPDATE, DELETE
Rewrite Query
Generate Paths
Optimal Path
Generate Plan
Plan
Execute Plan
6 / 26
EXPLAIN with Constants of Various Frequencies
l | count | lookup_letter
---+-------+-----------------------------------------------------------------------
p | 199 | Seq Scan on sample (cost=0.00..13.16 rows=199 width=2)
s | 9 | Seq Scan on sample (cost=0.00..13.16 rows=9 width=2)
c | 8 | Seq Scan on sample (cost=0.00..13.16 rows=8 width=2)
r | 7 | Seq Scan on sample (cost=0.00..13.16 rows=7 width=2)
t | 5 | Bitmap Heap Scan on sample (cost=4.29..12.76 rows=5 width=2)
f | 4 | Bitmap Heap Scan on sample (cost=4.28..12.74 rows=4 width=2)
v | 4 | Bitmap Heap Scan on sample (cost=4.28..12.74 rows=4 width=2)
d | 4 | Bitmap Heap Scan on sample (cost=4.28..12.74 rows=4 width=2)
a | 3 | Bitmap Heap Scan on sample (cost=4.27..11.38 rows=3 width=2)
_ | 3 | Bitmap Heap Scan on sample (cost=4.27..11.38 rows=3 width=2)
u | 3 | Bitmap Heap Scan on sample (cost=4.27..11.38 rows=3 width=2)
e | 2 | Index Scan using i_sample on sample (cost=0.00..8.27 rows=1 width=2)
i | 1 | Index Scan using i_sample on sample (cost=0.00..8.27 rows=1 width=2)
k | 1 | Index Scan using i_sample on sample (cost=0.00..8.27 rows=1 width=2)
(14 rows)
7 / 26
Deadlocks
(10 rows)
8 / 26
MVCC Behavior
Cre 40
Exp INSERT
Cre 40
Exp 47 DELETE
Create−Only
Cre 50 Snapshot
Exp Invisible
Cre 30
Exp 110 Visible
Internally, the creation xid is stored in the system column ’xmin’, and expire in ’xmax’.
MVCC Unmasked
10 / 26
Heap Page Structure
8K
Tuple
11 / 26
Pg_upgrade: Restore Schema In New Cluster
pg_dumpall − −schema
2 5 8 2 5 8
3 6 9 3 6 9
pg_class pg_class
10 16 22 10 16 22
11 17 23 11 17 23
12 18 24 12 18 24
13 19 25 13 19 25
14 20 26 14 20 26
15 21 27 15 21 27
clog clog
2 5 8 2 5 8
3 6 9 3 6 9
pg_class pg_class
10 16 22 10 16 22
11 17 23 11 17 23
12 18 24 12 18 24
13 19 25 13 19 25
14 20 26 14 20 26
15 21 27 15 21 27
clog clog
0
:0
:0
:0
:0
02
09
11
13
WAL AL AL
W W
14 / 26
Point-in-Time Recovery
5
:0
:3
:4
:5
17
17
17
17
WAL
AL AL
W W
15 / 26
Streaming Replication Setup
0
:0
:0
:0
:0
02
09
11
13
WAL AL AL
W W
16 / 26
Streaming Replication in Operation
Primary Standby
Network
/pg_xlog /pg_xlog
pgpool
INSERT, UPDATE, SELECT
DELETE to master to any host
host
111111111111
000000000000 1111111111111
0000000000000
0000000000000
1111111111111
000000000000
111111111111 0000000000000
1111111111111
streaming 000000000000
111111111111
000000000000
111111111111 0000000000000
1111111111111
000000000000
111111111111
replication 0000000000000
1111111111111
000000000000
111111111111 0000000000000
1111111111111
0000000000000
1111111111111
000000000000
111111111111 0000000000000
1111111111111
000000000000
111111111111
Master Slave Slave
replication
SQL Queries
PG FDW
SQL Queries
with joins, sorts, aggregates
111111111111111111111111
000000000000000000000000 11111111111111111111111
00000000000000000000000 11111111111111111111111
00000000000000000000000
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111 00000000000000000000000
11111111111111111111111
00000000000000000000000
11111111111111111111111 00000000000000000000000
11111111111111111111111
00000000000000000000000
11111111111111111111111
000000000000000000000000
111111111111111111111111
000000000000000000000000
111111111111111111111111 00000000000000000000000
11111111111111111111111
00000000000000000000000
11111111111111111111111 00000000000000000000000
11111111111111111111111
00000000000000000000000
11111111111111111111111
000000000000000000000000
111111111111111111111111
Foreign Server
00000000000000000000000
11111111111111111111111
Foreign Server
00000000000000000000000
11111111111111111111111
Foreign Server
000000000000000000000000
111111111111111111111111 00000000000000000000000
11111111111111111111111 00000000000000000000000
11111111111111111111111
The Future of Postgres Sharding
19 / 26
Database Server Hardware Priorities
CPU
Memory
I/O
20 / 26
Postgres’s Central Role
Oracle ISN
PostGIS
MongoDB
Foreign Data Extensions
Wrappers PL/R
Twitter
Postgres
\do @>
List of operators
Schema | Name | Left arg type | Right arg type | Result type | Description
------------+------+---------------+----------------+-------------+-------------
pg_catalog | @> | aclitem[] | aclitem | boolean | contains
pg_catalog | @> | anyarray | anyarray | boolean | contains
pg_catalog | @> | anyrange | anyelement | boolean | contains
pg_catalog | @> | anyrange | anyrange | boolean | contains
pg_catalog | @> | box | box | boolean | contains
pg_catalog | @> | box | point | boolean | contains
pg_catalog | @> | circle | circle | boolean | contains
pg_catalog | @> | circle | point | boolean | contains
pg_catalog | @> | jsonb | jsonb | boolean | contains
pg_catalog | @> | path | point | boolean | contains
pg_catalog | @> | polygon | point | boolean | contains
pg_catalog | @> | polygon | polygon | boolean | contains
pg_catalog | @> | tsquery | tsquery | boolean | contains
Non-Relational Postgres
22 / 26
Postgres System Tables
pg_database pg_trigger pg_aggregate pg_amproc
datlastsysoid tgrelid aggfnoid amopclaid
pg_conversion tgfoid aggtransfn amproc
conproc aggfinalfn
pg_language aggtranstype
24 / 26
SSL ’VERIFY-CA’ Is Secure
From Spoofing
server.crt
25 / 26
Conclusion: Release Dates and Sizes After 2000
26 / 26