Save
Tech
Postgres
Save
Share
Learn
Content
Leaderboard
Share
Learn
Created by
Irfan Habib
Visit profile
Cards (24)
Big Table Problems
Adding
Columns
Adding
Constraints
Index Creation
Unused Indexes
Skewed Data
Vacuum
Large
single table
Wasted
Table Space
View source
Big Table Problem: Index Creation
1.
CREATE
INDEX ON customers (last_name, first_name)
2. Locking bad
3.
Create
Index
Concurrently
4.
Quick
lock
5. Runtime
tradeoff
6. You
break
it you
clean
it up
7.
CREATE
INDEX CONCURRENTLY
View source
Big Table Problem:
Unused
Indexes
1. Index
analysis
/
cleanup
2. Combine btrees where they make sense
3.
Pg
_stat_user_
indexes
4.
Pg
_statio_user_
indexes
5. Look for unused indexes
6. Unused on primary != unused in cluster
7. Reset for
active
stats
8. Gather data on
all
nodes
View source
Big Table Problem: Skewed Data
1. Create
Partial
indexes
2. CREATE INDEX foo … WHERE bar =
1
3.
Faster
updates
4. Only
relevant
data
View source
Big Table Problem:
Vacuum
1.
Vacuum
required for
performance
2.
High xacts
=
wraparound autovacs
3.
Long
vacuums &
less
frequent vacuums
4. Vacuum-related
configuration
5.
Autovacuum
_workers =
6
6. Maintenance
_work_mem =
30GB
7.
Tune autovacuum
8. autovacuum_vacuum_insert_scale_factor=0
9. autovacuum_vacuum_insert_threshold=<constant>
View source
Big Table Problem: Large single table
1.
Partitioning
2. Queries don't need to know
3. Can tune/index partitions
individually
4. Break into smaller tables
5.
ATTACH PARTITION
6.
DETACH PARTITION
View source
Partitioning
helps with data
lifecycle
management
View source
Partitioning
is not a magic bullet
View source
Migrating
is a "project"
View source
Partitioner's
Paradox
View source
Big Table Problem: Wasted Table Space
1.
Optimize
Table Size
2.
Fixed-size
,
largest
to smallest
3. Variable
length
or NULLable
last
4. Order by
size
View source
30%
savings can be achieved by optimizing
table size
View source
High Transaction Problems
WAL
Generation
High
xid
pgBouncer
View source
WAL Size Workarounds
1.
Async archive
/
restore
2.
Daemon mode
3.
Pgbackrest
4.
Switches
to
streaming
5.
Replica catches up
6. Force
restore failure
View source
High Transaction Problems: High xid
1. Tune
VACUUM
2. Remove
SAVEPOINTs
3. Use
bigints
for ids
View source
PgBouncer solution
1.
Multi-Bouncer
2. Use
Systemd
to multiplex
3.
Semi-Arbitrary
numbers of
concurrent
PgBouncers
View source
Read Replica Problems
Management
Different Query Workloads
Lag
SAVEPOINT
Long running analytics
View source
Read Replica Problems: Management
1.
Automate
tool chains
2. Managed
Postgres
+ APIs
3.
Centralize
Monitoring & Data
Collection
View source
Read Replica Problems: Different Query Workloads
1.
Tuning
/
analysis
over time/trending
2. Can write back to
primary
to give stats
history
3.
Third-party
services
View source
Read Replica Problems:
Lag
1.
Statement timeouts
2. Max
standby archive delay
3. Max
standby streaming delay
View source
Read Replica Problems: SAVEPOINT
1.
Underlying
app changes
2.
Review
subtransactions
View source
Read Replica Problems: Long running analytics
1. Hot_standby_feedback =
off
2. Not
streaming
3. Dedicating specific replicas to
analytics
only
4. Archive only
replica
View source
How did we tame the
Mastodon
?
View source
Ways to tame the
Mastodon
Minimize
locks
Be smart about indexing
Per table
vacuum
tuning
Partition
if you can
Design
schema to minimize space
Look at multi
pgBouncer
Planned
replicas
View source
See similar decks
Postres
GCSE Spanish
47 cards
Postgres Query Optmisation
Tech
134 cards
Posture
17 cards
Posture
Sports Science > Influencing the risk of Injury
21 cards
posters
biology > unit 1
34 cards
Posture
Anatomy & Physiology > Skeletal System
5 cards
Posters
Design Optional
4 cards
posture
Psych GCSE > Language, thought, communication > types of communciation
12 cards
Posters
Media Studies
113 cards
posters
media
3 cards
TECH
36 cards
Tech
29 cards
Tech
Engineering paper 1
52 cards
tech
12 cards
tech
35 cards
materials
41 cards
Tech
127 cards
tech
11 cards
Tech
12 cards
Tech
20 cards
Tech
46 cards