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
Oracle Exadata Database Service(Dedicated Infrastructure):サービス概要のご紹介
oracle4engineer
PRO
0
12k
Amazon Q Developerで.NET Frameworkプロジェクトをモダナイズしてみた
kenichirokimura
1
200
dbtを中心にして組織のアジリティとガバナンスのトレードオンを考えてみた
gappy50
0
300
実践! ソフトウェアエンジニアリングの価値の計測 ── Effort、Output、Outcome、Impact
nomuson
0
2.1k
Evolving Architecture
rainerhahnekamp
3
260
商品レコメンドでのexplicit negative feedbackの活用
alpicola
2
370
生成AIのビジネス活用
seosoft
0
110
【JAWS-UG大阪 reInvent reCap LT大会 サンバが始まったら強制終了】“1分”で初めてのソロ参戦reInventを数字で振り返りながら反省する
ttelltte
0
140
When Windows Meets Kubernetes…
pichuang
0
310
デジタルアイデンティティ人材育成推進ワーキンググループ 翻訳サブワーキンググループ 活動報告 / 20250114-OIDF-J-EduWG-TranslationSWG
oidfj
0
550
KMP with Crashlytics
sansantech
PRO
0
250
ドメイン駆動設計の実践により事業の成長スピードと保守性を両立するショッピングクーポン
lycorptech_jp
PRO
13
2.4k
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1030
460k
Making Projects Easy
brettharned
116
6k
It's Worth the Effort
3n
183
28k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
Producing Creativity
orderedlist
PRO
343
39k
Site-Speed That Sticks
csswizardry
3
270
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.3k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
3
180
Typedesign – Prime Four
hannesfritz
40
2.5k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
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!