Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

adds some docs on postgres roles, cleans up the Self-hosting section

Copple4defada6a722
diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
index 37803d4823b..0ae5226d020 100644
--- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
+++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts
@@ -556,19 +556,20 @@ export const database: NavMenuConstant = {
name: 'Postgres Guides',
url: undefined,
items: [
- {
- name: 'Analyzing efficiency and performance',
- url: '/guides/database/inspect',
- },
{
name: 'JSON and unstructured data',
url: '/guides/database/json',
},
- { name: 'Implementing Full Text Search', url: '/guides/database/full-text-search' },
+ { name: 'Using Full Text Search', url: '/guides/database/full-text-search' },
{ name: 'Implementing Cascade Deletes', url: '/guides/database/postgres/cascade-deletes' },
- { name: 'Implementing column encryption', url: '/guides/database/column-encryption' },
- { name: 'Partitioning your tables', url: '/guides/database/partitions' },
{ name: 'Query Optimization', url: '/guides/database/query-optimization' },
+ {
+ name: 'Analyzing efficiency and performance',
+ url: '/guides/database/inspect',
+ },
+ { name: 'Managing Postgres Roles', url: '/guides/database/postgres-roles' },
+ { name: 'Partitioning your tables', url: '/guides/database/partitions' },
+ { name: 'Implementing column encryption', url: '/guides/database/column-encryption' },
{ name: 'Testing your database', url: '/guides/database/testing' },
{ name: 'Managing Timeouts', url: '/guides/database/timeouts' },
{ name: 'Managing Passwords', url: '/guides/database/managing-passwords' },
diff --git a/apps/docs/pages/guides/database/postgres-roles.mdx b/apps/docs/pages/guides/database/postgres-roles.mdx
new file mode 100644
index 00000000000..b2e68cc7165
--- /dev/null
+++ b/apps/docs/pages/guides/database/postgres-roles.mdx
@@ -0,0 +1,109 @@
+import Layout from '~/layouts/DefaultGuideLayout'
+
+export const meta = {
+ id: 'postgres-roles',
+ title: 'Postgres Roles',
+ description: 'Managing access to your Postgres database and configuring permissions.',
+ subtitle: 'Managing access to your Postgres database and configuring permissions.',
+}
+
+PostgreSQL manages database access permissions using the concept of roles. Generally you wouldn't use these roles for your own application - they are mostly for configuring _system access_ to your database. If you want to confgure _application access_, then you should use Row Level Security (although in some cases, you can mix RLS and Postgres Roles to build an extremely powerful Auth system).
+
+## Users vs Roles
+
+In PostgreSQL, roles can function as users or groups of users. Users are roles with login privileges, while groups (also known as role groups) are roles that don't have login privileges but can be used to manage permissions for multiple users.
+
+## Superuser Roles
+
+The superuser role has unrestricted access to the database system. Typically these roles will be able to bypass all security measures (like Row Level Security). Be cautious when granting superuser privileges as it can potentially lead to security risks.
+
+## Creating Roles
+
+You can create a role using the `create role` command:
+
+```sql
+create role "role_name";
+```
+
+## Granting Permissions
+
+Roles can be granted various permissions on database objects using the `GRANT` command. Permissions include `SELECT`, `INSERT`, `UPDATE`, and `DELETE`. You can configure access to almost any object inside your database - including tables, views, functions, and triggers.
+
+## Revoking Permissions
+
+Permissions can be revoked using the `REVOKE` command:
+
+```sql
+REVOKE permission_type ON object_name FROM role_name;
+```
+
+## Role Hierarchy
+
+Roles can be organized in a hierarchy, where one role can inherit permissions from another. This simplifies permission management, as you can define permissions at a higher level and have them automatically apply to all child roles.
+
+### Role inheritance
+
+To create a role hierarchy, you first need to create the parent and child roles. The child role will inherit permissions from its parent. Child roles can be added using the INHERIT option when creating the role:
+
+```sql
+create role "child_role_name" inherit "parent_role_name";
+```
+
+### Preventing inheritance
+
+In some cases, you might want to prevent a role from having a child relationship (typically superuser roles). You can prevent inheritance relations using NOINHERIT:
+
+```sql
+alter role "child_role_name" noinherit;
+```
+
+## Supabase Roles
+
+Postgres comes with a set of [predefined roles](https://www.postgresql.org/docs/current/predefined-roles.html). Supabase extends this with a default set of roles which are configured on your database when you start a new project:
+
+### `postgres`
+
+The default Postgres role. This has admin privileges.
+
+### `anon`
+
+For "anonymous access". This is the role which the API (PostgREST) will use when a user _is not_ logged in.
+
+### `authenticator`
+
+A special role for the API (PostgREST). It has very limited access, and is used to validate a JWT and then
+"change into" another role determined by the JWT verification.
+
+### `authenticated`
+
+For "authenticated access". This is the role which the API (PostgREST) will use when a user _is_ logged in.
+
+### `service_role`
+
+For elevated access. This role is used by the API (PostgREST) to bypass Row Level Security.
+
+### `supabase_auth_admin`
+
+Used by the Auth middleware to connect to the database and run migration. Access is scoped to the `auth` schema.
+
+### `supabase_storage_admin`
+
+Used by the Auth middleware to connect to the database and run migration. Access is scoped to the `storage` schema.
+
+### `dashboard_user`
+
+For running commands via the Supabase UI.
+
+### `supabase_admin`
+
+Supabase Administrative role for maintaining your database.
+
+## Resources
+
+- Official Postgres docs: [Database Roles](https://www.postgresql.org/docs/current/database-roles.html)
+- Official Postgres docs: [Role Membership](https://www.postgresql.org/docs/current/role-membership.html)
+- Official Postgres docs: [Function Permissions](https://www.postgresql.org/docs/current/perm-functions.html)
+
+export const Page = ({ children }) => <Layout meta={meta} children={children} />
+
+export default Page
diff --git a/apps/docs/pages/guides/self-hosting.mdx b/apps/docs/pages/guides/self-hosting.mdx
index aadf096723b..1ad426b229b 100644
--- a/apps/docs/pages/guides/self-hosting.mdx
+++ b/apps/docs/pages/guides/self-hosting.mdx
@@ -138,46 +138,7 @@ For working with JWT and Auth functions.
### Roles
-Supabase creates several default roles in your Postgres database. To restore defaults at any time you can run the commands inside the
-[schema initialization scripts](https://github.com/supabase/postgres/tree/develop/migrations/db/init-scripts). Remember to change your
-[role passwords](/docs/guides/self-hosting/docker#securing-your-setup) before deploying to production environments.
-
-##### `postgres`
-
-The default PostgreSQL role. This has admin privileges.
-
-##### `anon`
-
-For "anonymous access". This is the role which the API (PostgREST) will use when a user _is not_ logged in.
-
-##### `authenticator`
-
-A special role for the API (PostgREST). It has very limited access, and is used to validate a JWT and then
-"change into" another role determined by the JWT verification.
-
-##### `authenticated`
-
-For "authenticated access". This is the role which the API (PostgREST) will use when a user _is_ logged in.
-
-##### `service_role`
-
-For elevated access. This role is used by the API (PostgREST) to bypass Row Level Security.
-
-##### `supabase_auth_admin`
-
-Used by the Auth middleware to connect to the database and run migration. Access is scoped to the `auth` schema.
-
-##### `supabase_storage_admin`
-
-Used by the Auth middleware to connect to the database and run migration. Access is scoped to the `storage` schema.
-
-##### `dashboard_user`
-
-For running commands via the Supabase UI.
-
-##### `supabase_admin`
-
-Supabase Administrative role for maintaining your database.
+Supabase creates several [default roles](/docs/guides/database/postgres-roles) in your Postgres database. To restore defaults at any time you can run the commands inside the [schema initialization scripts](https://github.com/supabase/postgres/tree/develop/migrations/db/init-scripts). Remember to change your [role passwords](/docs/guides/self-hosting/docker#securing-your-setup) before deploying to production environments.
### Realtime Logs