Issue deploying to gigalixir - (RuntimeError) connect raised KeyError exception: key :database not found

I am having an issue deploying my phoenix app to gigalixir.

2019-09-24T01:05:40.350124+00:00 stipe[stipe-767f97457f-657ng]: web.1  | ** (RuntimeError) connect raised KeyError exception: key :database not found. The exception details are hidden, as they may contain sensitive data such as database credentials. You may set :show_sensitive_data_on_connection_error to true when starting your connection if you wish to see all of the details
2019-09-24T01:05:40.350152+00:00 stipe[stipe-767f97457f-657ng]: web.1  |     (elixir) lib/keyword.ex:393: Keyword.fetch!/2
2019-09-24T01:05:40.350182+00:00 stipe[stipe-767f97457f-657ng]: web.1  |     (postgrex) lib/postgrex/protocol.ex:92: Postgrex.Protocol.connect/1
2019-09-24T01:05:40.350260+00:00 stipe[stipe-767f97457f-657ng]: web.1  |     (db_connection) lib/db_connection/connection.ex:69: DBConnection.Connection.connect/2
2019-09-24T01:05:40.350286+00:00 stipe[stipe-767f97457f-657ng]: web.1  |     (connection) lib/connection.ex:622: Connection.enter_connect/5
2019-09-24T01:05:40.350315+00:00 stipe[stipe-767f97457f-657ng]: web.1  |     (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
2019-09-24T01:05:40.350334+00:00 stipe[stipe-767f97457f-657ng]: web.1  | Last message: nil
2019-09-24T01:05:40.350452+00:00 stipe[stipe-767f97457f-657ng]: web.1  | 01:05:40.270 [error] GenServer #PID<0.1683.0> terminating
2019-09-24T01:05:40.350459+00:00 stipe[stipe-767f97457f-657ng]: web.1  | ** (RuntimeError) connect raised KeyError exception: key :database not found. The exception details are hidden, as they may contain sensitive data such as database credentials. You may set :show_sensitive_data_on_connection_error to true when starting your connection if you wish to see all of the details
2019-09-24T01:05:40.350460+00:00 stipe[stipe-767f97457f-657ng]: web.1  |     (elixir) lib/keyword.ex:393: Keyword.fetch!/2
2019-09-24T01:05:40.350463+00:00 stipe[stipe-767f97457f-657ng]: web.1  |     (postgrex) lib/postgrex/protocol.ex:92: Postgrex.Protocol.connect/1
2019-09-24T01:05:40.350504+00:00 stipe[stipe-767f97457f-657ng]: web.1  |     (db_connection) lib/db_connection/connection.ex:69: DBConnection.Connection.connect/2
2019-09-24T01:05:40.350585+00:00 stipe[stipe-767f97457f-657ng]: web.1  |     (connection) lib/connection.ex:622: Connection.enter_connect/5
2019-09-24T01:05:40.350620+00:00 stipe[stipe-767f97457f-657ng]: web.1  |     (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
2019-09-24T01:05:40.350645+00:00 stipe[stipe-767f97457f-657ng]: web.1  | Last message: nil
2019-09-24T01:05:40.350692+00:00 stipe[stipe-767f97457f-657ng]: web.1  | 01:05:40.271 [info] Application stipe exited: shutdown
2019-09-24T01:05:40+00:00 stipe[gigalixir]: Readiness probe failed: dial tcp 10.56.12.134:4000: connect: connection refused
2019-09-24T01:05:41.359831+00:00 stipe[stipe-5c6c65949d-84thz]: web.1  | {"Kernel pid terminated",application_controller,"{application_terminated,stipe,shutdown}"}
2019-09-24T01:05:41.359881+00:00 stipe[stipe-5c6c65949d-84thz]: web.1  | Kernel pid terminated (application_controller) ({application_terminated,stipe,shutdown})
2019-09-24T01:05:41.362196+00:00 stipe[stipe-5c6c65949d-84thz]: web.1  | 
2019-09-24T01:05:41.782657+00:00 stipe[stipe-767f97457f-657ng]: web.1  | {"Kernel pid terminated",application_controller,"{application_terminated,stipe,shutdown}"}
2019-09-24T01:05:41.782745+00:00 stipe[stipe-767f97457f-657ng]: web.1  | Kernel pid terminated (application_controller) ({application_terminated,stipe,shutdown})
2019-09-24T01:05:41.786425+00:00 stipe[stipe-767f97457f-657ng]: web.1  | 
2019-09-24T01:05:43+00:00 stipe[gigalixir]: Readiness probe failed: dial tcp 10.56.12.134:4000: connect: connection refused

And this is my prod.exs file

config :stipe, StipeWeb.Endpoint,
  load_from_system_env: true,
  # Needed for Phoenix 1.2 and 1.4. Doesn't hurt for 1.3.
  http: [port: {:system, "PORT"}],
  # Without this line, your app will not start the web server!
  server: true,
  secret_key_base: "${SECRET_KEY_BASE}",
  url: [host: "${APP_NAME}.gigalixirapp.com", port: 443],
  cache_static_manifest: "priv/static/cache_manifest.json"

config :stipe, StipeWeb.Repo,
  adapter: Ecto.Adapters.Postgres,
  url: "${DATABASE_URL}",
  database: "",
  ssl: true,
  show_sensitive_data_on_connection_error: true,
  # Free tier db only allows 4 connections. Rolling deploys need pool_size*(n+1) connections where n is the number of app replicas.
  pool_size: 2

I wonder why it cant connect to db as mentioned in the logs. And even with the show_sensitive_data_on_connection_error: true, enabled I still see the enable it to show sensitive info message in the log

Also I am using distillery.

1 Like

Just a guess, but try replacing StipeWeb.Repo with Stipe.Repo

4 Likes

this is so embarassing. I didnt even see it was namespaced under StipeWeb. I wish the error was more verbose and told me that there is no repo inside StipeWeb.

No worries! It’s actually a very common error. I see it almost everyday.

4 Likes