
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: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 afly.toml configuration file for your Postgres app, if you don’t have it:
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:
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 infly.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:
--image with the image:tag found in the previous step:
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:
Adapting the connection string
The connection string thatfly pg create outputs for use in consuming apps is in the form:
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.