PostgreSQL is a powerful open-source relational database. Better Auth uses Kysely under the hood for PostgreSQL, which means any database Kysely supports is also supported.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/better-auth/better-auth/llms.txt
Use this file to discover all available pages before exploring further.
Installation
Schema generation and migration
The Better Auth CLI can both generate the schema and apply migrations directly against your PostgreSQL database.- migrate
- generate
| Command | Supported |
|---|---|
npx auth@latest generate | Yes |
npx auth@latest migrate | Yes |
Connection pooling
Usepg.Pool (not pg.Client) so that Better Auth can reuse connections across requests. Configure pool size based on your workload:
auth.ts
Using a non-default schema
By default Better Auth creates tables in thepublic schema. To use a different schema (e.g. auth), you have three options.
Option 1: Set search_path in the connection string (recommended)
auth.ts
?options=-c%20search_path%3Dauth.
Option 2: Set search_path in Pool options
auth.ts
Option 3: Set the default schema for the database user
Prerequisites for a non-default schema
Before using a custom schema, make sure it exists and your user has the necessary permissions:When running
npx auth migrate, the CLI automatically detects your configured search_path and creates tables in the correct schema. Tables in other schemas are ignored.Experimental joins
Enabling joins allows Better Auth to use SQLJOIN clauses to fetch related data in a single query instead of multiple round-trips. Endpoints such as /get-session and /get-full-organization see 2-3x latency improvements with high-latency databases.
auth.ts