TCP proxy to expose Fly.io Managed Postgres databases over public networking.
This is a simple proxy example if you need to expose a Fly.io Managed Postgres database over public networking.
We don't currently directly support public networking for Fly.io Managed Postgres databases.
-
Clone and prepare
git clone <repo> cd fly-postgres-proxy go mod tidy
-
Set primary region to match database region in
fly.toml
-
Create Fly app
fly apps create your-postgres-proxy
-
Set database URL
fly mpg attach <cluster-id> --app your-postgres-proxy
-
Deploy
# make sure you allocate IPs - you likely want a v4, and v6 # `fly deploy` should offer this otherwise you can use `fly ips allocate-v4` and `fly ips allocate-v6` fly deploy
Connect to your database through the proxy:
# Using psql
psql postgresql://user:[email protected]:5432/dbname
# Using any Postgres client
host: your-postgres-proxy.fly.dev
port: 5432
user: your_db_user
password: your_db_password
database: your_db_name
The proxy runs in your Fly.io organization with access to the private WireGuard network. It forwards TCP connections from the public internet to your private Postgres instance.
This exposes your database publicly. Consider IP restrictions for production use.