Closed nanophate closed 3 months ago
Staging 環境で念の為に手順の確認などを行いました。実際に下記の手順で進めることで、プランへの変更ができそうです。
データベース名を確認するために以下のコマンドを実行します。
heroku pg:info -a <アプリ名>
確認したデータベース名を使用して、以下のコマンドを実行し、プランを 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
データベース名の確認:
❯ 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
プランのアップグレード:
❯ 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.
Running addons:upgrade to upgrade to an essential-* plan puts the database in read-only mode, so no writes happen during the upgrade. https://devcenter.heroku.com/articles/updating-heroku-postgres-databases#updating-with-addons-upgrade
❯ heroku pg:info -a example-app
=== DATABASE_URL
Plan: essential-0
Status: unknown
Connections: 0/20
PG Version: 15.6
Created: 2024-06-14 21:12
Data Size: 8.69 MB / 1 GB (0.85%) (In compliance)
Tables: 14/4000 (In compliance)
Add-on: postgresql-example-123456
記事にある heroku addons:upgrade DATABASE heroku-postgresql:essential-0 -a example-app
コマンドを実行するとエラーが発生する場合があります。
❯ heroku addons:upgrade HEROKU_POSTGRESQL_CRIMSON_URL heroku-postgresql:essential-0 -a example-app
▸ Couldn't find that add on.
このエラーは、CLI がデータベースを正確に識別できない場合に発生します。heroku pg:info -a <アプリ名>
コマンドでデータベース名を確認し、正確な名前を使用することで解決できます。
https://help.heroku.com/6TMK6W1A/why-are-heroku-pg-commands-failing-with-couldn-t-find-that-add-on
@nanophate 対応ありがとうございます!!ちょっと今はガッツリとレビューできる状態ではないですが一旦この方向で進めましょう!!(>人< )✨
下記の手順でプラン変更を行いました。
まず、現在のデータベース情報を確認します。
❯ 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
次に、データベースのバックアップを作成します。
❯ 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
バックアップが正常に作成されたか確認します。
❯ 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
データベースプランを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.
プラン変更後のデータベース情報を確認します。
❯ 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
最後に、自動バックアップをスケジュール設定します。
❯ 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
気になる点
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)
統計スクリプトが正常に完了したいることを確認できたので、こちらの Issue はクローズします。
対応ありがとうございました!!!!😻🆒✨
問題の概要
CoderDojo Japan の Heroku Postgres データベースが Mini プランの制限(10,000行)を超えたと言うメールが届きました。今後もデータが増える可能性が大きので、制限を受けない適切なプランに変更したいと考えています。
データベースのプランを Mini (
$5
) から Basic ($9
) にアップグレードすることで問題を回避できると思われましたが、Basic プランが 2024年5月29日で EOL になっているため、Essential-0 ($5
) プランに変更することを検討しています。プラン変更をすることで、容量制限を回避でき、容量が増え料金も変わらず使えるのでとても効果的な対応だと考えています。やること
Heroku の発表についての情報