
Creating a Managed Postgres Cluster from the Dashboard
To create a new Managed Postgres (MPG) cluster, visit your Fly.io dashboard, select the āManaged Postgresā tab on the left, and click the āCreate new clusterā button. Youāll be prompted to set your clusters:- Cluster name (must be unique within your organization)
- Region (see available MPG regions)
- A plan with predefined hardware resources:
- Basic: 2 shared vCPUs, 1GB RAM
- Starter: 2 shared vCPUs, 2GB RAM
- Launch: 2 Performance vCPUs, 8GB RAM
- Scale: 4 Performance vCPUs, 32GB RAM
- Performance: 8 Performance vCPUs, 64GB RAM
- Initial storage size: Up to 500 GB at creation
- Optional PostGIS support. Other extensions, including pgvector, are enabled after creation from the Extensions page

Creating a Managed Postgres Cluster from Flyctl

--volume-size flag:
Attach an application to your Managed Postgres Database
To connect your application running on Fly.io to your Managed Postgres instance, youāll need to add the DB connection details as a secret on your app. This can be done from the Dashboard or via flyctl.Attaching an app from your MPG dashboard
From the āConnectā tab of your MPG Cluster page you can attach a specific app in your organization to your database.- Select the app to attach in the dropdown
- If needed, customize the variable name to use for the database connection URL. The default is
DATABASE_URL. If your chosen app already has a secret namedDATABASE_URL, you will need to choose a new variable name before you can deploy. - Select āSet secret and deployā. This will trigger a deploy of your chosen app to add the new secret.
- Your app can now use the
DATABASE_URLenvironment variable to connect to your database
Attaching an app using flyctl
To attach an application to your database using flyctl run:fly mpg list command.
Both of the attachment options will use the pooled connection URL, which uses PGBouncer to help manage database connections efficiently. This is recommended for most apps.
Manually connect an application using a connection string
After your database is created, the āConnectionā tab will display connection strings for both the pooled connection URL, and the direct database connection address. You can use these to manually connect an app to the database by setting it as a secret in your Fly.io application:Connecting from a local machine using flyctl
Because your MPG Cluster runs within your Fly.io private network, itās not accessible over the public internet. You can use flyctl to securely connect to your database from your local machine for development, manual DB work, or to connect to a local tool. All connections using flyctl are securely routed through your organizations private wireguard networkConnecting with psql
To connect directly to your Managed Postgres database using psql:Running SQL without a session
To run SQL from a script, a CI job, or an agent, pass it tofly mpg connect with -c or -f. The command runs the SQL, prints the result, and exits. Pass the cluster ID: with -c or -f, flyctl doesnāt prompt for a cluster, user, or database.
The -c and -f flags are available in flyctl v0.5.9 and later. If your fly does not have them, run fly version upgrade or install flyctl.
Run one statement:
-c and -f in one command. Use --database and --username to connect to something other than the defaults.
Everything after -- goes to psql unchanged. For example, to get a bare value into a shell variable, add psqlās -At flags:
Proxying... line that flyctl prints goes to stderr.
To read SQL from stdin, pass -f -. It behaves like any other file:
-c or -f keeps psqlās default behavior: it reads your psqlrc file and carries on after an error.
fly mpg connect exits with status 0 when psql succeeds and 1 when psql fails, so a script can check it. On failure, psqlās own error is followed by a line with psqlās exit status:
1 for a failed -c statement or an error of its own, such as a file it canāt read. It uses 2 for a connection that couldnāt be made or was lost, and 3 for a script that stopped at an error. flyctl also exits with status 1 for its own errors, such as a cluster it canāt find.
fly mpg connect always listens on local port 16380, which is also the default port for fly mpg proxy. Run one fly mpg connect at a time on your local machine, and give a proxy you run alongside it a different --local-port.