From b0bb496977722bb1f7aae4d8e551a3b78e728600 Mon Sep 17 00:00:00 2001 From: "supabase-supabase-autofixer[bot]" <248690971+supabase-supabase-autofixer[bot]@users.noreply.github.com> Date: Mon, 21 Sep 2026 21:18:04 +0000 Subject: [PATCH] [bot] Sync from supabase/troubleshooting (#50656) This PR syncs the latest troubleshooting guides from the supabase/troubleshooting repository. --------- Co-authored-by: github-docs-bot Co-authored-by: Miranda Limonczenko Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- ...base-postgres-during-migrations-78f33a.mdx | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 apps/docs/content/troubleshooting/resolving-permission-denied-for-database-postgres-during-migrations-78f33a.mdx diff --git a/apps/docs/content/troubleshooting/resolving-permission-denied-for-database-postgres-during-migrations-78f33a.mdx b/apps/docs/content/troubleshooting/resolving-permission-denied-for-database-postgres-during-migrations-78f33a.mdx new file mode 100644 index 00000000000..4ced34e7193 --- /dev/null +++ b/apps/docs/content/troubleshooting/resolving-permission-denied-for-database-postgres-during-migrations-78f33a.mdx @@ -0,0 +1,29 @@ +--- +title = "Resolving 'permission denied for database postgres' during migrations" +date_created = "2026-09-21T12:04:07+00:00" +topics = [ "database" ] +keywords = [ "42501", "create schema", "set role", "migrations" ] +[[errors]] +code = "42501" +message = "permission denied for database postgres" +--- + +If you encounter a `permission denied for database postgres` error during migrations, it typically occurs when executing `CREATE SCHEMA` or similar commands after a `SET ROLE` statement. + +## Why this happens + +Postgres 15 and later versions remove default `CREATE` privileges from the `PUBLIC` role. This means custom roles do not automatically have permission to create objects in the database, even if the session was initiated by the `postgres` user. + +## How to resolve the issue + +To resolve this, you must grant the `CREATE` privilege on the database to the specific role used in your migration script. Run the following command in the [SQL editor](/dashboard/project/_/sql/new): + +```sql +GRANT CREATE ON DATABASE postgres TO example_role; +``` + +Replace `example_role` with the name of the role being assumed during the migration (for example, the owner role of your schemas). + +## Related + +If this happened via a REST/GraphQL request instead of a direct connection or migration script, see [Database API 42501 errors](/docs/guides/troubleshooting/database-api-42501-errors) instead — that guide covers a different set of causes specific to the Data API.