Search code examples
google-cloud-sqlgoogle-cloud-runprisma

Prisma DATABASE_URL error (Cloud Run + Cloud SQL)


I use Prisma with Cloud Run & Cloud SQL. After providing DATABASE_URL to the prisma.schema it throws me an error in runtime.

Can't reach database server at `(/cloudsql/project-name:us-east1:database-id)`:`5432`
Please make sure your database server is running at `(/cloudsql/project-name:us-east1:database-id)`:`5432`."
  • Database: Postgres
  • Provided url DATABASE_URL: postgresql://username:password@localhost/databasename?host=(/cloudsql/project-name:us-east1:database-id)

What is wrong with connection? Do I failed to construct DATABASE_URL correctly?


Solution

  • I removed brackets () around host parameter /cloudsql/project-name:us-east1:database-id and everything start to work as expected.

    Before (with brackets)

    postgresql://username:password@localhost/databasename?host=(/cloudsql/project-name:us-east1:database-id)
    

    After (without brackets)

    postgresql://username:password@localhost/databasename?host=/cloudsql/project-name:us-east1:database-id