fly postgres create command. The command will walk you through the creation with prompts for name, region, and VM resources.
Because we keep adding shorter aliases, you can use any of the following and get the same result:
flyctl postgres, fly postgres, flyctl pg, and fly pg.You might need to configure any apps that connect to your Postgres app to scale to zero as well, otherwise your Postgres database will never have zero connections and will never scale down. Your app might also need to be able to wait for the database to start back up. Learn more about the scale to zero feature, including how to turn it off.
Connecting to the Database
To connect to our database, we first have to communicate with our app what the connection string is. Copy the value after “Connection string” in the output and then set a new secret:By default your postgres app is only available within your organization. Only apps within the fly organization are able to connect to it via the connection string above.
DATABASE_URL from the environment:
asyncpg:
Developing with Postgres Locally
Often you will want to setup a local postgres to run against. One way to do this is to usedocker and direnv. With the following command you can spin up a postgres database for your project:
.envrc file:
direnv allow the DATABASE_URL will be available to your app locally.