> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cockroachlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# DROP PROVISIONED ROLES

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

The `DROP PROVISIONED ROLES` <InternalLink path="sql-statements">statement</InternalLink> bulk-drops <InternalLink path="ldap-authentication#option-1-automatic-user-provisioning-recommended">auto-provisioned</InternalLink> SQL users that match a set of filter criteria. It is designed to simplify de-provisioning of dormant or removed users that were automatically created through <InternalLink path="ldap-authentication">LDAP</InternalLink>, <InternalLink path="sso-db-console">OIDC</InternalLink>, or <InternalLink path="sso-sql">JWT</InternalLink> authentication.

Only users that have a <InternalLink path="create-user#role-options">`PROVISIONSRC`</InternalLink> role option (set automatically during provisioning) are candidates for removal. Users created with <InternalLink path="create-user">`CREATE USER`</InternalLink> or <InternalLink path="create-role">`CREATE ROLE`</InternalLink> are never affected, and the <InternalLink path="drop-role">`DROP ROLE`</InternalLink> and <InternalLink path="drop-user">`DROP USER`</InternalLink> statements are unchanged by this statement.

## Considerations

* The `LIMIT` clause is **required**. It must be a constant integer between `1` and `1024`. This is a safety guard that prevents accidentally dropping an unbounded number of provisioned users in a single transaction. To remove more provisioned users than the maximum, run the statement repeatedly.
* Only provisioned users (users with a `PROVISIONSRC` role option) are dropped. Non-provisioned users are never affected, even if they match the filter criteria.
* The `root` and `admin` users are never dropped.
* Provisioned users that <InternalLink path="security-reference/authorization#object-ownership">own objects</InternalLink> (such as databases, tables, schemas, or types) or have other dependencies (direct privilege grants, <InternalLink path="security-reference/authorization#supported-privileges">system privileges</InternalLink>, <InternalLink path="alter-default-privileges">default privileges</InternalLink>, <InternalLink path="row-level-security">row-level security</InternalLink> policies, or ownership of scheduled jobs) are skipped rather than dropped. No error is returned for skipped users. Transfer ownership or revoke privileges before dropping these users.
* If the user running the statement is not a member of the `admin` role, any provisioned users that are members of `admin` are skipped. (This differs from <InternalLink path="drop-role">`DROP ROLE`</InternalLink>, which returns an error when a non-admin attempts to drop an admin user.)
* When a provisioned user is dropped, its role memberships are removed and any active <InternalLink path="ui-overview#authentication">web</InternalLink> <InternalLink path="cockroach-auth-session">sessions</InternalLink> are revoked.
* Each dropped user is recorded in the <InternalLink path="logging#user_admin">`USER_ADMIN`</InternalLink> logging channel, which you can use for auditing de-provisioning operations.

## Required privileges

To drop provisioned roles, the user must be a member of the `admin` role or have the <InternalLink path="create-role#create-a-role-that-can-create-other-roles-and-manage-authentication-methods-for-the-new-roles">`CREATEROLE`</InternalLink> role option.

## Synopsis

<img src="https://mintcdn.com/cockroachlabs/tSevpJBx33puNhBx/images/sql-diagrams/v26.3/drop_provisioned_roles.svg?fit=max&auto=format&n=tSevpJBx33puNhBx&q=85&s=fd0e2f335127557df16ad5644eb0c15e" alt="drop_provisioned_roles syntax diagram" style={{maxWidth: "100%", overflowX: "auto"}} width="719" height="207" data-path="images/sql-diagrams/v26.3/drop_provisioned_roles.svg" />

## Parameters

| Parameter                       | Description                                                                                                                                                                                                                                                                 |
| ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `SOURCE = <string>`             | Filter users by their provisioning source. Only users whose <InternalLink path="create-user#role-options">`PROVISIONSRC`</InternalLink> role option exactly matches the full string are dropped. For example, `'ldap:ldap.example.com'`. Pattern matching is not supported. |
| `LAST LOGIN BEFORE <timestamp>` | Filter users whose `estimated_last_login_time` is before the specified timestamp. Users who have never logged in (`NULL` value) are also dropped.                                                                                                                           |
| `LIMIT <n>`                     | **Required.** The maximum number of provisioned users to drop, as a constant integer between `1` and `1024`.                                                                                                                                                                |

When you specify more than one `WITH` option, separate the options with commas. Only users matching **all** specified options are dropped.

## Examples

The following examples assume that the user running each statement has the `admin` role or the `CREATEROLE` role option. Use <InternalLink path="show-users">`SHOW USERS`</InternalLink> with the same filter clauses to preview which users would be dropped before running `DROP PROVISIONED ROLES`.

### Drop provisioned users from a specific source

To drop up to 100 users that were provisioned by a specific <InternalLink path="ldap-authentication">LDAP</InternalLink> server:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> DROP PROVISIONED ROLES WITH SOURCE = 'ldap:ldap.example.com' LIMIT 100;
```

### Drop dormant provisioned users

To drop up to 100 provisioned users that have not logged in since a specific date:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> DROP PROVISIONED ROLES WITH LAST LOGIN BEFORE '2025-01-01' LIMIT 100;
```

<Note>
  Users who have never logged in (`NULL` `estimated_last_login_time`) are also dropped by `LAST LOGIN BEFORE`.
</Note>

### Combine filters

To drop up to 100 users that were provisioned by a specific source **and** have not logged in since a specific date:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> DROP PROVISIONED ROLES WITH SOURCE = 'oidc:okta.corp.com', LAST LOGIN BEFORE '2025-01-01' LIMIT 100;
```

## See also

* <InternalLink path="ldap-authentication">LDAP Authentication</InternalLink>
* <InternalLink path="show-users">`SHOW USERS`</InternalLink>
* <InternalLink path="show-roles">`SHOW ROLES`</InternalLink>
* <InternalLink path="drop-role">`DROP ROLE`</InternalLink>
* <InternalLink path="drop-user">`DROP USER`</InternalLink>
* <InternalLink path="create-user">`CREATE USER`</InternalLink>
* <InternalLink path="security-reference/authorization#create-and-manage-users">Manage Users</InternalLink>
* <InternalLink path="sql-statements">SQL Statements</InternalLink>
