New phoenix hello_world app - error attaching to Postgres Cluster


I followed the steps on Deploy an Elixir Phoenix Application and here is the output.

It failed to attach to Postgres cluster. I see there is a "unable to authenticate, attempted methods [none publickey] - where do I have to add the publickey?

Not sure if I missed some other configuration. Any help would be appreciated.

fly launch
Creating app in /Users/kannan/projects/fly_deploy/hello_elixir
Scanning source code
Detected a Phoenix app
? App Name (leave blank to use an auto-generated name):
Automatically selected personal organization: <firstname> <lastname>
? Select region: dfw (Dallas, Texas (US))
Created app red-snowflake-**** in organization personal
Set secrets on red-snowflake-****: SECRET_KEY_BASE
Preparing system for Elixir builds
Installing application dependencies
Running Docker release generator
Wrote config file fly.toml
? Would you like to setup a Postgresql database now? Yes
For pricing information visit:
? Select configuration: Development - Single node, 1x shared CPU, 256MB RAM, 1GB disk
Creating postgres cluster red-snowflake-****-db in organization personal
Postgres cluster red-snowflake-*****-db created
  Username:    postgres
  Password:    **********************
  Hostname:    red-snowflake-*****-db.internal
  Proxy Port:  5432
  PG Port: 5433
Save your credentials in a secure place, you won't be able to see them again!

Monitoring Deployment

1 desired, 1 placed, 1 healthy, 0 unhealthy [health checks: 3 total, 3 passing]
--> v0 deployed successfully

Connect to postgres
Any app within the personal organization can connect to postgres using the above credentials and the hostname "red-snowflake-****-db.internal."
For example: postgres://postgres:*********@red-snowflake-****-db.internal:5432

See the postgres docs for more information on next steps, managing postgres, connecting from outside fly:
Running flyadmin database-list
Error Failed attaching red-snowflake-*****-db to the Postgres cluster red-snowflake-****: error connecting to SSH server: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain.\nTry attaching manually with 'fly postgres attach --app red-snowflake-***** --postgres-app red-snowflake-****-db'`

I think that might have been a race condition in our infrastructure. It distributes the SSH key and then tries to connect, you’d get that error if the connection attempt happened before the SSH key appeared on the host.

Can you try running that last command from the logs manually and see if it works?

fly postgres attach --app red-snowflake-***** --postgres-app red-snowflake-****-db

Now I get the error that the db already exists

fly postgres attach --app red-snowflake-**** --postgres-app red-snowflake-****-db
Running flyadmin database-list
? Database "red_snowflake_****" already exists. Continue with the attachment process? Yes
Running flyadmin user-list
Error Database user "red_snowflake_****" already exists. Please specify a new database user via --database-user

I deleted the app and the db and reinstalled it couple of times and got it working eventually.

Thanks for your help @kurt

I’m seeing the same error, but when I attempt to retry the attach I get an “unexpected end of JSON input” error

$ fly postgres attach --app my-app --postgres-app my-app-db
Running flyadmin database-list
Running flyadmin user-list
Running flyadmin database-create
Running flyadmin user-create
Error unexpected end of JSON input

Here’s the info on the flyctl version I’m running.

flyctl v0.0.306 linux/amd64 Commit: b5101f2 BuildDate: 2022-03-15T18:17:35Z

I got that JSON error too when I tried to reattach as the instructions say. I deleted the app and db and started over and it worked better, though I had to try it a few times.