[GH-ISSUE #4452] how to tell better-auth with pg to use different schema than public? #9934

Closed
opened 2026-04-13 05:45:43 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @hp8wvvvgnj6asjm7 on GitHub (Sep 5, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4452

Maybe add this answer in docs. Helped me a lot!

Solution: PGOPTIONS="-c search_path=schemaname"

https://www.answeroverflow.com/m/1348852299795271700

Originally created by @hp8wvvvgnj6asjm7 on GitHub (Sep 5, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4452 Maybe add this answer in docs. Helped me a lot! Solution: PGOPTIONS="-c search_path=schemaname" https://www.answeroverflow.com/m/1348852299795271700
GiteaMirror added the locked label 2026-04-13 05:45:43 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 5, 2025):

To use a different PostgreSQL schema with better-auth, you can specify the schema in your adapter configuration.

For the Drizzle adapter, pass the schema property when you set up the adapter, like this:

database: drizzleAdapter(db, {
  provider: 'pg',
  schema: 'your_schema_name',
})

This tells better-auth to use the specified schema instead of the default public schema. Make sure the schema exists and your database user has the necessary permissions. Reference

If you're using the Prisma adapter, schema selection is handled in your Prisma schema file using model-level annotations. For example:

model User {
  // ...
  @@map("User")
  @@schema("your_schema_name")
}

After updating your Prisma schema, run npx prisma generate to update your client. Reference

No extra undocumented requirements were found—just ensure your schema and permissions are set up in PostgreSQL.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

<!-- gh-comment-id:3257344797 --> @dosubot[bot] commented on GitHub (Sep 5, 2025): <!-- Answer --> To use a different PostgreSQL schema with better-auth, you can specify the schema in your adapter configuration. For the Drizzle adapter, pass the `schema` property when you set up the adapter, like this: ```ts database: drizzleAdapter(db, { provider: 'pg', schema: 'your_schema_name', }) ``` This tells better-auth to use the specified schema instead of the default `public` schema. Make sure the schema exists and your database user has the necessary permissions. [Reference](https://github.com/better-auth/better-auth/issues/4188) If you're using the Prisma adapter, schema selection is handled in your Prisma schema file using model-level annotations. For example: ```prisma model User { // ... @@map("User") @@schema("your_schema_name") } ``` After updating your Prisma schema, run `npx prisma generate` to update your client. [Reference](https://app.dosu.dev/documents/dfca922a-f368-4b8d-b16c-99433641e9a0) No extra undocumented requirements were found—just ensure your schema and permissions are set up in PostgreSQL. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/1a6c7ccf-4dc1-49b5-975c-7dc8dfacfd02?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/1a6c7ccf-4dc1-49b5-975c-7dc8dfacfd02?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/1a6c7ccf-4dc1-49b5-975c-7dc8dfacfd02?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/1a6c7ccf-4dc1-49b5-975c-7dc8dfacfd02?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/1a6c7ccf-4dc1-49b5-975c-7dc8dfacfd02?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/1a6c7ccf-4dc1-49b5-975c-7dc8dfacfd02?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/1a6c7ccf-4dc1-49b5-975c-7dc8dfacfd02?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4452)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9934