Unable to detach and/or attach to a new db created from snapshot

My database for my app seems to have crashed. I am trying to restore my db from a snapshot but I’m running into errors. I don’t know if I’m doing something wrong or if I’m even trying to solve the actual problem…Any guidance would be much appreceated!

  • The command fly postgres detach returns Error: no active leader found
  • The command fly postgres attach returns Checking for existing attachments Error: consumer app "whodapet" already contains a secret named DATABASE_URL

Hey there,

So I took a look at the DB that crashed. It looks like the last known healthy primary was machine 85755eb4415028. I think the best route would be to tear down your other machines to bring the cluster back down to a single node. Once the primary has been re-established, you can recreate the replicas by cloning the primary machine.

Since the cluster isn’t healthy, the members may not unregister properly when you delete the machines. However, these instructions should help:

In the meantime, i’ll take a look at the attach/detach logic to see what’s going on there.

Thanks. I’ll give it a try.

I tried to follow those instructions but when I try and run repmgr daemon status it is reporting -bash: repmgr: command not found. I tried installing repmgr-common with apt install repmgr-common but that tells me it’s not able to find the package. Am I missing something?

Hey @johnhitz,

You will want to make sure you’re targeting your older database app, which should be whodapet-db.

On another note, it looks like you may have tried to manually set the DATABASE_URL to use the whodapet-db-20240429 app, but forgot to include the database name in the URI. You can see the specific error within the whodapet logs.

Are you using a terminal that supports interactivity?

If so, you should be receiving a confirmation prompt that would allow you to overwrite the existing secret value if that’s what you’re aiming to do.

If you’re not, you could consider trying to pass --yes to auto-confirm.

fly pg attach --help
Attach a postgres cluster to an app

  fly postgres attach <POSTGRES APP> [flags]

  -a, --app string             Application name
  -c, --config string          Path to application configuration file
      --database-name string   The designated database name for this consuming app.
      --database-user string   The database user to create. By default, we will use the name of the consuming app.
  -h, --help                   help for attach
      --superuser              Grants attached user superuser privileges (default true)
      --variable-name string   The environment variable name that will be added to the consuming app.  (default
  -y, --yes                    Accept all confirmations

Global Flags:
  -t, --access-token string   Fly API Access Token
      --debug                 Print additional logs and traces
      --verbose               Verbose output

Turns out I just faithfully copied the connetion string generated by fly. As Shun pointed out, I needed to add the database name to the end so that it is in this configuration
postgres://{username}:{password}@{hostname}:{port}/{database}?options as per Connect From a Fly App · Fly Docs

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