Django app stopped working due to the postgres cluster got suspended

Hell Guys.

I have faced a strange issue. After my app successfully ran for 5 month and I gathered some data already it stopped to work! Just like this… it work till it doesn’t

When the website opens I see the login page and it works well which makes me suspect that it is not Django’s side. As soon as I try to enter the website and of course touch the DB I receive an 500 Internal server error. I tried to restore the image and create a new PG app but no luck in connecting it to my website!

At the end of my long struggle I launched a new app and connected it to an image of the old DB cluster. Unfortunately I see no data… my new PG volume has the same size as it used to have so it is a good indicator that the data is still there.

Please let me know what additional information can I provide to support my question.

Hi… By default, your new app would have gotten a DATABASE_URL ending with /new_app, whereas getting to your actual data would instead require /old_app in that position.

Try fly pg connect -a new-db-app-name and then \l (followed by the Enter/Return key) at the prompt. This will show you what’s really available in there…

$ fly pg connect -a new-db-app-name
postgres=# \l
Name      | Owner
----------+---------
postgres  | postgres
repmgr    | repmgr
template0 | postgres
template1 | postgres
new_app   | postgres
old_app   | postgres
postgres=# \c old_app
old_app=# \dt
...should see list of old tables...
old_app=# \q

(Many columns elided from the \l example.)

If your old Django app still exists, you can probably just copy its DATABASE_URL (via fly secrets set).

$ fly m start -a old-app  # ensure at least one running.
$ fly ssh console -C 'printenv DATABASE_URL' -a old-app
$ fly secrets set "DATABASE_URL=<string-from-above>" -a new-app

(Assumes bash syntax.)

Hope this helps!


Aside: It’s generally unwise to post the full DATABASE_URL, since it contains a password.

It worked! I spent 5 hours trying to crack it on…

The solution that helped was very simple and obvious… after listing all the available tables in my cluster I saw that mine with a correct and full data is still in there waiting.

$ fly pg connect -a new-db-app-name
postgres=# \l

Then I just followed the second suggestion and tricked a DATABASE_URL so that it uses the right table.

It works splendid!

1 Like