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のアップグレード
Search
ester41
March 17, 2019
3.4k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
こわくないPostgreSQLのアップグレード
ester41
March 17, 2019
More Decks by ester41
See All by ester41
PostgreSQLのレプリケーションを使ってみよう / PostgreSQL 13 Replication
ester41
1
910
はじめてのPostgreSQLモニタリング入門 / PostgreSQL 11 Monitoring
ester41
17
3.8k
PostgreSQL11 設定パラメーター解体新書 / PostgreSQL 11 parameter
ester41
2
4.2k
PostgreSQLデプロイの基礎
ester41
1
1.4k
Featured
See All Featured
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
320
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
590
Being A Developer After 40
akosma
91
590k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
エンジニアに許された特別な時間の終わり
watany
107
250k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Building the Perfect Custom Keyboard
takai
2
790
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
230
Design in an AI World
tapps
1
240
Music & Morning Musume
bryan
47
7.2k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.3k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
610
Transcript
͜Θ͘ͳ͍PostgreSQLͷ ΞοϓάϨʔυ Mastodonαʔόʔษڧձ
͡Ίʹ ֎෦ʹެ։͍ͯ͠ΔαʔϏεɺ ͖ͪΜͱΞοϓσʔτ ·ͨΞοϓάϨʔυ͍ͯ͠·͔͢ʁ
͡Ίʹ ݟ͍͑ͯΔιϑτ͚ͩͰͳ͘ɺ όοΫͰಈ͍͍ͯΔιϑτ ߋ৽͕ඞཁͰ͢ɻ
͡Ίʹ MastodonͷཪଆͰಈ͍͍ͯΔ PostgreSQLʹযΛͯͯɺ ΞοϓάϨʔυͷղઆ͠·͢ɻ
͡Ίʹ ຊηογϣϯͰɺMastodonͰ༻͞Ε͍ͯΔɺ PostgreSQL 9.5·ͨ9.6͔Β11ͷͷΞοϓάϨʔυͷղ આΛߦ͍·͢ɻ RedHatܥͷඇDockerͳMastodonͰղઆ͠·͢ɻ ແఀࢭͰΞοϓάϨʔυ͢Δ͜ͱͰ͖·ͤΜɻ (ํ๏͋Γ·͕͢ɺઆ໌ର֎ͱ͠·͢ɻ)
ΞδΣϯμ ࣗݾհ PostgreSQLʹ͍ͭͯ PostgreSQLͷΞοϓάϨʔυʹ͍ͭͯ ΞοϓάϨʔυํ๏ ऴΘΓʹ
ࣗݾհ ໊લ: ࣉ େً(ͯΒ͏ͪ ͍͖ͨ) ॴଐ: ຊPostgreSQLϢʔβձ ؔࢧ෦ Twitter/GitHub: @ester41
ࣄ: อकɾઃܭɾ։ൃͳͲSE࡞ۀશൠ
MastodonͷPostgreSQL ग़య: https://handon.hatenablog.jp/entry/2018/12/18/004652
PostgreSQLʹ͍ͭͯ Mastodonͱಉ͡OSS(ΦʔϓϯιʔειϑτΣΞ)Ͱ͋Γɺ RDBMS(ؔσʔλϕʔεཧγεςϜ)ͱݺΕΔϛυϧΣΞͰ͢ɻ େֶͷݚڀࣨੜ·ΕͷͨΊɺඪ४SQLͷ४ڌൺֱత ߴ͘ͳ͍ͬͯ·͢ɻ(MySQLͷΑ͏ͳΫη͕গͳ͍ɻ) όʔδϣϯ൪߸ͷॻࣜ৽چͷ2छྨଘࡏ͠·͢ɻ چ: 9.6.12 => ࠨ͔Β2ͭͷࣈ͕ϝδϟʔόʔδϣϯͰɺ
Γ͕ϚΠφʔόʔδϣϯ ৽: 11.2 => ෦͕ϝδϟʔόʔδϣϯͰɺ খ෦͕ϚΠφʔόʔδϣϯ
PostgreSQLͷ ΞοϓάϨʔυʹ͍ͭͯ(1/3) PostgreSQLجຊతʹޙํޓΛେʹ͍ͯ͠·͕͢ɺ ϝδϟʔόʔδϣϯΞοϓͰ෦༷͕มߋʹͳΔ߹͕͋Γ·͢ɻ (SQLߏจͷมߋɺΊͬͨͳ͜ͱ͕ͳ͍ݶΓมߋ͞Ε·ͤΜɻ) ϝδϟʔόʔδϣϯΞοϓΛߦ͏ࡍมߋΛ֬ೝ͠ɺ ༻͍ͯ͠ΔπʔϧͷରԠঢ়گΛ֬ೝ͍ͯͩ͘͠͞ɻ ΞοϓάϨʔυΛߦ͏߹ɺσʔλͷίϯόʔτॲཧ͕ ඞཁͱͳΓ·͢ɻ
PostgreSQLͷ ΞοϓάϨʔυʹ͍ͭͯ(2/3) PostgreSQLͷΞοϓάϨʔυॲཧʹɺෳͷํ๏͕ଘࡏ͠·͢ɻ pg_dumpallͰόοΫΞοϓΛऔಘ͠ɺ৽͍͠όʔδϣϯͰϩʔυ͢ Δɻ pg_upgradeͰݹ͍σʔλΛ৽͍͠σʔλʹίϯόʔτ͢Δɻ ࠓճɺͪ͜ΒͰΞοϓάϨʔυ͠·͢ɻ Slony-1ͰҟόʔδϣϯؒϨϓϦέʔγϣϯΛ༻͍Δɻ
PostgreSQLͷ ΞοϓάϨʔυʹ͍ͭͯ(3/3) ϨϓϦέʔγϣϯΛΜͰ͍Δ߹ɺҰׅͯ͠ΞοϓάϨʔυΛߦ ͏ඞཁ͕͋Γ·͢ɻ ֦ுػೳΛಋೖ͍ͯ͠Δ߹ɺΞοϓάϨʔυޙͷPostgreSQLʹ࠶ ಋೖ͢Δඞཁ͕͋Γ·͢ɻ ίωΫγϣϯϓʔϥʔͷιϑτΛಋೖ͍ͯ͠Δ߹ɺΞοϓάϨʔ υޙͷόʔδϣϯʹରԠ͍ͯ͠Δ͔֬ೝΛߦ͍ͬͯͩ͘͞ɻ
ΞοϓάϨʔυํ๏ 1. MastodonఀࢭɺσʔλͷόοΫΞοϓ σʔλϕʔεͷΞοϓάϨʔυʹࣦഊͨ͠߹Λߟྀ͠ɺσʔλϕʔε ͷόοΫΞοϓΛऔಘ͠·͢ɻ όοΫΞοϓͷऔಘޙʹσʔλߋ৽͕ൃੜ͠ͳ͍Α͏ɺMastodonͷఀ ࢭΛߦ͍·͢ɻ $ sudo systemctl
stop mastodon* $ pg_dump -F tar mastodon_production > mastodon_backup.tar
ΞοϓάϨʔυํ๏ 2. ৽͍͠PostgreSQLͷಋೖ ݹ͍PostgreSQLΛఀࢭޙɺ৽͍͠PostgreSQLΛಋೖ͠·͢ɻ $ su - # systemctl stop
postgresql-9.6 # systemctl disable postgresql-9.6 # yum install -y https://download.postgresql.org/pub/repos/yum/11/ redhat/rhel-7-x86_64/pgdg-redhat11-11-2.noarch.rpm # yum install -y postgresql11-server postgresql11-contrib postgresql11-devel postgresql11-libs # cd /usr/pgsql-11/bin/ # export PGSETUP_INITDB_OPTIONS="-E UTF-8 --locale=C" # ./postgresql-11-setup initdb
ΞοϓάϨʔυํ๏ 3. σʔλͷΞοϓάϨʔυɺىಈ ݹ͍PostgreSQLͷσʔλΛɺ৽͍͠PostgreSQLʹҠߦ͠·͢ɻ # su - postgres $ /usr/pgsql-11/bin/pg_upgrade
-b /usr/pgsql-9.6/bin/ -B /usr/ pgsql-11/bin/ -d /var/lib/pgsql/9.6/data/ -D /var/lib/pgsql/11/data/ $ vim /var/lib/pgsql/11/data/postgresql.conf pg_hba.conf $ exit # systemctl start postgresql-11 # systemctl enable postgresql-11 # su - postgres $ ./analyze_new_cluster.sh $ exit # exit
ΞοϓάϨʔυํ๏ 4. Ruby༻PostgreSQLଓϥΠϒϥϦͷߋ৽(1/2) MastodonͷPostgreSQLଓ༻ϥΠϒϥϦpgɺlibpqͱݺΕΔϥΠϒ ϥϦΛϦϯΫ͍ͯ͠·͢ɻ libpqͱɺCݴޠͰॻ͔ΕͨPostgreSQLͷΠϯλʔϑΣʔεϥΠϒϥϦ ͱͳΓ·͢ɻ( https://www.postgresql.jp/document/10/html/ ) ͜ͷ··چPostgreSQLΛআͯ͠͠·͏ͱɺMastodon͔ΒPostgreSQL
ʹଓͰ͖ͳ͘ͳͬͯ͠·͍·͢ɻ ͦͷͨΊɺϥΠϒϥϦͷ࠶ϦϯΫ(࠶ίϯύΠϧ)͕ඞཁͱͳΓ·͢ɻ $ ldd vendor/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0- static/pg-1.1.4/pg_ext.so | grep libpq libpq.so.5 => /usr/pgsql-9.6/lib/libpq.so.5 (0x00007fc0598e4000)
ΞοϓάϨʔυํ๏ 4. Ruby༻PostgreSQLଓϥΠϒϥϦͷߋ৽(2/2) Gemͷ࠶ίϯύΠϧΛߦ͍·͢ɻ (RubyͷίϚϯυʹ͍ͭͯܮ͕ਂ͋͘Γ·ͤΜͷͰɺશϥΠϒϥϦͷ ࠶ίϯύΠϧ͕Γ·͢ɻͬͱ͍͍ํ๏͕͋Εڭ͑ͯͩ͘͞ ͍ɻɻɻ) $ bundle config
build.pg --with-pg-config=/usr/pgsql-11/bin/ pg_config $ bundle install --force $ ldd vendor/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0- static/pg-1.1.4/pg_ext.so | grep libpq libpq.so.5 => /usr/pgsql-11/lib/libpq.so.5 (0x00007f0fea6b5000)
ΞοϓάϨʔυํ๏ 5. Mastodonͷىಈɺಈ࡞֬ೝɺچσʔλআ MastodonΛىಈ͠ɺਖ਼ৗʹಈ࡞͢Δ͔֬ೝ͠·͢ɻ ͳ͚ΕɺچPostgreSQLΛআ͠·͢ɻ $ su - # systemctl
start mastodon-web mastodon-sidekiq mastodon-streaming # su - postgresql $ ./delete_old_cluster.sh $ rm -f analyze_new_cluster.sh delete_old_cluster.sh $ exit # yum remove postgresql96-contrib postgresql96-libs postgresql96- devel postgresql96-server postgresql96 # exit
Φεεϝͷॻ੶ PostgreSQLʹ͍͍͔ͭͯͪΒֶΔॻ੶Ͱ͢ʂ
Φεεϝͷॻ੶ PostgreSQLΛ҆ఆͯ͠ಈ͔ͨ͢ΊʹࢀߟͱͳΔຊͰ͢ʂ
ऴΘΓʹ MastodonͰ༻͞Ε͍ͯΔPostgreSQLͷαϙʔτظݶ 2021·Ͱ͍ͬͯ·͕͢ɺݹ͍σʔλϕʔεΛ͍ଓ͚Δ ͷϦεΫͰ͔͋͠Γ·ͤΜɻ ৽͍͠όʔδϣϯηΩϡϦςΟͷվળύϑΥʔϚϯεͷ վળΛߦͳ͍ͬͯͨΓ͍ͯ͠·͢ɻ όοΫΞοϓΛऔ͔ͬͯΒͥͻɺ օ͞ΜΞοϓάϨʔυΛࢼ͍ͯͩ͘͠͞ʂ
ྑ͍PostgreSQL MastodonϥΠΫΛʂ ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ