Rename Postgres database after importing from Heroku

I used the fly postgres import command to import my database from Heroku.
The resulting database has some name that is autogenerated by heroku. This doesn’t work with my attached fly app as it expects the database to be named like the app.

To rename the imported database I need first to drop (or rename) the existing app-database. This always fails with an error “There is 1 other session using the database.”.

My app is suspended at this time.

What can I do, to rename the database or otherwise get a database with the “right” name after importing from heroku?

From General to Questions / Help

Added postgres

Hi… This may be postgres_exporter, the metrics subprocess:

$ fly pg connect -a db-app-name
> select usename, query from pg_stat_activity where datname = '<database-name>';
usename     query
----------  -----------------
flypgadmin  SELECT version();

It auto-attaches to all databases—if I understand correctly.

The easiest is to change the DATABASE_URL to match the Heroku-based name, I think.

(In other words, you redefine the “right name” altogether.)

What have you done already in the way of fly pg attach, etc.?

Thanks for the hint. It’s just a bit ugly to keep the auto-generated names from heroku, like the fly naming convention better.

I have done nothing specific with attach etc. Just launched and deployed my existing django app with an autogenerated Fly Postgres app.
Then followed the tutorial to import the database from heroku.

If someone from fly.io is reading: perhaps the import from heroku tutorial should mention this problem. I lost some time because my app database was empty after importing, until I found out there is anoter database with the name from heroku.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.