2
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 1 year has passed since last update.

herokuからMaintenance is required for your databaseというメールが来てアプリを確認したらデータベース接続ができなくなってた話

Last updated at Posted at 2021-12-20

何があったのか

タイトルの通りです。

herokuからデータベースメンテナンスのメールが来ていて、Webアプリの動作を確認したらデータベースへの接続に失敗していました。

その時の状況と復旧方法を残しておきます。

2023/01/20追記
DATABASE_URLを使ってデータベースの接続先を設定すればメンテナンス後に自動で情報が書き換わることに気が付きました。
対処方法を変更しておきます。

状況

bot@notifications.heroku.comからMaintenance is required for your databaseというメールが2021/12/20 6:03に来ていたことに起きてすぐ気が付きました。

Your database DATABASE_URL on latest-anime requires maintenance. During this period, your database will become read-only. Once maintenance has completed, your database credentials and hostname will have changed, but we will update your app's config variables accordingly to reflect the new database connection string.
This automated maintenance is a necessary part of our Hobby tier plans, Dev and Basic. Should you need more control over maintenance windows, a production database (Standard tier or higher) offers more control over database maintenance, as we are able to schedule them in advance and provide better tools for self-served maintenance.
We expect maintenance to last just a few moments depending on the size of your database. We will notify you when maintenance begins, and again once it's complete.

2021/12/20 6:23にメンテナンスの開始メールが、2021/12/20 6:26にメンテナンス完了メールも届いています。

2018年からherokuを利用していて初めてのメールだったので、「こんなこともあるんだなー。一応動作確認しておくか。」くらいな軽い気持ちでWebアプリを確認したところなんとデータの取得ができていなさそうです。

「heroku logs -t」コマンドでログを確認するとやはりデータベースに接続できていない様子。

herokuの管理画面でデータベースの情報と「heroku config」で表示した環境変数の情報を見比べるとデータベース情報が違いました。

メールには以下のように書いてありました。

your database credentials and hostname will have changed, but we will update your app's config variables accordingly to reflect the new database connection string.

Google日本語訳

データベースのクレデンシャルとホスト名は変更されますが、それに応じてアプリの構成変数が更新され、新しいデータベース接続文字列が反映されます。

嘘つき!!!!!!!!!!

自動で更新されてないじゃないか。

と2021年の私は思っていましたが、DATABASE_URLの値は自動で変更されているようでした。

復旧方法(暫定対応)

自動で更新されるのはDATABASE_URLだけです、それ以外の値を参照している場合は、手動で更新するしかありません。

herokuの管理画面と環境変数に差があった下記4つの値を手動で更新。

heroku config:set DB_DATABASE=***
heroku config:set DB_HOST=ec2-**.compute-1.amazonaws.com
heroku config:set DB_USERNAME=**
heroku config:set DB_PASSWORD=**

復旧方法(恒久対応)

環境変数のDATABASE_URLを参照してデータベース接続を行うように対応します。

古いLaravelを脈々とバージョンアップさせている場合は、config/database.phpの設定の中にDATABASE_URLを参照する設定がなかったりします。追加してみましょう。

        'pgsql' => [
            'driver' => 'pgsql',
            'url' => env('DATABASE_URL'),//追加

DATABASE_URLを利用するようになると今まで使っていた環境変数は不要になるものがあります。残っていても悪さをすることはないと思いますが、気になるようなら削除しましょう。

heroku config:unset DB_DATABASE
heroku config:unset DB_HOST
heroku config:unset DB_PASSWORD
heroku config:unset DB_USERNAME
heroku config:unset DB_PORT

開発しているWebサービス(LAR)について

LARは放送時期(クール)ごとにアニメを一覧で見ることができるサービスです。
ログイン不要で自由にアニメの一覧が作成できる「おすすめアニメメーカー」などの機能があります。
ログインすると自分専用のアニメ番組表が作れるMY番組表も使えます。

LARは、もともとスマホアプリが先にリリースされているため編集機能はスマホアプリで行うことができます。
(今後利用者が増えればWEB版にも編集機能を追加します)

是非ご利用ください。

2
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
2
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?