Phoenix app launches fine in dev but fails in prod

I started working on a Phoenix application using SQLite (it was only me using it) but then decided to move to postgres. I didn’t migrate, just started over with a clean DB.

The application runs fine with mix phx.server but once I run it in prod mode, it fails to start since I started using postgres.

The dev config is

config :work_tracker, WorkTracker.Repo,
  username: "tracker",
  password: "*********",
  hostname: "localhost",
  database: "tracker_dev",
  stacktrace: true,
  show_sensitive_data_on_connection_error: true,
  pool_size: 10

The command to run prod is

PHX_HOST=localhost MIX_ENV=prod DATABASE_URL="ecto://tracker:******@localhost/tracker_dev" SECRET_KEY_BASE=<loongsecret> mix phx.server

The application exits with

warning: variable "opts" is unused (if the variable is not meant to be used, prefix it with an underscore)

warning: unused alias Accounts

warning: variable "maybe_ipv6" is unused (if the variable is not meant to be used, prefix it with an underscore)

09:58:26.113 [info] Running WorkTrackerWeb.Endpoint with cowboy 2.10.0 at :::4000 (http)
09:58:26.132 [info] Access WorkTrackerWeb.Endpoint at https://localhost
09:58:26.225 [notice] Application work_tracker exited: shutdown
Kernel pid terminated (application_controller) ({application_terminated,work_tracker,shutdown})

Crash dump is being written to: erl_crash.dump...done

I can’t make much sense of the crash dump I’m afraid.

  • Erlang/OTP 26
  • Interactive Elixir (1.15.7)
  • Phoenix installer v1.7.9

the error message is not very helpful, and it basically says that Erlang crashed.

Are you running this on Windows maybe?

Running it on WSL as well as a plain ubuntu server

I know the message isn’t helpful, but that’s all I get.

1 Like

I am uncertain if it’s safe to share these publictly. The file above may contain credentials and such.

I couldn’t see anything in there myself, but have removed it just in case. Thanks for the headsup

yeah… I am not an expert on analysing these dump files and my contribution here probably ends now as I don’t know how to help you but maybe other members saw similar problems and will help. It’s good you have the dump file it may come in handy.

1 Like

Seems like it might be related to the ecto URL. When I use that in the dev settings I get the same behaviour.
I replaced the database settings in prod with

    username: System.get_env("DB_USER"),
    password: System.get_env("DB_PASS"),
    hostname: System.get_env("DB_HOST"),
    database: System.get_env("DB_NAME"),

and that is working fine.

1 Like

huh, glad you sorted it out

1 Like

As a nitpick, did you try surrounding the DATABASE_URL value with single quotes? It’s possible that a character in the password was not passed correctly to the app due to the character escaping quirks of the shell.

Thanks for suggestion, but alas that also didn’t work.

It fails when I set the URL in dev settings as well, so no shell invovled

 database: 'ecto://tracker:*****@localhost/tracker_dev',
  stacktrace: true,
  show_sensitive_data_on_connection_error: true,
  pool_size: 10

If you use a url the key should be url: , not datebase:


I meant the shell command line explicitly by the way.

Doh! I guess I edited the runtime from when I used sqlite and forgot I did that. Thanks, that is indeed the problem, and clearly a very obvious one (once you know)