Database token access
Database token access is in public alpha and must be enabled as a feature preview.
Database token access lets team members, approved OAuth apps, and automated jobs connect to your project's Postgres database with a short-lived access token instead of the database password.
It covers direct Postgres connections and connections through the shared pooler (Supavisor). Supabase HTTP APIs such as the Data API (PostgREST), Storage, and Auth use their own keys and don't accept these tokens.
Prerequisites
- Turn on SSL enforcement.
- Upgrade the project to Postgres 17.6.1.081 or later. The General Settings page shows your version. To upgrade, see Upgrading.
Turning database token access on or off closes every token and password connection through the shared pooler but leaves direct connections open.
Tokens you can connect with
Each of these tokens works as a database password. Unless the table says otherwise, the token's owner also needs a member access rule for the role they connect as.
| Token | Where it comes from | What it needs |
|---|---|---|
| Personal access token | The Access Tokens page in the Supabase Dashboard or the CLI's supabase login command | A token with full access works as it is. A scoped token needs at least Read only on the Database token access permission for the project. |
| OAuth access token | An OAuth app a user authorized | The app needs the database:read scope. Supabase must also approve the app for database token access. A Trusted Partner app connects only as its own role and doesn't need a member access rule. |
| Vercel resource token | A Vercel project connected through the Vercel Marketplace | No member access rule. The token must be minted for the postgres or supabase_read_only_user role it connects as. |
Every organization and project role, Read-only included, can connect with a token.
Turn on database token access
After you turn it on, add a member access rule for each team member.
In the dashboard
- Open the Database token access feature preview and click Enable feature.
- Go to Database Settings > Database access and turn on Token access.
With the Management API
Use a personal access token. A scoped token needs Project settings with Read only access to check the status and Read and write access to turn the feature on or off.
# Get your access token from https://supabase.com/dashboard/account/tokensexport SUPABASE_MANAGEMENT_API_TOKEN="YOUR_ACCESS_TOKEN"export PROJECT_REF="YOUR_PROJECT_REF"# Get the current database token access statuscurl -X GET "https://api.supabase.com/v1/projects/$PROJECT_REF/jit-access" \ -H "Authorization: Bearer $SUPABASE_MANAGEMENT_API_TOKEN"# Turn on database token accesscurl -X PUT "https://api.supabase.com/v1/projects/$PROJECT_REF/jit-access" \ -H "Authorization: Bearer $SUPABASE_MANAGEMENT_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "state":"enabled" }'# Turn off database token accesscurl -X PUT "https://api.supabase.com/v1/projects/$PROJECT_REF/jit-access" \ -H "Authorization: Bearer $SUPABASE_MANAGEMENT_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "state":"disabled" }'For the full request and response details, see the API reference:
Connect with database token access
Database token access doesn't work with the dedicated pooler.
To connect, take a direct or shared pooler connection string, replace the password with your token, and use a role your member access rule allows as the user. For example, a team member mapped to the postgres role connects like this:
psql 'postgres://postgres:sbp_111222333aaabbbccc@db.YOUR_PROJECT_REF.supabase.co/postgres'Because a personal access token works as a password, a service such as a GitHub Action can connect with its own scoped token instead of the database password. The service uses the member access rule of the team member who creates the token. You can give the token an expiry and limit the rule by expiry and network.
Shared pooler connections require SSL and the jit=true option. The pooler reads jit=true to choose token authentication and doesn't pass it to Postgres. Don't include it for direct connections because Postgres treats it as its own jit setting and turns on JIT compilation. For pooler connections, add it to the URI or use the conninfo form:
# directly in the URIpsql 'postgres://postgres.YOUR_PROJECT_REF:sbp_111222333aaabbbccc@aws-1-us-west-1.pooler.supabase.com:5432/postgres?options=-c%20jit%3dtrue&sslmode=require'# or as a connection info stringpsql "host=aws-1-us-west-1.pooler.supabase.com dbname=postgres user=postgres.YOUR_PROJECT_REF sslmode=require options='-c jit=true'"Connect to preview branches and read replicas
Database token access and member access rules live on the main project. They apply to all of its preview branches and healthy read replicas. Turning token access on or off for the main project does the same for each of them. To connect, use the branch's or replica's connection string with the same token.
To limit a role to preview branches, see Restrict a team member's access.
End access that's already in use
Database token access checks a token only when a connection opens. These changes block new connections but leave open ones running:
- Removing a member access rule or changing its roles
- A role's expiry passing
- The access token expiring or being revoked
Revoking a Trusted Partner app also closes the app's open connections. See OAuth apps with database token access.
A change to a member access rule can take several seconds to reach new connections.
The shared pooler in transaction mode is the exception. After one of these changes it can disconnect clients, including team members whose access hasn't changed. See Authentication credentials are invalid for the cause and the fix.
To end an open direct connection, terminate it in Postgres. Several people can connect as the same role because a member access rule doesn't create a role for each team member. Find a team member's sessions by the network address they connect from rather than by role.
Run the following SQL using the SQL Editor in the Supabase Dashboard or with psql over a direct connection. To connect with psql, see Direct connection.
-- Find the sessions from the team member's addressselect pid, usename, client_addr, backend_startfrom pg_stat_activitywhere client_addr = '203.0.113.10';-- Terminate themselect pg_terminate_backend(pid)from pg_stat_activitywhere client_addr = '203.0.113.10' and pid <> pg_backend_pid();Replace 203.0.113.10 with the team member's address. Check the sessions the first query returns before you terminate them, since team members on the same network can share an address. Because shared pooler connections show the pooler's address in pg_stat_activity, you can't single out one team member's pooler connections this way.
Troubleshooting
SSL connection is required for user
The shared pooler accepts token connections only over SSL. Connect with sslmode=require or a stricter mode.
JIT authentication is not enabled for user
The connection sets jit=true while database token access is off for the project. The shared pooler can also report this case as password authentication failed. Turn token access on or connect with the role's password and without jit=true.
server requested a cleartext password
Your client accepts only SCRAM authentication, for example libpq with require_auth=scram-sha-256. Because database token access needs the token itself, Postgres and the shared pooler ask for it in cleartext over SSL. Remove the SCRAM-only setting from your connection string.
too many authentication failures
The shared pooler blocks an address for two minutes after 10 failed authentication attempts from it within 150 seconds. Rejected tokens and wrong passwords both count. Fix the failing credential and wait two minutes before you connect again.
password authentication failed or PAM authentication failed
The database rejected the token. Check that:
- The token's owner has a member access rule for the role in the connection string. Through the shared pooler, a missing rule shows as
failed to reach JIT provider for userinstead. - The role's expiry hasn't passed.
- You connect from an address in the role's allowed networks.
- The role isn't limited to preview branches while you connect to the main project.
- The token is still valid. A scoped personal access token also needs at least Read only on the Database token access permission. An OAuth app needs the
database:readscope and Supabase's approval. - Shared pooler connections include
jit=true. Without it, the pooler checks the token as a regular password.
Authentication credentials are invalid
The shared pooler closes an open transaction-mode connection with the error Authentication credentials are invalid. Please reconnect with fresh credentials to restore pool functionality.
In transaction mode, clients share a pool of database connections. The pooler opens each new database connection with the token from the most recent token connection. When that token stops working, the pooler can't open new database connections and disconnects clients. Because clients share the pool, you can see this error while your own token and member access rule are still valid.
A token stops working when its owner's member access rule is removed or no longer allows the role, the role's expiry passes, or the token expires or is revoked.
Reconnect with a valid token. The pooler then uses it to open new database connections.
failed to reach JIT provider for user
This error comes only from the shared pooler and starts with the code (EJITREQUESTFAILED). It means the pooler sent the token to Supabase for a check and didn't get an answer that allows or rejects the role. Check that:
- The token's owner has a member access rule on the project. When a person doesn't have any rule, the pooler shows this error instead of
password authentication failed. - You haven't opened too many token connections in a short time. By default, each user can open 120 token connections per minute to each project. Further connections fail until the minute is over.
If neither applies, retry the connection. The check might have failed for a temporary reason.
The dashboard says database token access is unavailable
Projects on a Postgres 17 version older than 17.6.1.081 can show this message instead of an upgrade prompt. Check your version on the General Settings page and upgrade the project if it's older.
Next steps
After token access is on, extend it to your team and your read replicas:
- Member access rules: create, restrict, and remove member access rules in the dashboard or with the Management API.
- Read replicas: add a replica that accepts the same tokens.
If you authorize an OAuth integration from a Trusted Partner, see OAuth apps with database token access to learn what the partner can access and how to revoke it.