Can't get Postgres external connection working

Trying to follow the instructions at https://fly.io/docs/postgres/connecting/connecting-external/ to set up a single Postgres instance with external connections. Here’s what I ran into:

  • Not clear what the fly.toml should be, other than the service section
  • When deploying another instance the CLI asks if the original instance should be converted to part of an application group (or something like that)
  • The second instance is deployed but in a critical condition
  • I’m not sure what to do with the original primary instance

Just to be clear, my goal is to have a single instance (no replicas) that has external connection using the pg_tls handler.

1 Like

I’m having the same issue here.

The CLI message is: “Found 1 machines that are not part of the Fly Apps Platform”, and then ask if the machine associated to the Postgres application should be migrated.

If you say yes → an error happen because the fly.toml file does not have a “mount” section - when the Postgres app uses a volume.

If you say no → a new machine is created but fails non-stop.

I previously followed the documentation some weeks ago, and it worked fine.

How to make it work?

Hi all, I’m looking into this. Please share the actual commands you’re running and the output.

1 Like

In the meantime, you can downgrade the version of flyctl you’re using to one that doesn’t have these issues. Version 0.0.458 is likely to work and can be installed with:

curl -L https://fly.io/install.sh | sh -s -- v0.0.458
$ flyctl deploy . --image flyio/postgres:14.6
==> Verifying app config
--> Verified app config
==> Building image
Searching for image 'flyio/postgres:14.6' remotely...
image found: img_0lq747j0ym646x35
WARN Found 1 machines that are not part of the Fly Apps Platform:
dq-db-cyanite-cache machines
ID              NAME            STATE   REGION  IMAGE                           IP ADDRESS                       VOLUME                  CREATED                 LAST UPDATED
6e82267b710087  small-bush-388  started lax     flyio/postgres:14.6 (v0.0.34)   fdaa:1:5a22:a7b:7d16:4d85:70c5:2 vol_ypkl7vz2ml9vqg60    2023-02-18T01:30:12Z    2023-02-18T01:30:28Z

? Migrate 1 existing machines into Fly Apps Platform? No
INFO Skipping machines migration to Fly Apps Platform and the deployment
No machines in dq-db-cyanite-cache app, launching one new machine
  Machine 908052ea6e0e87 [app] update finished: success
  Finished deploying

$ flyctl status
ID              STATE   ROLE    REGION  HEALTH CHECKS           IMAGE                           CREATED                 UPDATED
6e82267b710087  started leader  lax     3 total, 3 passing      flyio/postgres:14.6 (v0.0.34)   2023-02-18T01:30:12Z    2023-02-18T01:30:28Z
908052ea6e0e87  started unknown lax                             flyio/postgres:14.6 (v0.0.34)   2023-02-18T01:34:46Z    2023-02-18T01:34:47Z

$ flyctl info
Command "info" is deprecated, Replaced by 'status', 'ips list', and 'services list'
App
  Name     = dq-db-cyanite-cache
  Owner    = dequency-production
  Platform = machines
  Hostname = dq-db-cyanite-cache.fly.dev

Services
PROTOCOL        PORTS                           FORCE HTTPS
TCP             1374403680304 => 5432 [PG_TLS]  False

IP Addresses
TYPE    ADDRESS         REGION  CREATED AT
v4      149.248.209.81  global  4m1s ago

Using the following fly.toml:

# fly.toml file generated for dq-db-cyanite-cache on 2023-02-17T17:32:42-08:00

app = "dq-db-cyanite-cache"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[env]

[experimental]
  auto_rollback = true

[[services]]
  internal_port = 5432 # Postgres instance
  protocol = "tcp"

[[services.ports]]
  handlers = ["pg_tls"]
  port = 5432

While using the older version of flyctl worked in going through the instructions, I still cannot connect to the db as the hostname isn’t available. And this looks weird as well:

$ ~/.fly/bin/flyctl info
Command "info" is deprecated, Replaced by 'status', 'ips list', and 'services list'
Update available 0.0.458 -> 0.0.462.
Run "flyctl version update" to upgrade.
App
  Name     = dq-db-cyanite-cache
  Owner    = dequency-production
  Platform = machines
  Hostname = dq-db-cyanite-cache.fly.dev

Services
PROTOCOL        PORTS                           FORCE HTTPS
TCP             1374405256852 => 5432 [PG_TLS]  False

IP Addresses
TYPE    ADDRESS         REGION  CREATED AT
v4      37.16.18.144    global  16m40s ago

I used an old CLI version, and it worked for me. I managed to connect to my-application.fly.dev.

Did you allocate an IPv4 address to your hostname?

I did assign an IPv4 address and it didn’t work for me. I ended up just provisioning a managed Postgres server at Render.