So latest
is not a valid tag in this particular image repo. If you’re using PG 14, you should specify flyio/postgres:14
or the specific tag listed when you run image show
.
Hi @shaun, I’ve created a Postgres DB following the official docs
Then I created the .toml
file by doing fly config save --app theirstack-test
and added the [[Services]]
part from your comment. I tried both the secure and insecure versions.
My full fly.toml
file looks like this:
# fly.toml file generated for theirstack-test on 2022-07-18T18:15:22+02:00
app = "theirstack-test"
kill_signal = "SIGTERM"
kill_timeout = 300
processes = []
[checks]
[checks.pg]
grace_period = "30s"
headers = []
interval = "15s"
method = "get"
path = "/flycheck/pg"
port = 5500
protocol = "http"
restart_limit = 0
timeout = "10s"
tls_skip_verify = false
type = "http"
[checks.role]
grace_period = "30s"
headers = []
interval = "15s"
method = "get"
path = "/flycheck/role"
port = 5500
protocol = "http"
restart_limit = 0
timeout = "10s"
tls_skip_verify = false
type = "http"
[checks.vm]
grace_period = "1s"
headers = []
interval = "1m"
method = "get"
path = "/flycheck/vm"
port = 5500
protocol = "http"
restart_limit = 0
timeout = "10s"
tls_skip_verify = false
type = "http"
[env]
PRIMARY_REGION = "mad"
[build]
image = "flyio/postgres:14.4"
[experimental]
allowed_public_ports = []
auto_rollback = false
enable_consul = true
private_network = true
[metrics]
path = "/metrics"
port = 9187
[[mounts]]
destination = "/data"
encrypted = false
source = "pg_data"
[[services]]
internal_port = 5432
protocol = "tcp"
[[services.ports]]
handlers = ["tls"]
port = 443
I need to connect to it from Heroku and eventually from GitHub to set up actions.
Running flyctl postgres connect theirstack-test
works, but when I try to connect with psql it fails. The hostname is theirstack-test.fly.dev
.
My psql command looks like this:
psql postgresql://postgres:<PASSWORD>@theirstack-test.fly.dev:5432/postgres
But I keep getting the same error: psql: error: could not translate host name "theirstack-test.fly.dev" to address: nodename nor servname provided, or not known
Is there something wrong with my connection string?
Hello.
It’s been some time, but it might help someone else.
There are a few things to be done.
You updated the port in the fly.toml
file, so that’s part of it.
For it to work externally, you’ll need an IP as well, otherwise, the host can’t be solved externally.
So use the command
flyctl ips allocate-v4 -a postgres_app
Or
flyctl ips allocate-v6 -a postgres_app
Depending on what you need.
To check the IP:
flyctl ips list -a postgres_app
Then your URL should be something like:
postgres://postgres:<password>@theirstack-test.fly.dev:443/postgres
Hope it helps!
Now that dedicated IP addresses are a paid feature, is there any other way to access the Fly Postgres from an external server?
You can use flyctl postgre connect
but this way you can use psql
only. A second way is use the command fly proxy <custom-local-port>:5432 -a <pg-instance-name>
. This command will establish a proxy connection from your local PC to the FlyIo private network of your DB instance. Then use some tools like PGAdmin to connect to your localhost:. Now you’re connected.
I did this an my DB app (I’m using TablePlus on my Mac) and connects fine. But I need to fly proxy
. I wish I didn’t need to do this dance every time I need to connect. I have a dedicated IP address, BTW.