Skip to main content
Important: We are not able to provide support or guidance for unmanaged Postgres. We now offer Fly.io Managed Postgres , our fully-managed database service that handles all aspects of running production PostgreSQL databases.
Illustration by Annie Ruygt of bird workers on a factory assemmbly line Fly Postgres databases can be used by applications outside their Fly.io internal private network; this means in a different private network belonging to your organization, in another Fly organization, or outside Fly.io altogether. We don’t expose Postgres apps to the internet by default. To get this working, you’ll need to make two adaptations: configuring your Postgres app to accept connections from the Fly proxy, and providing a publicly-resolvable hostname to your app.

Allocate an IP address

If you haven’t already, you will need to allocate a public IP address to your Postgres app. You can view your list of IPs by running the following command from your application directory:
You can allocate an IPv4 address by running the following:
If your network supports IPv6:

Configure an external service

Now that you have an IP address, it’s time to configure your app to accept connections on an external port, and direct incoming requests to your Postgres instance. Pull down a fly.toml configuration file for your Postgres app, if you don’t have it:
Note that this could overwrite a fly.toml in the current directory, so be careful! Open up your fly.toml file. This may come with a default services section for internal_port 8080. Replace that with the following to configure your port mappings to work with Postgres:
Note the use of the pg_tls handler to manage the specific requirements of Postgres connections. For additional information on services and service ports: The services sections

Deploy with the new configuration

Once your service has been set up in fly.toml, it’s time to deploy with the new configuration. Verify the version of Postgres you are running. This step is important, because there can be changes in the internal storage format between major versions of Postgres. Figure out which image and tag (Postgres version) you’re on:
Deploy your cluster, using --image with the image:tag found in the previous step:
As an example, if you are running Postgres 16.x you would specify flyio/postgres-flex:16 as your target image. After the deployment completes, you can verify your services configuration by running the fly services list command:
You should then be able to access your Postgres cluster via psql like:

Adapting the connection string

The connection string that fly pg create outputs for use in consuming apps is in the form:
where the hostname is an internal one. Substitute your newly publicly reachable hostname (<pg-app-name>.fly.dev) here to get a connection string an external app can use.