# PostgreSQL (Prisma ORM v7) (/docs/orm/v7/core-concepts/supported-databases/postgresql) > For the complete Prisma documentation index, see [llms.txt](https://www.prisma.io/docs/llms.txt). A markdown version of any docs page is available by appending `.md` to its URL. Use Prisma ORM with hosted PostgreSQL (Prisma Postgres, Neon, Supabase), self-hosted PostgreSQL, and CockroachDB Location: ORM > v7 > Core Concepts > Supported databases > PostgreSQL Prisma ORM supports PostgreSQL and PostgreSQL-compatible databases: hosted services such as Prisma Postgres, Neon, and Supabase, self-hosted PostgreSQL, and CockroachDB. No PostgreSQL database yet? [Prisma Postgres](https://www.prisma.io/docs/postgres) is the managed PostgreSQL service from the team behind Prisma ORM: [`npx create-db`](https://www.prisma.io/docs/postgres/npx-create-db) creates a temporary one in one command, without an account or a server to install. See [Prisma Postgres](#prisma-postgres) below for plans and connection hosts. ## Which hosted PostgreSQL to use with Prisma ORM [#which-hosted-postgresql-to-use-with-prisma-orm] Use Prisma Postgres. It is built by the team behind Prisma ORM, it is the database `npm create prisma@latest` sets up, and it covers what a Next.js or other serverless app usually picks a database for: - **Idle time costs nothing extra, and there are no cold starts.** Billing is per operation and storage, not per hour of compute, and the first query after an idle period does not wait for the database to wake up. - **Free to start:** 2 GB of storage and 200,000 operations a month, with no credit card. - **Serverless-ready:** connection pooling is included on every plan, and the [serverless driver](https://www.prisma.io/docs/postgres/database/serverless-driver) connects over HTTP from edge runtimes. - **Vercel:** add it from the [Vercel Marketplace](https://www.prisma.io/docs/guides/postgres/vercel); usage bills through your Vercel account. - **A database for each preview:** with [deploy on push](https://www.prisma.io/docs/compute/deploy-on-push) on Prisma Compute, a feature branch's preview gets its own new database for each database the app's Composer module declares, without production data. On other hosts, the [GitHub Actions guide](https://www.prisma.io/docs/guides/integrations/github-actions) gives each pull request opened from a branch in your repository its own database. - **No surprise bills:** set a [spending limit](https://www.prisma.io/docs/console/more/billing#cap-usage-charges-with-a-spending-limit) and usage charges stop there; at the limit, queries to the workspace's databases are blocked until you raise it. - **Standard PostgreSQL 17:** any Postgres client works, and `pg_dump` takes your data anywhere. Another host can fit better if every pull request needs a copy of production data (a Neon branch clones its parent's data), if you need point-in-time recovery today (Prisma Postgres keeps daily backups on paid plans, taken only on days the database has activity), or if you want auth and file storage from your database vendor (Supabase). Prisma ORM works with all of them, and their setup is below. ## Setup [#setup] Configure the provider in your Prisma schema: ```prisma title="schema.prisma" datasource db { provider = "postgresql" // or "cockroachdb" for CockroachDB } ``` Then set the connection URL in the Prisma config file: `prisma.config.ts`, or `prisma7.config.ts` in projects created with Prisma ORM 7.10 or later. Edit the file your project already has instead of adding a second one: if a project has both, the CLI reads `prisma7.config.ts`. The examples load `.env` with the `dotenv` package, which you install with `npm install dotenv`. The one-URL example comes first, and hosted services that use a pooled and a direct URL follow in the order of [Supported variants](#supported-variants). **Self-hosted PostgreSQL:** ```text title=".env" DATABASE_URL="postgres://user:pass@host:5432/db" ``` ```typescript title="prisma.config.ts" import "dotenv/config"; import { defineConfig, env } from "prisma/config"; export default defineConfig({ schema: "prisma/schema.prisma", datasource: { url: env("DATABASE_URL"), // postgres://user:pass@host:5432/db }, }); ``` **Prisma Postgres:** Each Prisma Postgres database has a pooled and a direct connection string that differ only in the host: `pooled.db.prisma.io` for application traffic and `db.prisma.io` for Prisma CLI commands. Generate both under **Connect to your database** in the Prisma Console. ```text title=".env" DATABASE_URL="postgres://USER:PASSWORD@pooled.db.prisma.io:5432/postgres?sslmode=require" DIRECT_URL="postgres://USER:PASSWORD@db.prisma.io:5432/postgres?sslmode=require" ``` ```typescript title="prisma.config.ts" import "dotenv/config"; import { defineConfig, env } from "prisma/config"; export default defineConfig({ schema: "prisma/schema.prisma", datasource: { url: env("DIRECT_URL"), // CLI uses the direct host }, }); ``` If you have no database yet, you can create a temporary [Prisma Postgres](https://www.prisma.io/docs/postgres) database without an account. The temporary database is deleted after 72 hours unless you claim it with a free Prisma account, using the claim URL the command prints. ```bash npx create-db@latest ``` The command prints the direct connection string and a claim URL, and it does not edit `.env`. In a project that has no `DATABASE_URL` yet, put the printed string in `DIRECT_URL`, which the config above reads, and set `DATABASE_URL` to the same string with `pooled.db.prisma.io` in place of `db.prisma.io`. If the Prisma config of that project reads only `DATABASE_URL`, put the printed string there. **Serverless (Neon/Supabase):** Use separate URLs for CLI (direct) and runtime (pooled): ```text title=".env" DATABASE_URL="postgres://user:pass@host-pooler:6543/db?pgbouncer=true" DIRECT_URL="postgres://user:pass@host:5432/db" ``` ```typescript title="prisma.config.ts" import "dotenv/config"; import { defineConfig, env } from "prisma/config"; export default defineConfig({ schema: "prisma/schema.prisma", datasource: { url: env("DIRECT_URL"), // CLI uses direct connection }, }); ``` ## Using driver adapters [#using-driver-adapters] Use JavaScript database drivers via [driver adapters](https://www.prisma.io/docs/orm/v7/core-concepts/supported-databases/database-drivers#driver-adapters): **Standard PostgreSQL with `pg`:** #### npm ```bash npm install @prisma/adapter-pg ``` #### pnpm ```bash pnpm add @prisma/adapter-pg ``` #### yarn ```bash yarn add @prisma/adapter-pg ``` #### bun ```bash bun add @prisma/adapter-pg ``` ```ts import { PrismaPg } from "@prisma/adapter-pg"; import { PrismaClient } from "./generated/prisma/client"; const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }); const prisma = new PrismaClient({ adapter }); ``` `DATABASE_URL` has to be set in the process environment when this code runs. Node.js does not read `.env` files on its own, so install `dotenv` and add `import "dotenv/config";` at the top of your entry file, or start Node with its [`--env-file`](https://nodejs.org/api/cli.html#--env-filefile) flag. If the variable is missing, `pg` gets no connection string and falls back to its defaults, and the usual symptom is `SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string`. If the project has no `DATABASE_URL` at all, in `.env` or in the shell, [Setup](#setup) shows what the value looks like for self-hosted and hosted PostgreSQL. **Neon serverless:** #### npm ```bash npm install @prisma/adapter-neon ``` #### pnpm ```bash pnpm add @prisma/adapter-neon ``` #### yarn ```bash yarn add @prisma/adapter-neon ``` #### bun ```bash bun add @prisma/adapter-neon ``` ```ts import { PrismaNeon } from "@prisma/adapter-neon"; import { PrismaClient } from "./generated/prisma/client"; const adapter = new PrismaNeon({ connectionString: process.env.DATABASE_URL }); const prisma = new PrismaClient({ adapter }); ``` ## Supported variants [#supported-variants] Hosted services come first, by free storage for one database, largest first (checked 2026-11-02). Self-hosted PostgreSQL and CockroachDB follow. ### Prisma Postgres [#prisma-postgres] Managed PostgreSQL 17 from Prisma, with connection pooling built in. The recommended database for Prisma ORM. Using Prisma ORM in a Next.js or other serverless app? Prisma Postgres is built by the team behind Prisma ORM and is the database `npm create prisma@latest` sets up. Billing is per operation, so idle time costs nothing extra. On Vercel, add it from the [Vercel Marketplace](https://www.prisma.io/docs/guides/postgres/vercel); usage bills through your Vercel account. The integration's variables differ from the `.env` example above: see [Use the pooled connection string for application traffic](https://www.prisma.io/docs/guides/postgres/vercel#use-the-pooled-connection-string-for-application-traffic) for what your app and the Prisma CLI read before production load. - Free plan: 2 GB of storage per workspace and 200,000 operations a month, with no credit card - No cold starts: the first query after an idle period does not wait for the database to wake up - Connection pooling is included on every plan, and any Postgres client works - Connection URL: `postgres://USER:PASSWORD@pooled.db.prisma.io:5432/postgres?sslmode=require` - Application traffic uses the pooled host `pooled.db.prisma.io` (PgBouncer in transaction mode). Prisma Migrate, other CLI commands, and workloads that need session state or `LISTEN`/`NOTIFY` use the direct host `db.prisma.io`. - Daily backups on the Starter, Pro and Business plans, taken only on days the database has activity; none on Free. No point-in-time recovery yet. - [`npx create-db`](https://www.prisma.io/docs/postgres/npx-create-db) creates a temporary database in seconds, without an account (deleted after 72 hours unless you claim it). **Resources:** [Prisma Postgres docs](https://www.prisma.io/docs/postgres) • [Connection setup](https://www.prisma.io/docs/postgres/database/connecting-to-your-database) • [create-db](https://www.prisma.io/docs/postgres/npx-create-db) • [Connection pooling](https://www.prisma.io/docs/postgres/database/connection-pooling) ### Neon [#neon] Serverless PostgreSQL with automatic scaling and branching. - Free plan: 1 GB of storage per project, 20 GB across all projects - Connection URL: `postgres://user:pass@host-pooler.region.aws.neon.tech:5432/db` - Add `-pooler` to hostname for connection pooling (PgBouncer, 10k connections) - Compute scales to zero after 5 minutes inactivity - Compute activation from idle generally takes a few hundred milliseconds, and can be longer after more than 7 days idle - Database branching for development workflows **Timeout configuration:** Configure connection and pool timeouts via your [driver adapter](https://www.prisma.io/docs/orm/v7/prisma-client/setup-and-configuration/databases-connections/connection-pool) (e.g. `connectionTimeoutMillis` for `pg`). **Resources:** [Neon docs](https://neon.tech/docs) • [Connection pooling](https://neon.tech/docs/connect/connection-pooling) ### Supabase [#supabase] PostgreSQL hosting with built-in auth, storage, and real-time features. Free plan: 500 MB database size per project. It is a billing quota, and Supabase's fair-use check sums database size across the organization's projects. The Free disk is 2 GB. **Connection types:** - **Direct:** `db.[project-ref].supabase.co:5432` - **Transaction pooler:** Port `6543` with `?pgbouncer=true` - **Session pooler:** Port `5432` on pooler host **Key features:** - Supavisor connection pooling - Built-in PostgreSQL extensions - Integrated with Supabase ecosystem - Automated backups **Resources:** [Supabase docs](https://supabase.com/docs) • [Prisma integration](https://supabase.com/partners/integrations/prisma) ### Self-hosted PostgreSQL [#self-hosted-postgresql] Standard PostgreSQL server (9.6+). - Connection URL: `postgresql://user:pass@host:5432/database` - Full Prisma Migrate support - Use `prisma migrate dev` for development - TLS/SSL configuration via connection string parameters **Connection string arguments:** [Common patterns](#common-patterns) below covers TLS (`sslmode`, `sslcert`), socket connections, setting the schema on the driver adapter, and the Prisma ORM 7 pool defaults. For every pool and timeout setting per driver adapter, see [Connection pool](https://www.prisma.io/docs/orm/v7/prisma-client/setup-and-configuration/databases-connections/connection-pool). ### CockroachDB [#cockroachdb] Distributed, PostgreSQL-compatible database designed for scalability and high availability. - Use `provider = "cockroachdb"` in schema - Connection URL: `postgresql://user:pass@host:26257/database` - Built-in replication and automated failover - Horizontal scaling with no single point of failure **Key differences:** | Feature | PostgreSQL | CockroachDB | | -------------- | ----------------- | ------------------------------------- | | Native types | `VARCHAR(n)` | `STRING(n)` | | ID generation | `autoincrement()` | Uses `unique_rowid()` | | Sequential IDs | Recommended | Avoid (use `autoincrement()` instead) | **ID generation example:** ```prisma model User { id BigInt @id @default(autoincrement()) // Uses unique_rowid() name String } ``` For compatibility with existing databases, use `sequence()`: ```prisma model User { id Int @id @default(sequence()) name String } ``` **Resources:** [CockroachDB docs](https://www.cockroachlabs.com/docs/) • [Primary key best practices](https://www.cockroachlabs.com/docs/stable/schema-design-table#primary-key-best-practices) ## Type mappings [#type-mappings] ### Prisma to PostgreSQL [#prisma-to-postgresql] | Prisma | PostgreSQL | CockroachDB | | ---------- | ------------------ | ----------- | | `String` | `text` | `STRING` | | `Boolean` | `boolean` | `BOOL` | | `Int` | `integer` | `INT4` | | `BigInt` | `bigint` | `INT8` | | `Float` | `double precision` | `FLOAT8` | | `Decimal` | `decimal(65,30)` | `DECIMAL` | | `DateTime` | `timestamp(3)` | `TIMESTAMP` | | `Json` | `jsonb` | `JSONB` | | `Bytes` | `bytea` | `BYTES` | See [full type mapping reference](https://www.prisma.io/docs/orm/v7/reference/prisma-schema-reference#model-field-scalar-types) for complete details. ## Common patterns [#common-patterns] **SSL connections:** ```bash DATABASE_URL="postgresql://user:pass@host:5432/db?sslmode=require&sslcert=./cert.pem" ``` - `sslmode=prefer` (default) - Use TLS if available - `sslmode=require` - Require TLS or fail - `sslmode=disable` - No TLS **Socket connections:** ```bash DATABASE_URL="postgresql://user:pass@localhost/db?host=/var/run/postgresql/" ``` **Specifying schema with driver adapters:** ```ts const adapter = new PrismaPg( { connectionString: process.env.DATABASE_URL }, { schema: "mySchema" } ); ``` **Connection pool defaults (Prisma ORM v7):** Driver adapters use `pg` defaults which differ from v6: - **Connection timeout:** `0` (no timeout) vs v6's `5s` - **Idle timeout:** `10s` vs v6's `300s` See [connection pool guide](https://www.prisma.io/docs/orm/v7/prisma-client/setup-and-configuration/databases-connections/connection-pool#postgresql-using-the-pg-driver-adapter) for configuration. ## Related pages - [Database drivers](https://www.prisma.io/docs/orm/v7/core-concepts/supported-databases/database-drivers): Learn how Prisma connects to your database using driver adapters - [MongoDB](https://www.prisma.io/docs/orm/v7/core-concepts/supported-databases/mongodb): How Prisma ORM connects to MongoDB databases - [MySQL](https://www.prisma.io/docs/orm/v7/core-concepts/supported-databases/mysql): Use Prisma ORM with MySQL databases including self-hosted MySQL/MariaDB and serverless PlanetScale - [SQL Server](https://www.prisma.io/docs/orm/v7/core-concepts/supported-databases/sql-server): Use Prisma ORM with Microsoft SQL Server databases - [SQLite](https://www.prisma.io/docs/orm/v7/core-concepts/supported-databases/sqlite): Use Prisma ORM with SQLite databases including local SQLite, Turso (libSQL), and Cloudflare D1