coderdojo-japan / coderdojo.jp

☯️ CoderDojo Japan (@coderdojo-japan) official website developed by Ruby on Rails with @YassLab team. 💎
https://coderdojo.jp
Other
61 stars 101 forks source link

データベース容量制限を回避するために、大きい容量が使えるプランに変更したい #1606

Closed nanophate closed 3 months ago

nanophate commented 3 months ago

問題の概要

CoderDojo Japan の Heroku Postgres データベースが Mini プランの制限(10,000行)を超えたと言うメールが届きました。今後もデータが増える可能性が大きので、制限を受けない適切なプランに変更したいと考えています。

データベースのプランを Mini ($5) から Basic ($9) にアップグレードすることで問題を回避できると思われましたが、Basic プランが 2024年5月29日で EOL になっているため、Essential-0 ($5) プランに変更することを検討しています。プラン変更をすることで、容量制限を回避でき、容量が増え料金も変わらず使えるのでとても効果的な対応だと考えています。

やること

Heroku の発表についての情報

▸ Heroku Postgres Mini and Basic plans will reach end-of-life (EOL) on May 29, 2024. ▸ Starting on this date, you can no longer provision Mini and Basic plans. ▸ We'll also begin migrating the Service to the new Essential-tier plans. ▸ See https://devcenter.heroku.com/changelog-items/2862 for more information. screenshot_2024-06-10_at_11 57 28

nanophate commented 3 months ago

Staging 環境で念の為に手順の確認などを行いました。実際に下記の手順で進めることで、プランへの変更ができそうです。

アップグレード手順

手順

  1. データベース名を確認するために以下のコマンドを実行します。

    heroku pg:info -a <アプリ名>
  2. 確認したデータベース名を使用して、以下のコマンドを実行し、プランを Essential-0 や Essential-1 にアップグレードします。

    heroku addons:upgrade <データベース名> heroku-postgresql:essential-0 -a <アプリ名>

https://blog.heroku.com/heroku-postgres-essential-launch#migrating-mini-and-basic-postgres-plans

実行例

  1. データベース名の確認:

    ❯ heroku pg:info -a example-app
    === DATABASE_URL
    Plan: Mini
    Status: Available
    Connections: 0/20
    PG Version: 15.7
    Created: 2023-07-25 06:14 UTC
    Data Size: 8.6 MB/1.00 GB (In compliance)
    Tables: 14
    Rows: 21/10000 (In compliance)
    Add-on: postgresql-example-123456
  2. プランのアップグレード:

    ❯ heroku addons:upgrade postgresql-example-123456 heroku-postgresql:essential-0 -a example-app
    Changing postgresql-example-123456 on example-app from heroku-postgresql:mini to heroku-postgresql:essential-0... done, ~$0.007/hour (max $5/month)
    Your database's plan is being changed from mini to essential-0.

注意点

問題解決のための発見事項

https://help.heroku.com/6TMK6W1A/why-are-heroku-pg-commands-failing-with-couldn-t-find-that-add-on

yasulab commented 3 months ago

@nanophate 対応ありがとうございます!!ちょっと今はガッツリとレビューできる状態ではないですが一旦この方向で進めましょう!!(>人< )✨

nanophate commented 3 months ago

下記の手順でプラン変更を行いました。

Herokuデータベースプラン変更手順

1. 現在のデータベース情報を確認

まず、現在のデータベース情報を確認します。

❯ heroku pg:info -a example-app

出力例:

 ▸ Heroku Postgres Mini and Basic plans will reach end-of-life (EOL) on May 29, 2024.
 ▸ Starting on this date, you can no longer provision Mini and Basic plans.
 ▸ We'll also begin migrating the Service to the new Essential-tier plans.
 ▸ See https://devcenter.heroku.com/changelog-items/2862 for more information.
=== DATABASE_URL
Plan: Mini
Status: Available
Connections: 2/20
PG Version: 14.12
Created: 2022-12-03 01:01 UTC
Data Size: 14.6 MB/1.00 GB (In compliance)
Tables: 9
Rows: 9952/10000 (In compliance, close to row limit)
Fork/Follow: Unsupported
Rollback: Unsupported
Continuous Protection: Off
Add-on: postgresql-redacted-number

2. データベースのバックアップを作成

次に、データベースのバックアップを作成します。

❯ heroku pg:backups:capture -a example-app

出力例:

Starting backup of postgresql-redacted-number... done
Use Ctrl-C at any time to stop monitoring progress; the backup will continue running.
Use heroku pg:backups:info to check progress.
Stop a running backup with heroku pg:backups:cancel.
Backing up DATABASE to b007... done

3. バックアップの確認

バックアップが正常に作成されたか確認します。

❯ heroku pg:backups -a example-app

出力例:

=== Backups
ID Created at Status Size Database
──── ───────────────────────── ─────────────────────────────────── ──────── ────────
b007 2024-06-15 19:48:31 +0000 Completed 2024-06-15 19:48:34 +0000 422.91KB DATABASE
b006 2024-06-15 19:38:51 +0000 Completed 2024-06-15 19:38:52 +0000 422.91KB DATABASE
=== Restores
ID Started at Status Size Database
──── ───────────────────────── ──────────────────────── ──────── ────────
r004 2022-12-03 02:55:34 +0000 Finished with 1 warnings 348.16KB DATABASE
=== Copies
ID Started at Status Size From To
──── ───────────────────────── ─────────────────────────────────── ──────── ───────── ───────────
c005 2023-03-01 21:39:34 +0000 Completed 2023-03-01 21:39:55 +0000 360.46KB From Name Target Name
c003 2022-06-11 14:24:11 +0000 Completed 2022-06-11 14:24:26 +0000 325.51KB From Name Target Name
c002 2019-10-04 08:58:14 +0000 Completed 2019-10-04 08:58:26 +0000 165.16KB From Name Target Name

4. データベースプランの変更

データベースプランをMiniからEssential-0に変更します。

❯ heroku addons:upgrade postgresql-redacted-number heroku-postgresql:essential-0 -a example-app

出力例:

Changing postgresql-redacted-number on example-app from heroku-postgresql:mini to heroku-postgresql:essential-0... done, ~$0.007/hour (max $5/month)
Your database's plan is being changed from mini to essential-0.

5. 変更後のデータベース情報を確認

プラン変更後のデータベース情報を確認します。

❯ heroku pg:info -a example-app

出力例:

=== DATABASE_URL
Plan: essential-0
Status: Available
Connections: 2/20
PG Version: 14.11
Created: 2024-06-15 19:52
Data Size: 12.5 MB / 1 GB (1.22%) (In compliance)
Tables: 9/4000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported
Continuous Protection: Off
Add-on: postgresql-redacted-number

6. 自動バックアップのスケジュール設定

最後に、自動バックアップをスケジュール設定します。

❯ heroku pg:backups:schedule DATABASE_URL --at '08:00 Asia/Tokyo' --app example-app

出力例:

Scheduling automatic daily backups of postgresql-redacted-number at 08:00 Asia/Tokyo... done
nanophate commented 3 months ago

気になる点

pg:info の結果で、Data Size の違いがありましたが、変更前の各テーブルの Row カウントが変わっていない事と、最後に追加された、情報も全て同一だったので、データの欠損がない事を確認しました。 Heroku の Plan 変更で同様の問題が上がっていましたが、データ欠損はない為、Known Issue の可能性が高そうです。

- Data Size: 14.6 MB/1.00 GB (In compliance)
+ Data Size: 12.5 MB / 1 GB (1.22%) (In compliance)
nanophate commented 3 months ago

統計スクリプトが正常に完了したいることを確認できたので、こちらの Issue はクローズします。

Screenshot 2024-06-17 at 11 19 01

yasulab commented 3 months ago

対応ありがとうございました!!!!😻🆒✨