Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RDB(ぽすぐれ)チューニング入門/rdb-tuning-introduction-for-p...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
aono
October 09, 2024
Programming
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RDB(ぽすぐれ)チューニング入門/rdb-tuning-introduction-for-postgresql
aono
October 09, 2024
More Decks by aono
See All by aono
Dockerfileチョットカケルになろう/dockerfile-next-steps
awonosuke
0
78
Other Decks in Programming
See All in Programming
in-process GraphQL のすすめ #ginzajs
izumin5210
4
1.5k
Go を使い始めて 2 ヶ月の学び / My first two months with Go
contour_gara
0
390
高専、大学編入、そして未踏へ〜プロダクト開発とキャリアの歩み - Technical College, University Transfer, and On to “Mitou” / My Journey in Product Development and Career
pkmiya
0
100
承認済みなのに差戻しできてしまうバグ、型で潰せます
shinchit
0
120
複数の Claude Code が"放置"されてしまう問題をCLI ダッシュボードを自作して解決した話
sumihiro3
1
740
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
170
コンパウンドプロダクト開発のためのローカルプロセスマネージャー再発明 #layerxgo
izumin5210
0
460
Hello, Hiroshima Geospatial Data! — Exploring DoboX with Python
ra0kley
0
110
初めての模倣学習とVLA
natsutan
0
320
私のClaude Code活用法 (個人開発編) - PHPerKaigi mini #4(2026/08/24)
panda_program
1
190
Jindong: Introducing Declarative Haptics in Compose Multiplatform
l2hyunwoo
0
130
Webエンジニアなのにブラウザの仕組みがわからないので、Pythonで自作してみた
tatsuki12
4
1.1k
Featured
See All Featured
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
410
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
300
Paper Plane
katiecoart
PRO
2
53k
First, design no harm
axbom
PRO
2
1.3k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
260
Leo the Paperboy
mayatellez
8
2.2k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
630
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Odyssey Design
rkendrick25
PRO
2
780
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Are puppies a ranking factor?
jonoalderson
2
3.8k
Transcript
RDB(ぽすぐれ)チューニング入門
目次 1. RDBチューニング_戦略編 2. RDBチューニング_戦術編 3. まとめ 4. 補足
RDBチューニング_戦略編 • 早めに削る • 効率的に削る • チートで削る
RDBチューニング_戦略編 • ep. 0: 遅いクエリはEXPLAINで実行計画を見る ◦ 遅い原因を特定してから適切な対応をする ◦ そもそも遅いクエリを検知できないといけない→スロークエリの監視をする •
早めに削る • 効率的に削る • チートで削る
RDBチューニング_戦術編 • 早めに削る ◦ テーブルを小さくする ▪ テーブル分割 • パーティション(RANGE・LIST・HASH) •
シャーディング ◦ SQLの評価順を意識して削る(細かいとこは割愛) ▪ FROM→サブクエリとかとか ▪ ON, JOIN ▪ WHERE ▪ GROUP BY ▪ HAVING ▪ SELECT ▪ DISTINCT ▪ ORDER BY ▪ LIMIT
RDBチューニング_戦術編 • 早めに削る • 効率的に削る ◦ joinしない→サマリテーブル(=非正規化) ◦ 不要データを削ぐ ▪
ON句、WHERE句 ▪ SELECT句でカラム選択 ◦ パーティショニング ◦ ページネーション • チートで削る
RDBチューニング_戦術編 • 早めに削る • 効率的に削る • チートで削る ◦ クエリ呼び出しを減らす ▪
アプリケーション側での制御 ◦ indexを張る ▪ 複合indexのカラム順番大事→ユースケースを意識(参考) • CREATE INDEX hoge_index ON fuga USING btree (c3, c1, c2 DESC) ▪ カバリングインデックス ◦ RDBMSのパラメータチューニング(参考:DBサーバのスペックで推奨値を算出) ▪ shared_buffers、work_mem、effective_cache_sizeとかがパフォーマンス直結 ◦ お金で解決(💸👋) ▪ DBサーバのスペック上げる ▪ リードレプリカを増やす ◦ RDBを利用しない ▪ NoSQL ▪ NewSQL(SQLがインターフェース)
まとめ • 戦略を立てるの大事 ◦ 初手index張って改善しようとしてあまりうまく行かなかった ▪ 敵を知って戦う準備を整える • 調査と泥臭い検証 ◦
実行計画見よう ◦ 何か試す→実行計画見よう ▪ データ量によっても実行計画が変わる→統計情報を定期的にアップデート
補足 • 機械学習を利用したパラメータチューニングとかもあるらしい ◦ https://pgecons-sec-tech.github.io/tech-report/html_wg3_ml_tuning/wg3_ml_tun ing.html
参考 • PostgreSQL 日本語ドキュメント • [富士通] PostgreSQL技術インデックス • 複合indexの正しい順序 •
Where狙いのキー、order by狙いのキー • PostgreSQLの実行計画を読み解くための参考資料集