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
940
はじめての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
30 Presentation Tips
portentint
PRO
1
430
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
460
The agentic SEO stack - context over prompts
schlessera
0
970
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
Making Projects Easy
brettharned
120
6.8k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
320
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
470
New Earth Scene 8
popppiees
4
2.7k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
530
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ϥΠΫΛʂ ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ