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
aono
October 09, 2024
Programming
160
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
70
Other Decks in Programming
See All in Programming
5分で問診!Composer セキュリティ健康診断
codmoninc
0
340
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
110
symfony/aiとlaravel/boost
77web
0
130
AIエージェントで 変わるAndroid開発環境
takahirom
2
680
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
7
1.9k
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
360
関数型プログラミングのメリットって何だろう?
wanko_it
0
180
AI時代、エンジニアはどう育つのか -未経験エンジニアの成長を間近で見て考えたこと-
thasu0123
0
130
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
170
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
150
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
380
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
8
4.4k
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
37
7.4k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
360
How STYLIGHT went responsive
nonsquared
100
6.2k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
67
56k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
610
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
150
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
390
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
510
Writing Fast Ruby
sferik
630
63k
[SF Ruby Conf 2025] Rails X
palkan
2
1.2k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Building an army of robots
kneath
306
46k
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の実行計画を読み解くための参考資料集