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
270
TRUG#54 - Z czym się je VueJS
aokon
0
230
TRUG#40 - Roda
aokon
0
230
Other Decks in Programming
See All in Programming
AI時代のFlutter品質設計 — アプリ品質を守るQuality Layers
omatty198
0
360
AI時代のシニアエンジニアとは
yosuke_furukawa
PRO
15
11k
DroidKnights 2026 Android A2UI Jetpack Compose 기반의 안전한 AI UI 렌더링 - 박제창
itsmedreamwalker
1
210
Kotlinize Is Not Just Converting to Kotlin
chigichan24
1
220
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
420
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
170
エージェントを使い続けるためのメタワーク / Meta-work for keeping using the agent
rkaga
6
2.2k
プロジェクトコードをキレイキレイしよう!暗黙的な参照を読み解く静的解析
ostk0069
0
210
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
740
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
150
AI時代のIaC入門 〜なぜインフラをコードで管理したいのか?〜 / Introduction to IaC in the AI Era
akihisaikeda
6
1.4k
Crash Auto Pipelines
veronikapj
1
400
Featured
See All Featured
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1.1k
30 Presentation Tips
portentint
PRO
1
460
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
760
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
930
How to build a perfect <img>
jonoalderson
1
6.2k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
610
Done Done
chrislema
187
17k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
750
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
680
Abbi's Birthday
coloredviolet
4
11k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
560
Building AI with AI
inesmontani
PRO
1
1.4k
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