On this page

Connect to Postgres

Connect any Postgres client, ORM or migration tool to your project's database through the StitchDB connection pooler. TLS is required.

#Connection details

Copy them from your project's Settings → Database in the dashboard, where the password and full connection strings are shown.

SettingValue
HostThe database host of your project, for example pooler-eu-de-1.stitchdb.com
Port5432 session mode, 6543 transaction mode
Databasep_<project-ref>
Userp_<project-ref>_owner (copy the exact value from the dashboard)
PasswordShown in your project's Settings → Database
TLSRequired: sslmode=require (TLS 1.2 or 1.3)
Terminal
psql "postgresql://p_<ref>_owner:<password>@<db-host>:5432/p_<ref>?sslmode=require"

#A stable host

Each project keeps the database host it was created with for its whole life. If StitchDB moves your project to another server, connections to the same host are forwarded to the new server, so you never have to change connection strings. The host resolves to an IPv4 address.

#Direct or pooled?

Postgres itself is not exposed to the internet: every connection goes through the StitchDB connection pooler, which checks TLS and the password first.

  • Session mode (5432) behaves like a direct connection: each client gets its own database connection while it stays connected, so SET, LISTEN/NOTIFY, temporary tables and session advisory locks work. Use it for psql, migrations and long-running servers.
  • Transaction mode (6543) hands out a database connection per transaction and shares it between clients. It suits serverless functions and many short-lived connections. Prepared statements sent by drivers work; session state (plain SET, LISTEN, SQL PREPARE, temporary tables, session advisory locks) does not carry over between transactions.

More in Connection pooling modes.

#TLS

Connections without TLS are refused. Use sslmode=require (or verify-full if your driver has the public certificate authorities installed); the server certificate is issued for the database host.

#Network restrictions

Included from the Pro plan. Limit Postgres connections to your own servers: in Settings → Database → Network restrictions, list the IPv4 addresses or CIDR ranges (up to 50) that may connect on ports 5432 and 6543. Every other address is refused before the password is checked. Leave the list empty to allow every address. Open connections stay open when you change the list.

The REST, Auth, Storage and Realtime APIs, Edge Functions, Studio and the SQL editor are not affected: they reach the database inside StitchDB. With the Management API:

Terminal
curl -X PUT https://stitchdb.com/platform/v1/projects/<ref>/network-restrictions \
  -H "Authorization: Bearer $STITCHDB_TOKEN" -H "Content-Type: application/json" \
  -d '{"allowlist": ["203.0.113.7", "198.51.100.0/24"]}'

#ORMs and drivers

.env
# Prisma, Drizzle, Knex, SQLAlchemy, ...
DATABASE_URL="postgresql://p_<ref>_owner:<password>@<db-host>:6543/p_<ref>?sslmode=require"

Startup options in the connection string, such as options=-c … or search_path, are ignored by the pooler; run SET after connecting instead.

#Limits

Each plan limits the database connections of your project role (Direct database connections), the clients the pooler accepts (Pooled client connections) and the database connections the pooler opens for you (Pooler database connections). A single IP address can also open only a limited number of new connections per second. See Database limits.