0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Herokuのpostgresql をHobby-devkからhobby-basic にアップグレードする

Posted at

Herokuのpostgresql は無料のHobby-devプランだと10,000件以上レコードが作れない制約がある。
https://elements.heroku.com/addons/heroku-postgresql

非常に困るので、とりあえずhobby-basicにアップグレードして10,000,000件までデータが作れるようにしてみた。

現在の状況を確認

$ heroku pg:info -a #{app_name}

=== DATABASE_URL
Plan:                  Hobby-dev
Status:                Available
Connections:           2/20
PG Version:            12.3
Created:               2020-07-07 15:55 UTC
Data Size:             12.5 MB
Tables:                6
Rows:                  3810/10000 (In compliance)
Fork/Follow:           Unsupported
Rollback:              Unsupported
Continuous Protection: Off
Add-on:                postgresql-lively-57044

Rows: 3810/10000 (In compliance)

ちなみに10000件超えるとここが

Rows: 16132/10000 (Write access revoked)

こんな感じになり、ます。databaseへのWrite access件がなくなり、データcreateが毎回失敗するようになります。

pgのhobby-basicを追加

$ heroku addons:create heroku-postgresql:hobby-basic -a #{app_name}

Creating heroku-postgresql:hobby-basic on ⬢ #{app_name}... $9/month
Database has been created and is available
 ! This database is empty. If upgrading, you can transfer
 ! data from another database with pg:copy
Created postgresql-round-77939 as HEROKU_POSTGRESQL_PINK_URL
Use heroku addons:docs heroku-postgresql to view documentation

$9/month Database has been created and is available

ここでも請求情報を教えてくれますね。

pgをwaitする

$ heroku pg:wait -a #{app_name}

メンテナンスモードにする

$ heroku maintenance:on -a #{app_name}

データをコピーする

$ heroku pg:copy DATABASE_URL HEROKU_POSTGRESQL_PINK_URL -a #{app_name}

こんな感じで変更に同意しろって出たので、#{app_name}を打てば良さそう。

 ▸    WARNING: Destructive action
 ▸    This command will remove all data from PINK
 ▸    Data from DATABASE will then be transferred to PINK
 ▸    To proceed, type #{app_name} or re-run this command with --confirm #{app_name}

または --confirm #{app_name} をつけて再度実行

$ heroku pg:copy DATABASE_URL postgresql-round-77939 -a #{app_name} --confirm #{app_name}

Starting copy of DATABASE to PINK... done
Copying... done

コピー完了🎉

dbの参照先を変更する

$ heroku pg:promote HEROKU_POSTGRESQL_PINK_URL -a #{app_name}

Ensuring an alternate alias for existing DATABASE_URL... HEROKU_POSTGRESQL_MAROON_URL
Promoting postgresql-round-77939 to DATABASE_URL on ⬢ agile-peak-55895... done

変更されたか確認

DATABASE_URLがちゃんとHobby-basicになっているか確認

$ heroku pg:info -a #{app_name}

=== HEROKU_POSTGRESQL_PINK_URL, DATABASE_URL
Plan:                  Hobby-basic
Status:                Available
Connections:           0/20
PG Version:            12.3
Created:               2020-07-29 08:47 UTC
Data Size:             9.1 MB
Tables:                0
Rows:                  0/10000000 (In compliance) - refreshing
Fork/Follow:           Unsupported
Rollback:              Unsupported
Continuous Protection: Off
Add-on:                postgresql-round-77939

=== HEROKU_POSTGRESQL_MAROON_URL
Plan:                  Hobby-dev
Status:                Available
Connections:           0/20
PG Version:            12.3
Created:               2020-07-07 15:55 UTC
Data Size:             12.5 MB
Tables:                6
Rows:                  3810/10000 (In compliance)
Fork/Follow:           Unsupported
Rollback:              Unsupported
Continuous Protection: Off
Add-on:                postgresql-lively-57044


DATABASE_URL がついている方が Plan: Hobby-basic になってるのでOK

=== HEROKU_POSTGRESQL_PINK_URL, DATABASE_URL
Plan:                  Hobby-basic

ちなみに操作前は

=== DATABASE_URL
Plan:                  Hobby-dev

なってなたはず。

メンテナンスモード解除

$ heroku maintenance:off -a #{app_name}

Disabling maintenance mode for ⬢ #{app_name}... done
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?