Which hosted Postgres works with Bun's SQL client?
Using Bun's SQL client does not tie the database to a particular ORM or app host. Choose a database that provides a normal PostgreSQL connection URL Bun can use, and preserve the provider's connection security settings.
We make Prisma Postgres and Prisma Compute. The Bun and provider documentation linked here was checked on October 22, 2026.
What should I check before choosing a provider?
Start with the connection URL, region, recovery requirements and pool behavior. A database that supports an HTTP driver may also expose a PostgreSQL endpoint; choose that endpoint for Bun SQL.
Keep the database near the server that runs the queries. A customer opening your frontend nearby does not make a remote database query local. If the app runs on Compute, choose a matching available database region; if it runs elsewhere, compare the two providers' actual locations.
Your Bun client keeps a pool of connections ready for reuse. The hosted database may also have a pooler that shares database connections among application connections. More app instances multiply the client connections. Start with a small per-instance pool and measure contention before increasing it.
Which services fit a Bun application?
These providers, listed alphabetically, expose PostgreSQL connection URLs; choose around the surrounding workflow without changing query libraries.
| Provider | Useful fit | Connection detail to check |
|---|---|---|
| Neon | An app that wants Neon's database workflow, including its pooled and direct endpoints. | Copy the connection string for the intended branch and role; the pooled hostname contains -pooler. |
| Prisma Postgres | A Bun app that wants managed Postgres and built-in pooling, optionally alongside Compute. | Use the pooled PostgreSQL URL in the app. Use the direct URL when an administrative tool needs to keep the same database connection. |
| Supabase | An app that also wants Supabase's surrounding backend services. | Choose its direct, session-pooler or transaction-pooler connection for the host's network and workload. Transaction mode requires prepared statements to be disabled. |
Prisma Postgres is a straightforward fit when the app already uses SQL and needs a managed database without adopting a new data-access layer. Supabase's session pooler keeps a database connection for the client's session; transaction mode lends it for one transaction at a time. Choose a connection mode that supports the app's actual use of sessions.
How do I connect Bun to Prisma Postgres?
1. Create a development database and copy the right URL
Create a database in your account in Prisma Console. Open its connection details and copy the pooled PostgreSQL URL. Preserve its encryption settings, including TLS options, and keep the value in your existing local secret mechanism as DATABASE_URL; do not commit it or paste it into a browser bundle.
Use a direct connection when a migration, dump or other tool needs to keep the same database connection across several statements. Transaction pooling does not preserve that connection between transactions, so a temporary table or session setting is not a durable application store.
2. Run a small connection check
Save this standalone script as connection-check.ts and run it with Bun from the environment where DATABASE_URL is available. It reads no customer table and prints no connection string.
import { SQL } from "bun";
const url = process.env.DATABASE_URL;
if (!url) throw new Error("Set DATABASE_URL for a development database");
const sql = new SQL({ url, max: 1, idleTimeout: 10, prepare: false });
try {
const rows = await sql`
SELECT ${"connection-check"}::text AS label, ${7}::integer AS value
`;
console.log(JSON.stringify(rows));
} finally {
await sql.close();
}bun connection-check.tsThe query returns:
[{"label":"connection-check","value":7}]prepare: false stops the client from saving reusable statements by name on a database connection, which can be unsuitable when connections are shared. Keep this setting for the pooled connection shown here. Values written as ${...} in the tagged template are still sent separately as query parameters. max: 1 is a starting limit for this check, not a throughput recommendation for every application.
3. Reuse the client and test real queries
Create one client for a running application instance rather than opening a fresh pool for every request. Test your actual queries, transactions and data types against a development database. A successful connection check does not prove that a migration has created the app's tables.
Apply schema changes through your migration workflow. Use tagged-template parameters for values and trusted, reviewed identifiers for table or column choices. An AI assistant should not turn user input into arbitrary SQL.
4. Deploy with the same connection rules
To host the app on Compute, first complete Composer getting started for the service files, build command and deploy configuration. Composer is the framework that describes which server and database to create. Its database guide shows how to add db: rawPostgres() under the service's deps, and create and connect that database in module.ts.
In that app's server file, import its service configuration and use the supplied database URL:
import { SQL } from "bun";
import service from "./service.ts";
const { db } = service.load();
const sql = new SQL({ url: db.url, max: 1, idleTimeout: 10, prepare: false });The database created by the module is a new deployment resource; it does not reuse the Console database from step 1. Keep that first database for the standalone development check. Apply migrations separately to every new deployment database, using that database's direct connection before testing or serving application queries. rawPostgres() supplies the connection but does not apply migrations. Migrating the Console development database in step 3 does not prepare review or production databases. This is an integration excerpt for the configured service, not another standalone script. service.load() reads the connections supplied to that service, and db.url is its PostgreSQL URL. Keep this client for the instance's lifetime. A manually supplied URL instead follows the schema, binding and server-side read steps in Service input.
Build and test in an isolated review environment using a separate database. For first production deployment with rawPostgres(), provision the database with customer traffic disabled, obtain its direct connection and apply migrations before serving application queries. For an existing production database, apply reviewed migrations before the app release. Verify the production database identity, schema, pool configuration and backup plan before enabling customers. Review errors and query behavior after release rather than treating a larger pool as the automatic fix for latency.
When should I choose another approach?
Bun's native client requires a Bun runtime. If the app runs in a different runtime, choose a client that the host supports or move the server to a compatible host. Check Compute's runtime limits for the rest of the app's dependencies.
If your workload relies on long-lived session state, compare a direct connection against its connection limits. Prisma Postgres also has no point-in-time recovery yet (it is coming in November 2026); a requirement to restore to a specific moment should decide the database provider before client-library preference does.
Frequently asked questions
Keep Bun's SQL client
Create Prisma Postgres, copy its PostgreSQL connection URL into server-side configuration and test your existing queries.