Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
PostgreSQL - dlaczego moje zapytania są takie w...
Search
Adam Okoń
January 18, 2017
Programming
350
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
PostgreSQL - dlaczego moje zapytania są takie wolne?
Adam Okoń
January 18, 2017
More Decks by Adam Okoń
See All by Adam Okoń
Ruby on Serverless
aokon
0
120
TRUG#69 - Make frontend development great again in Rails
aokon
0
260
TRUG#60 - Webpack 2
aokon
0
260
TRUG#54 - Z czym się je VueJS
aokon
0
230
TRUG#40 - Roda
aokon
0
220
Other Decks in Programming
See All in Programming
最近”作らせてる” ローカルAIアプリの話
akit37
0
480
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2.5k
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
380
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
970
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
270
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
0
510
Simple Storage Service(S3) is not simple
iwatsukayura
0
290
パスワード再設定メールのURLについて知っておこう
uyuki234
0
160
Agents on Rails - Rails at Scale 2026
irinanazarova
0
570
Featured
See All Featured
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
600
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.1k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.3k
The Cult of Friendly URLs
andyhume
79
7k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
570
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.7k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
760
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
890
Transcript
PostgreSQL - Dlaczego moje zapytania są takie wolne? Adam Okoń
Elegant Code
None
None
None
Przykładowy EXPLAIN
W jaki sposób możemy poprawić wrażenia z korzystania z psql?
W jaki sposób możemy zlokalizować wolne zapytania? Jak podejść do tematu analizy i optymalizacji zapytań? Rozkład jazdy
W jaki sposób mogę poprawić wrażenia z korzystania z psql?
Pimp my psql przy pomocy .psqlrc https:/ /github.com/thoughtbot/dotfiles/blob/ master/psqlrc
pgcli https:/ /github.com/dbcli/pgcli
W jaki sposób zlokalizować wolne zapytania?
None
pg_stat_statements Wymagane: postgresql-contrib
Przykładowa konfiguracja w pliku postgresql.conf
None
SELECT (total_time / 1000 / 60) as total_minutes, (total_time/calls) as
average_time, query FROM pg_stat_statements ORDER BY 1 DESC LIMIT 100; http:/ /www.craigkerstiens.com/2013/01/10/more-on-postgres- performance/
Jak podejść do tematu analizy i optymalizacji?
Przykładowy EXPLAIN
Czy możemy wyciągnąć więcej informacji na temat zapytania przy pomocy
EXPLAIN?
None
Dla nieprzekonanych EXPLAIN z poziomu ActiveRecord https:/ /github.com/bradurani/pg-eyeballs
Analiza zapytania - counting
Analiza zapytania - filtrowanie
Analiza zapytania - sortowanie
Optymalizacja zapytania przez dodanie indeksów
Indeksy warunkowe SELECT * FROM events WHERE user_id = 1
AND active = TRUE; CREATE INDEX index_events_on_created_at ON events USING btree (user_id) WHERE active = TRUE;
https:/ /coderwall.com/p/9hxejg/advanced-rails- indexing-where-clause-postgresql Jak dodać indeks warunkowy w migracji ActiveRecord
Co możemy zrobić kiedy mamy duży zbiór danych i chcemy
dodać indeks na bazie produkcyjnej?
Jak dodać indeks współbieżnie w migracji ActiveRecord https:/ /robots.thoughtbot.com/how-to-create- postgres-indexes-concurrently-in
Zrozumieć wykorzystanie indeksów SELECT relname, 100 * idx_scan / (seq_scan
+ idx_scan) percent_of_times_index_used, n_live_tup rows_in_table FROM pg_stat_user_tables WHERE seq_scan + idx_scan > 0 ORDER BY n_live_tup DESC; http:/ /www.craigkerstiens.com/2012/10/01/understanding-postgres- performance/
Przydatne linki https:/ /www.postgresql.org/docs/current/static/using-explain.html https:/ /robots.thoughtbot.com/reading-an-explain-analyze-query-plan http:/ /www.craigkerstiens.com/2012/10/01/understanding- postgres-performance/ https:/
/devcenter.heroku.com/articles/postgresql-indexes http:/ /blog.redpanthers.co/optimising-postgresql-database-query- using-indexes/ http:/ /tatiyants.com/pev/#/plans/new https:/ /www.amazon.com/gp/product/184951030X
Dzięki! Adam Okoń (@adamokon) https:/ /github.com/aokon