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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
920
はじめてのPostgreSQLモニタリング入門 / PostgreSQL 11 Monitoring
ester41
17
3.8k
PostgreSQL11 設定パラメーター解体新書 / PostgreSQL 11 parameter
ester41
2
4.3k
PostgreSQLデプロイの基礎
ester41
1
1.4k
Featured
See All Featured
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
390
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
350
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
230
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
470
How STYLIGHT went responsive
nonsquared
100
6.2k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
RailsConf 2023
tenderlove
30
1.5k
The Curse of the Amulet
leimatthew05
2
13k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
280
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ϥΠΫΛʂ ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ