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
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
2
590
TypeScriptの次なる大進化なるか!? 条件型を返り値とする関数の型推論
uhyo
2
1.6k
社内で最大の技術的負債のリファクタリングに取り組んだお話し
kidooonn
1
550
個人でもIAM Identity Centerを使おう!(アクセス管理編)
ryder472
3
200
SREによる隣接領域への越境とその先の信頼性
shonansurvivors
2
520
SSMRunbook作成の勘所_20241120
koichiotomo
2
130
ハイパーパラメータチューニングって何をしているの
toridori_dev
0
140
Engineer Career Talk
lycorp_recruit_jp
0
150
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
300
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
170
【Startup CTO of the Year 2024 / Audience Award】アセンド取締役CTO 丹羽健
niwatakeru
0
990
オープンソースAIとは何か? --「オープンソースAIの定義 v1.0」詳細解説
shujisado
7
800
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Writing Fast Ruby
sferik
627
61k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
How to train your dragon (web standard)
notwaldorf
88
5.7k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Music & Morning Musume
bryan
46
6.2k
Into the Great Unknown - MozCon
thekraken
32
1.5k
The Language of Interfaces
destraynor
154
24k
Optimizing for Happiness
mojombo
376
70k
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!