Skip to main content

Connect your database

Connecting your database

To connect your database, you need to set the url field of the datasource block in your Prisma schema to your database connection URL:

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")

In this case, the url is set via an environment variable which is defined in .env:


You now need to adjust the connection URL to point to your own database.

Connection URL

The format of the connection URL for your database depends on the database you use. For PostgreSQL, it looks as follows (the parts spelled all-uppercased are placeholders for your specific connection details):


Note: In most cases, you can use the postgres:// and postgresql:// URI scheme designators interchangeably - however, depending on how your database is hosted, you might need to be specific.

If you're unsure what to provide for the schema parameter for a PostgreSQL connection URL, you can probably omit it. In that case, the default schema name public will be used.

As an example, for a PostgreSQL database hosted on Heroku, the connection URL might look similar to this:


When running PostgreSQL locally on macOS, your user and password as well as the database name typically correspond to the current user of your OS, e.g. assuming the user is called janedoe: