User Hard-Delete Database Scripts

Database administrators can use the user hard-delete scripts to permanently delete a single user and the related data directly from the database. The scripts are available for MySQL, Oracle, and Microsoft SQL Server, and you run them manually.

On this page:

Overview

The scripts back up the user data before the deletion, so you can recover it if the results are not as expected. After the deletion, you verify the row counts and, if necessary, roll back. Drop the backup tables only after you verify the deletion and the rollback window is closed.

The workflow has the following stages:

  1. Identify the user: Run a query to get the USERID, related USERSID, distinguished name, and federation member ID of the user, and set the identifiers in the scripts.
  2. Back up: Copy all in-scope rows into temporary backup tables.
  3. Capture the before state: Execute the verify-counts script and save the output.
  4. Delete user data: Execute the delete script as one controlled operation.
  5. Verify the deletion: Execute the verify-counts script again. The counts for in-scope tables must be zero.
  6. Roll back, if necessary: Restore the backed-up rows and validate the restored counts.
  7. Clean up: Drop the backup tables after the deletion is verified and any rollback window is closed.

The scripts perform the following operations:

  • Backup: Copies the rows that belong to the user into temporary backup tables. Each backup table has the same name as its source table with the suffix _BKP, for example USERS_BKP. It uses the same user identifiers and conditions as the delete script, and includes rows that are removed only through cascading dependencies. The backup tables are the only recovery source until you drop them.
  • Verify counts: Reports the row count for every table in scope. For the list of tables, see Database tables affected by the scripts. You can run this script before and after the deletion, and save both outputs for comparison.
  • Delete: Removes the dependent rows and the user identity rows in an order that respects foreign keys. The script preserves the PM_USERS deletability check.
  • Rollback: Restores the rows from the backup tables. The script restores parent rows before child rows where required. Microsoft SQL Server might require IDENTITY_INSERT.
  • Cleanup: Drops the backup tables. Run this script only after the deletion is verified and the approved rollback window is closed.
Hard deletion permanently removes the user identity and the related data after you run the cleanup script. Cleanup also removes the only data that the rollback script can restore. Confirm the target user, the database platform, the backup results, and the rollback requirements before you run the delete script.

Prerequisites

Before you begin, ensure that you have the following:

  • Database access with privileges to create tables, read data, delete data, and drop tables in the platform database.
  • A SQL client that can run the scripts, such as mysql, SQL*Plus, or sqlcmd. For client tool installation paths, see Prerequisites in Database Cleanup Utility.
  • The target user, the target tenant, and the database platform (MySQL, Oracle, or Microsoft SQL Server).
  • The hard-delete scripts. Download the zip archive: hard_delete_user_db_cleanup_scripts.zip. The archive contains a script for each stage, for MySQL, Oracle, and Microsoft SQL Server. The script names use the format DeleteUser-<stage>-<platform>.sql, where <platform> is MySQL_Oracle for MySQL and Oracle, or MsSQL for Microsoft SQL Server. For example, DeleteUser-01-backup-MsSQL.sql.
  • No backup tables from a previous run exist in the database. The backup script fails if a table with the same name already exists. If such tables exist, confirm that you no longer need them as a recovery source before you drop them.

Hard-delete a user

To hard-delete a user, complete the following steps.

  1. Identify the user. Run the following query to get the USERID, related USERSID, distinguished name, and federation member ID of the user:
    Copy
    SELECT
        u.USERID          AS user_id,     -- = DISTINGUISHED_NAMES.NAMEID
        u.USERSID         AS user_sid,    -- = PM_USERS.USERSID (NULL if no PM link)
        dn.RDN            AS rdn,
        dn.FEDMEMBERID    AS fedmemberid
    FROM USERS u
    JOIN DISTINGUISHED_NAMES dn ON dn.NAMEID = u.USERID
    WHERE dn.RDN = '<user fdn>'
      AND dn.FEDMEMBERID = '<fed member id>';

    Replace:

    • <user fdn> with the distinguished name of the target user, which is stored in the RDN column.
    • <fed member id> with the federation member ID of the user.
  2. Set the identifiers in the backup, verify-counts, and delete scripts. The rollback and cleanup scripts do not use the identifiers.
    • For MySQL, set @user_id and @user_sid by using SET statements.
    • For Microsoft SQL Server, set @user_id and @user_sid in the DECLARE statements. To leave @user_sid empty, use NULL.
    • For Oracle, follow the instructions in the script header to replace the SET block with DEFINE statements and use the &user_id and &user_sid references.
  3. Run the backup script and review the backup-table row counts to confirm that the backup tables contain the expected rows.
  4. Run the verify-counts script and save the output. This output is the baseline for the deletion and for an optional rollback.
  5. Run the delete script. The script runs as one transaction, so an error stops the script and the deletion is not applied.
  6. Run the verify-counts script again and compare the output with the baseline. The row counts for all tables in scope must be zero, except for tables that are intentionally out of scope. See Limitations and Database tables affected by the scripts.

    If any count is not zero, investigate the cause before you continue. To revert the deletion, see Roll back the deletion.

Roll back the deletion

Roll back the deletion if validation fails or if you must revert the operation. You can run the rollback script at any time after the backup and before you run the cleanup script.

On Microsoft SQL Server, check which tables have IDENTITY columns before you run the rollback script. Inserts into those tables require SET IDENTITY_INSERT <table> ON and SET IDENTITY_INSERT <table> OFF.
  1. Run the rollback script for your platform. If the pre-check shows that a backup table is missing, stop. An error stops the script and no data is restored.
  2. Confirm that the last line of the output is ROLLBACK COMPLETE.
  3. Run the verify-counts script and confirm that the counts match the baseline that you saved before the deletion.

Drop the backup tables

After you verify the deletion, the rollback window is closed, and you have final approval, run the cleanup script for your platform. The script uses DROP TABLE statements to drop the backup tables.

Do not run the cleanup script immediately after the deletion if you might need to roll back. The cleanup script drops the backup tables that the rollback script uses as the recovery source.

Database tables affected by the scripts

The backup, verify-counts, delete, and rollback scripts process the following tables. The verify-counts script reports the row count for each table. Each backup table has the name of its source table with the suffix _BKP.

Table Name Description
BOARD_ITEM_ARTIFACTS Board item artifacts that belong to the user.
BOARD_ITEM_ASSIGNMENTS Board item assignments to the user, and assignments on board items that the user authored.
BOARD_ITEMS Board items that the user authored.
COMMENT_MARKS Marks that the user added to comments.
COMMENTS Comments that the user authored.
DXRESOURCEIMAGES Resource images that belong to the user.
FOLLOWINGS Follow relationships in which the user follows or is followed.
GROUP_MEMBERSHIP_REQUESTS Requests that belong to the user's group memberships.
GROUP_MEMBERSHIPS Group memberships of the user.
IDENTITYSET_USERS Identity set memberships of the user.
ITEM_MARKS Marks that the user added to items.
OPTED_NOTIFICATIONS Notification subscriptions of the user.
ORGANIZATION_IDENTITIES Organization identities of the user.
PASSWORD_HISTORY Password history of the user.
PM_GROUPSUSERS Group memberships of the user in Policy Manager.
PM_LARGEDATA Large data records that belong to the user's PKI keys.
PM_LARGEDATAVALUES Large data values that belong to the user's PKI keys.
PM_PKIKEYS PKI keys of the user.
PM_USERS Policy Manager user record. The delete script removes this row only if ISDELETABLE = 'Y'.
PM_VAULT Vault entries that the user created or that were created for the user.
PM_VAULTVALUES Values of the vault entries that belong to the user.
RESOURCE_RATING Ratings that the user submitted.
RESOURCEIMAGES Avatar image of the user.
SERVICE_IDENTITIES Service identities of the user.
USER_AGREEMENTS Agreement records of the user.
USER_AUTH_TOKEN Authentication tokens of the user.
USER_INFO_CLAIMS User info claims of the user.
USER_NOTIFICATION_DELIVERY Notification delivery records of the user.
USER_NOTIFICATIONS Notifications of the user.
USER_PREFERENCES Preferences of the user.
USER_SCOPEDROLE Scoped role assignments of the user.
USER_TECHNOLOGIES Technologies that are associated with the user.
USER_TOP_APIS Top APIs of the user.
USERCHALLENGE Challenge records of the user.
USERS User identity row in the developer portal.
USERS_PHONE Phone numbers of the user.
VISIBILITY_RELATIONSHIPS Visibility relationships in which the user is the viewer.
VISIBILITY_SCOPE Visibility scope entries in which the user is the viewer.
WORKFLOW_COMMENT Workflow comments on the comments that the user authored.
WORKFLOW_DN Workflow records of the user.

Limitations

  • Run the scripts for one user at a time. Run the cleanup script for one user before you run the backup script for the next user.
  • The delete script removes the PM_USERS row only if ISDELETABLE = 'Y'. If the row is not deletable, the verify-counts output still shows it after the deletion.
  • The scripts do not delete the user row in DISTINGUISHED_NAMES. The row remains with DELETED = 'N', and the verify-counts script does not report this table.