3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rails 8 デプロイでハマった「cable database is not configured」エラーと対処法

Posted at

はじめに

Rails 8 を使ったアプリを Heroku にデプロイしたら、こんなエラーで落ちました。

at=error code=H10 desc="App crashed" method=GET path="/" ....

ログをよく見ると、こんなメッセージが。

cable database is not configured for the production environment.

つまり「production 環境で cable 用の DB 接続が設定されてないよ」ということらしい。
Rails 8 からの仕様変更に引っかかったっぽいです。

Solid Trifectaってなんやねん?????

Rails 8 では Solid Trifecta という思想が導入されたそうです。

従来は 1 つの DB で全部まとめて処理していたものが、Rails 8 からは用途ごとに接続先を分けるようになっていそう。

  • primary : アプリの通常データ
  • cache : キャッシュ用
  • queue : ジョブ用
  • cable : Action Cable(WebSocket の状態管理用)

これで、用途に応じて最適化できるし、障害が起きても他の機能に影響を及ぼしにくい、スケールもしやすい。大規模サービスには良さそう、依存が少なくなったり...

小規模アプリではどうなる?

Heroku の無料枠や hobby プランで使うときみたいに、Postgres が 1 つしかないケースでは、これがめちゃくちゃ困る...(←今回の記事の本題)
だって cache / queue / cable 用に別 DB を用意できないというか、お財布にダメージが...

僕のケースも WebSocket を使わないので cable は不要、でもエラーは出る...。

応急処置

なので応急処置としては「全部 primary にまとめる」しかないよね..(多分)。

production:
  primary: &primary_production
    <<: *default
    url: <%= ENV["DATABASE_URL"] %>

  cache:
    <<: *primary_production

  queue:
    <<: *primary_production

  cable:
    <<: *primary_production

こうしておけば、Heroku 上の単一 DB でもエラーが消えて動きます。

まとめ

  • Rails 8 では Solid Trifecta により DB 接続が 4 つに分割された

  • 大規模アプリにはメリット大(安定性・最適化・スケーラビリティ)

  • 小規模・単一 DB の環境では「全部 primary に寄せる」設定でとりあえず動く

知らないエラーでめっちゃ時間かかったぜ..🙃
でも思想としてはすごく良さそうなので、規模とお財布に合わせて取り入れるのが良さそうです。

3
0
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
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?