Can't connect to Postgres DB externally after following docs.

Followed the docs here and read through a few issues (notably this one), and I’m still not sure which bit of my configuration is not correct:

fly.toml

# fly.toml file generated for flxwebsites-db-staging on 2022-11-18T12:07:29-05:00

app = "flxwebsites-db-staging"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[env]

[experimental]
  allowed_public_ports = []
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 5432
  protocol = "tcp"
  script_checks = []

  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    handlers = []
    port = 10000

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

fly info

❯ fly info -a flxwebsites-db-staging
App
  Name     = flxwebsites-db-staging
  Owner    = flx-websites
  Platform = machines
  Hostname = flxwebsites-db-staging.fly.dev

Services
PROTOCOL        PORTS   FORCE HTTPS

IP Addresses
TYPE    ADDRESS         REGION  CREATED AT
v4      149.248.198.118 global  34m23s ago

Connection attempt

❯ psql postgres://postgres:<password>@flxwebsites-db-staging.fly.dev:10000/
psql: error: connection to server at "flxwebsites-db-staging.fly.dev" (149.248.198.118), port 10000 failed: server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.

Hi, I’m not from the fly team but I think I can help you :slight_smile: .

To connect to the database it is necessary to do it through a VPN.

Another alternative is to do it using the fly client:
https://fly.io/docs/postgres/the-basics/connecting/#connecting-to-fly-postgres-from-outside-fly

You may have to run this command before connecting as you want:
flyctl proxy 5432 -a <postgres-app-name>

@fedeotaran hmm, OK I think I misunderstood the docs when first reading them and this is probably what I want:

Thanks!

1 Like