Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
こわくない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
950
はじめてのPostgreSQLモニタリング入門 / PostgreSQL 11 Monitoring
ester41
17
3.9k
PostgreSQL11 設定パラメーター解体新書 / PostgreSQL 11 parameter
ester41
2
4.3k
PostgreSQLデプロイの基礎
ester41
1
1.4k
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1033
470k
Being A Developer After 40
akosma
PRO
92
590k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
440
Building AI with AI
inesmontani
PRO
1
1.4k
Embracing the Ebb and Flow
colly
88
5.2k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
3.7k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
500
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
23k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
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ϥΠΫΛʂ ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ