Doctl / Delete Database User
Delete Database User
Delete a database user in DigitalOcean's Databases service.
doctl databases user delete <database_id> <user_name> doctl databases user delete <database_id> <user_name> #!/bin/bash
# Delete Database User
doctl databases user delete {{database_id}} {{user_name}} import subprocess
# Delete Database User
# Make sure to replace <placeholders> with actual values
def run_command():
cmd = [
"doctl",
"databases",
"user",
"delete",
"<database_id>",
"<user_name>"
]
try:
print(f"Executing: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
except FileNotFoundError:
print("Error: doctl not found. Please install it first.")
if __name__ == "__main__":
run_command() When To Use
When a user accesses sensitive data incorrectly and needs removal.
Pro Tip
Add `--force` to bypass confirmation prompt for automated scripts.
Warning
Destructive operation. Confirm the target path and keep a backup before executing.
Command Builder
Tune the command before you copy it
doctl databases user delete <database_id> <user_name> Terminal Output
Expected runtime feedback
$ doctl databases user delete 12345 john_doe
User 'john_doe' deleted successfully from database '12345'.
$ doctl databases user list 12345
+-----------+----------+-----------------+
| User ID | Username | Role |
+-----------+----------+-----------------+
| 67890 | jane_doe | read-only |
+-----------+----------+-----------------+ Anatomy of Output
Understanding the result
User deleted: user_123456 Deleted User ID ID of the deleted user for confirmation.
Remaining users: 3 User Count Total users remaining after deletion.
Operation Status: success Operation Status Indicates successful execution.
Troubleshooting
Common pitfalls
Error deleting user: User not found.
Solution: Check that the username and database_id are correct.
Error: Cannot delete user with ongoing connections.
Solution: Ensure all connections for this user are closed.
Error: Insufficient permissions.
Solution: Verify the access token used has admin privileges.
Command Breakdown
What each part is doing
-
doctl - Base Command
- The executable that performs this operation. Here it runs Doctl before the shell applies any redirect operators.
-
<database_id> - database id
- The value supplied for database id.
-
<user_name> - user name
- The user value supplied to this command.
How To Run
Execution path
- Step 1
Run the command: `doctl databases user delete {{database_id}} {{user_name}}`
- Step 2
Verify deletion with: `doctl databases user list {{database_id}}`
Alternative Approaches
Comparable commands in other tools
Alternative documentation tools for the same job.