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
PostgreSQL - maintenance -
Search
rm-rf-slant
July 29, 2015
Technology
0
110
PostgreSQL - maintenance -
rm-rf-slant
July 29, 2015
Tweet
Share
More Decks by rm-rf-slant
See All by rm-rf-slant
The story behind AbemaTV
rmrfslant
10
10k
Akamai Training Day2
rmrfslant
0
100
CloudでのMySQL
rmrfslant
0
75
Other Decks in Technology
See All in Technology
visionOSでの空間表現実装とImmersive Video表示について / ai-immersive-visionos
cyberagentdevelopers
PRO
1
110
カメラを用いた店内計測におけるオプトインの仕組みの実現 / ai-optin-camera
cyberagentdevelopers
PRO
1
120
オーティファイ会社紹介資料 / Autify Company Deck
autifyhq
9
120k
Commitment vs Harrisonism - Keynote for Scrum Niseko 2024
miholovesq
6
1.1k
20241031_AWS_生成AIハッカソン_GenMuck
tsumita
0
110
一休.comレストランにおけるRustの活用
kymmt90
3
590
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
5
49k
生成AIとAWS CDKで実現! 自社ブログレビューの効率化
ymae
2
330
[AWS JAPAN 生成AIハッカソン] Dialog の紹介
yoshimi0227
0
150
現地でMeet Upをやる場合の注意点〜反省点を添えて〜
shotashiratori
0
530
バクラクにおける可観測性向上の取り組み
yuu26
3
420
初心者に Vue.js を 教えるには
tsukuha
5
390
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
27
1.9k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Designing Experiences People Love
moore
138
23k
GraphQLとの向き合い方2022年版
quramy
43
13k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Facilitating Awesome Meetings
lara
49
6k
Being A Developer After 40
akosma
86
590k
Into the Great Unknown - MozCon
thekraken
31
1.5k
Fireside Chat
paigeccino
32
3k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
14
1.9k
Rails Girls Zürich Keynote
gr2m
93
13k
Designing on Purpose - Digital PM Summit 2013
jponch
115
6.9k
Transcript
PostgreSQL ~ςʔϒϧϝϯςφϯε~
Situa&on
@ςʔϒϧʹෆཁྖҬ͕େྔʹ͍ͬͯΔέʔε PostgreSQLͷσʔλߏهܕɻ ඇৗʹγϯϓϧʹMVCCϞσϧΛ࣮ݱ͍ͯ͠Δ͕ɺෆཁྖҬΛఆ ظతʹআ͢ΔͨΊͷॲཧΛ࣮ߦ͢Δඞཁ͕͋Δɻ ͦΕ͕ɺVACUUMॲཧ...!
@͓͞Β͍(MySQL(+(InnoDBͷ߹)(1/2 ෳςʔϒϧͷϨίʔυσʔλฒͼʹΠϯσοΫεσʔλΛ·ͱ ΊͯɺςʔϒϧεϖʔεͱݺͿσʔλϑΝΠϧʹ֨ೲ͢Δߏ ɻ ΑͬͯςʔϒϧͷϨίʔυ͕݅૿Ճ͢Δͱɺςʔϒϧεϖʔε ༻ͷσʔλϑΝΠϧͷ༰ྔ͕૿Ճɻ ͨͩ͠ɺϨίʔυ͕݅૿Ճ͢ΔͨͼʹϑΝΠϧαΠζ͕ঃʑʹ େ͖͘ͳΔΈͰͳ͍ɻ
@͓͞Β͍(MySQL(+(InnoDBͷ߹)(2/2 ઃఆͨ͠ҰఆαΠζͷϑΝΠϧΛ࡞͓͖ͯ͠ɺ༰ྔ͕ෆͨ͠ ࣌ʹ͡ΊͯϑΝΠϧαΠζΛେ͖͘͢ΔΈʹͳ͍ͬͯΔɻ ͨͩ͠ɺϨίʔυ͕݅૿Ճ͢ΔͨͼʹϑΝΠϧαΠζ͕ঃʑʹ େ͖͘ͳΔΈͰͳ͘ɺ ઃఆͨ͠ҰఆαΠζͷϑΝΠϧΛ࡞͓͖ͯ͠ɺ༰ྔ͕ෆͨ͠ ࣌ʹ͡ΊͯϑΝΠϧαΠζΛେ͖͘͢ΔΈɻ (MyISAMςʔϒϧ୯ҐͷϑΝΠϧͱ͍͏ҙຯͰগ͠ࣅͯΔ)
VACCUMॲཧ
@What's(that? • ෆཁྖҬͷ࠶ར༻ • τϥϯβΫγϣϯIDपճͷճආ
ෆཁྖҬͷ࠶ར༻
@VACCUMͷ෦ॲཧɹ1/2 1. ֤ςʔϒϧͷϖʔδΛઌ಄͔Βࠪ 2. VMΛνΣοΫͯ͠ෆཁߦΛؚΉϖʔδͳΒ3.ʹɺෆཁߦ͕ͳ͚ Ε࣍ͷϖʔδΛࠪ ※VM(Visibility*Map)*.*ςʔϒϧͷՄࢹੑͷஅʹར༻͢Δิॿ σʔλɻςʔϒϧ̍ϖʔδͷঢ়ଶΛ1bitͰཧ 3. ରϖʔδͷશߦΛࠪ͠ɺෆཁߦͷใΛநग़
@VACCUMͷ෦ॲཧɹ2/2 4"શϖʔδࠪޙɺෆཁߦ͕நग़͞Ε͍ͯΕରςʔϒϧͷΠ ϯσοΫεϝϯςφϯεΛߦ͍ɻෆཁߦͷআ 5"আͨ͠ߦͷใΛͱʹFSMΛߋ৽
@VMͱFSMʹΑΔԸܙ • VMͷใΛͱʹॲཧΛߦ͏͖ϖʔδΛߜΔͷͰɺෛՙͷ ܰݮ͕ظ͞ΕΔ • FSMʹΑͬͯɺߦ͕ޮΑ͘࠶ར༻͞ΕΔΑ͏ʹͳΔɻ͜Εʹ ΑͬͯςʔϒϧͷཧతͳංେԽΛ͑ɺσʔλϕʔεͷύϑ ΥʔϚϯεΛҡ࣋Ͱ͖Δ
XIDपճͷճආ
@What's(that? • ςʔϒϧʹσʔλΛ֨ೲ͢Δࡍɺ࣮ߦ͞ΕͨτϥϯβΫγϣϯ Λ۠ผͰ͖ΔΑ͏ʹɺXID͕ߦϔομ(xmin)ͱͯ֨͠ೲ͞ΕΔ • ࣮ߦதͷτϥϯβΫγϣϯɺ͕ࣗ࣋ͭXIDͱߦϔομͷ XID(xmin)ͷൺֱΛ͠ɺՄࢹorෆՄࢹͷஅΛ͢ΔΈ
@XIDपճ͕ى͜Δέʔε XID32bit(=40ԯ)Ͱཧ͞Ε͍ͯΔͷͰɺपճΛ܁Γฦ͢ɻ पճͨ͠τϥϯβΫγϣϯIDΛ࣋ͭτϥϯβΫγϣϯ͔Βطଘͷ σʔλΛݟΔͱɺՄࢹఆʹΑΓશͯͷσʔλ͕ݟ͑ͳ͘ͳΔݱ ͕ى͜Δɻ
ҙਤతʹϝϯςφϯεʁ ͳΜ͔ɺ໘ͳΠϝʔδ...
͔͠͠ʂ
PostgreSQL+8.3Ҏ͔߱ΒɺVACCUM ϝϯςφϯεࣗಈԽʂͨͩ͠...
@Demerit • ࣗಈόΩϡʔϜͷઃఆ͚ͩͰશʹ੍ޚͰ͖ͳ͍ɻςʔϒϧ ͕ංେԽ͠ɺੑೳʹӨڹΛٴ΅͢Մೳੑ͋Γ ※ࣗಈόΩϡʔϜɺALTER&TABLEͰର֎ʹͰ͖Δɻ ʢςʔϒϧΦϓγϣϯมߋʣ
VACCUM&FULL
@What's(that? VACCUMʹΑΔϝϯςφϯε͕ఆ௨Γʹػೳ͠ͳ͔ͬͨ ߹ͷରॲࡦɻ (VACCUMͱVACCUM'FULLผͳͷͰҙ) LongTransac*on͕ଘࡏ͍ͯ͠Δ߹ɺVACCUMػೳ͠ͳ͍ͷ Ͱɺͦ͏͍͏࣌ʹ͜ΕΛ༻ɻ ※LongTransac*onʹ͍ͭͯɺp211ࢀর
@important*point • VACUUM'FULLɺ࣮ߦதഉଞϩοΫɻ
@Summary • VACCUMେࣄ • VACCUM͕༗ޮʹͳΒͳ͍έʔε͕͋ΔࣄΛཧղ͠ɺͦͷ্Ͱ ରॲࡦΛݕ౼͢Δඞཁ͋Γ • جຊతʹɺࣗಈόΩϡʔϜorఆظతͳखಈόΩϡʔϜΛਖ਼ৗ ʹߦ͑ɺͳ͍
PostgreSQL ~indexϝϯςφϯε~
@ΠϯσοΫεͷΞΫηεੑೳ͕Լ͢Δ߹ͷݪҼ • ංେԽ • அยԽ • Ϋϥελੑͷܽམ
@ංେԽʹ͍ͭͯ • indexϑΝΠϧ͕ංେԽ͢ΔͱɺςʔϒϧͷංେԽͱൺྫͯ͠༗ ޮσʔλ͕গྔͰଟ͘ͷϖʔδ͕ར༻͞ΕΔ • ͦΕʹΑͬͯແବͳI/O͕ൃߦ͞ΕΔͷͰੑೳͷԼʹͭͳ͕ Δ • ɺpg_classͷrelpagesྻɺreltuplesྻͰ֬ೝ͢Δ͜ͱ͕Ͱ ͖Δ
@ංେԽͷ༧ࡦ ΓVACCUMͷग़൪ɻ VACCUMʹΑΓશʹۭͱͳΓɺ࠶ར༻Մೳͱͳͬͨindexϖʔ δ࠶ར༻͞ΕɺංେԽΛ͙ɻ ఆظతʹVACCUN͕ػೳ͍ͯ͠Εɺ͋·Γҙࣝ͢Δඞཁແ͍
@அยԽʹ͍ͭͯ • B#treeΠϯσοΫεݻ༗ͷࣄ • Ωϟογϡώοτޮ͕ѱԽ͠ɺੑೳʹӨڹΛٴ΅͢Մೳੑ͕ ͋Δ • ɺcontribϞδϡʔϧͷpgsta0upleʹؚ·ΕΔpgstaindex ؔͰ֬ೝ͢Δɻʢleaf_fragmenta8onΛݟΔʣ ※͜ͷௐࠪํ๏ɺൺֱతαʔόͷෛՙ͕ߴ͍ͷͰɺߟ͑ͯ
༻͢Δ͜ͱ
@அยԽͷ༧ࡦ ࣗಈόΩϡʔϜͰɺશͯͷindex͕͖Ε͍ʹ࠶ར༻Ͱ͖Δঢ়گ͕ ଓ͘ͱݶΒͳ͍ɻ அยԽʹΑΓindexϑΝΠϧͷαΠζ͕૿Ճ͢Δ߹ɺ REINDEXʹΑΔindexͷ࠶ఆٛΛߦ͏ɻ
@Ϋϥελੑͷܽམʹ͍ͭͯ • ӡ༻͍ͯ͠Δؒʹςʔϒϧσʔλͷཧతͳஔॱং͕ɺසൟ ʹར༻͞ΕΔindexͷฒͼॱͱဃ͍ͯ͠Δঢ়ଶʹͳΔ͜ͱ • ΠϯσοΫεεΩϟϯΛߦͬͯɺඞཁͳσʔλΛऔಘ͢Δͨ ΊʹෳͷϖʔδΛࢀর͠ͳ͚ΕͳΒͳ͍ͷͰɺI/O͕૿Ճ ͠ੑೳʹӨڹΛٴ΅͢ • ɺpg_statsϏϡʔͷcorrela1onΛ֬ೝ͢Δ
ʢp2185ද1471ࢀরʣ
@Ϋϥελੑͷܽམͷ༧ࡦ CLUSTERΛߦ͏ɻ ࣮ߦ࣌ʹɺVACCUM+FULLͱಉ༷ʹ࣍ͷʹҙ • Ұ࣌తʹରςʔϒϧ/indexͱಉఔͷ༰ྔ͕ඞཁʹͳΔ • CLUSTER࣮ߦ࣌ʹഉଞϩοΫΛऔಘ͢Δ ※CLUSTER࣮ߦ࣌ʹREINDEX࣮ࢪ͞ΕΔͷͰɺஅยԽͱΫϥ ελੑͷվળΛಉ࣌ʹ࣮ࢪ͍ͨ͠߹CLUSTERͷΈ࣮ࢪ͢Ε ແ͍
Index&Only&Scan
@What's(that? • Index'Only'ScanɺindexͷΈΛݕࡧͯ݁͠ՌΛฦ٫͢ΔΈ • ςʔϒϧσʔλͰͳ͘ɺVMΛ֬ೝ͢ΔܗͰ࣮ݱ͞Ε͍ͯΔ • PostgreSQL9.2͔Βಋೖ͞Εͨ
@important*point • ಛఆͷ݅Ͱ͔͠ޮՌ͕ൃشͰ͖ͳ͍ͷͰɺ༻͢Δ͜ͱࣗମ ͍͠ʢৄࡉp223ࢀরʣ • VMΛߋ৽ͨ͠ΓɺՄೳͳݶΓVACCUM͕࣮ߦ͞ΕΔΑ͏ͳ Λ͢Δඞཁ͕͋Δ
@Summary • ӡ༻Λଓ͚Δ͜ͱͰindexʹى͜ΔΛཧղ͢Δ • Ұ࿈ͷྲྀΕͱͯ͠ɺVACUUMʹΑΔ࠶ར༻ΛޮՌతʹߦ͍ɺ ੑೳͷӨڹ͕ஶ͍࣌͠ʹϝϯςφϯεظؒΛઃ͚ͯɺ REINDEXͱCLUSTERͰindexΛϝϯςφϯε͢Δ
Thank&you!