Skip to content

Latest commit

 

History

History
73 lines (53 loc) · 2.84 KB

postgresql.md

File metadata and controls

73 lines (53 loc) · 2.84 KB

PostgreSQL data source connector

The PostgreSQL data source connector connects Prisma to a PostgreSQL database server.

Example

To connect to a PostgreSQL database server, you need to configure a datasource block in your schema file:

datasource pg {
  provider = "postgresql"
  url      = env("POSTGRESQL_URL")
}

// ... the file should also contain a data model definition and (optionally) generators

The fields passed to the datasource block are:

Find more information on the datasource fields here.

Data model mapping

The PostgreSQL connector maps the scalar types from the data model as follows to native column types:

Data model PostgreSQL
String text
Boolean boolean
Int integer
Float real
Datetime timestamp

Connection details

Connection string

PostgreSQL offers two styles of connection strings:

  • Key-value string: host=localhost port=5432 database=mydb connect_timeout=10
  • Connection URI:
    postgresql://
    postgresql://localhost
    postgresql://localhost:5433
    postgresql://localhost/mydb
    postgresql://user@localhost
    postgresql://user:secret@localhost
    postgresql://other@localhost/otherdb?connect_timeout=10&application_name=myapp
    postgresql://host1:123,host2:456/somedb?target_session_attrs=any&application_name=myapp
    

See the official documentation for details.

The connection URI needs to follow the official format for PostgreSQL connection strings:

postgresql://[user[:password]@][netloc][:port][,...][/database][?param1=value1&...]

Configuration options

  • host: The IP address/domain of your database server, e.g. localhost.
  • port: The port on which your database server listens, e.g. 5432.
  • database: The name of the database with the target schema.
  • schema: The name of the target schema. Default: public.
  • user: The database user, e.g. admin.
  • password: The password for the database user.
  • ssl: Whether or not your database server uses SSL.
  • connection_limit: The connection limit specifies the maximum number of simultaneous connections that Prisma might have open to your database. Default: 1.