Error when upgrading database on Heroku

I’m getting close to reaching the 10K limit on my Heroku Hobby Dev Postgres database. I’m attempting to upgrade to Hobby Basic which has a 10M row limit.

I followed the instructions for upgrading with pg:copy from Heroku.

I created the new database and copied the data over without errors. I put my app in maintenance mode. However, when I tried to use pg:promote, I got the following error:

00:32:45.216 [error] GenServer #PID<0.273.0> terminating
** (KeyError) key :database not found in: [hostname: "localhost", types: Ecto.Adapters.Postgres.TypeModule, port: 5432, name: Ex338.Repo.Pool, otp_app: :ex338, repo: Ex338.Repo, timeout: 15000, pool_timeout: 5000, adapter: Ecto.Adapters.Postgres, ssl: true, pool_size: 1, pool: DBConnection.Poolboy]
    (elixir) lib/keyword.ex:386: Keyword.fetch!/2
    (postgrex) lib/postgrex/protocol.ex:76: Postgrex.Protocol.connect/1
    (db_connection) lib/db_connection/connection.ex:134: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: nil

Any idea what the problem is?

Have you checked heroku config to make sure DATABASE_URL is pointing in the right place now?

Also check your config/prod.exs uses it/hasn’t been changed accidentally.

I didn’t change anything in my config files.

The DATABASE_URL in Heroku is pointed to the new database, but the connections are still to the old database. I tried to to redeploy to see if it would pull in the new DATABASE_URL Config Var, but the release failed with this error:

02:14:51.509 [error] GenServer #PID<0.271.0> terminating
** (ArgumentError) argument error
    :erlang.element(1, :error)
    (postgrex) lib/postgrex/utils.ex:67: anonymous fn/1 in Postgrex.Utils.parse_version/1
    (elixir) lib/enum.ex:1314: Enum."-map/2-lists^map/1-0-"/2
    (elixir) lib/enum.ex:1314: Enum."-map/2-lists^map/1-0-"/2
    (postgrex) lib/postgrex/utils.ex:67: Postgrex.Utils.parse_version/1
    (postgrex) lib/postgrex/protocol.ex:641: Postgrex.Protocol.bootstrap_send/6
    (postgrex) lib/postgrex/protocol.ex:475: Postgrex.Protocol.handshake/2
    (db_connection) lib/db_connection/connection.ex:134: DBConnection.Connection.connect/2
Last message: nil
** (exit) exited in: :gen_server.call(#PID<0.271.0>, {:checkout, #Reference<0.3235637939.1198260227.206973>, true, :infinity}, 5000)
    ** (EXIT) an exception was raised:
        ** (ArgumentError) argument error
            :erlang.element(1, :error)
            (postgrex) lib/postgrex/utils.ex:67: anonymous fn/1 in Postgrex.Utils.parse_version/1
            (elixir) lib/enum.ex:1314: Enum."-map/2-lists^map/1-0-"/2
            (elixir) lib/enum.ex:1314: Enum."-map/2-lists^map/1-0-"/2
            (postgrex) lib/postgrex/utils.ex:67: Postgrex.Utils.parse_version/1
            (postgrex) lib/postgrex/protocol.ex:641: Postgrex.Protocol.bootstrap_send/6
            (postgrex) lib/postgrex/protocol.ex:475: Postgrex.Protocol.handshake/2
            (db_connection) lib/db_connection/connection.ex:134: DBConnection.Connection.connect/2
    (db_connection) lib/db_connection/poolboy.ex:112: DBConnection.Poolboy.checkout/3
    (db_connection) lib/db_connection.ex:920: DBConnection.checkout/2
    (db_connection) lib/db_connection.ex:742: DBConnection.run/3
    (db_connection) lib/db_connection.ex:1133: DBConnection.run_meter/3
    (db_connection) lib/db_connection.ex:584: DBConnection.prepare_execute/4
    (ecto) lib/ecto/adapters/postgres/connection.ex:86: Ecto.Adapters.Postgres.Connection.execute/4
    (ecto) lib/ecto/adapters/sql.ex:256: Ecto.Adapters.SQL.sql_call/6
    (ecto) lib/ecto/adapters/sql.ex:198: Ecto.Adapters.SQL.query!/5

In your root folder type

mix deps.update postgrex

Commit your updated mix.lock file and push to heroku again. That should fix it.

2 Likes

I too converted to a paid database. As part of this process Heroku gives you a config variable for the new paid database.

Free vs Paid Config variable
In my app I had referenced “DATABASE_URL”, so I had to go through my app and change all references from “DATABASE_URL” to “HEROKU_POSTGRESQL_GREEN_URL” which is the new config variable for the paid database.

Locating config var names
Select your app then select “settings” and it’s in a section called “config vars”

The files I needed to modify in my phoenix application to were config/prod.exs and lib/yourappname/repo.ex.

The feedback in this forum is correct just leaving more details for any newbies to Heroku deployment.

1 Like