dropuser
Remove a PostgreSQL user
TLDR
Prompt for confirmation and the username before user removal
Remove user instantly
No error if the user to be removed doesn't exist
Remove a user on the server with address 127.0.0.1 on port 4321
Remove a user on the server with address 127.0.0.1 on port 4321 as user "admin"
SYNOPSIS
dropuser [OPTION]... [ROLENAME]
PARAMETERS
-d DBNAME, --dbname=DBNAME
connect to database DBNAME (default: current user name)
-e, --echo
echo SQL commands before executing
-h HOSTNAME, --host=HOSTNAME
server host or socket directory (default: local socket)
--if-exists
skip error if role does not exist
-p PORT, --port=PORT
server port (default: 5432)
-r ROLE, --role=ROLE
connect using role ROLE (default: current user)
-s, --superuser
connect as superuser
-V, --version
print version and exit
-W, --password
force password prompt
-w, --no-password
never prompt for password
-?, --help
show help and exit
DESCRIPTION
dropuser is a PostgreSQL client utility for removing a specified database role (user). It connects to a PostgreSQL server and issues the SQL DROP ROLE command, synonymous with DROP USER. Ideal for script-based administration without a GUI.
By default, it uses the current system username for both database connection and role to drop, connecting via Unix socket to the default port (5432). Options customize connection details like host, port, username, and authentication. Superuser privileges are typically required, as non-superusers can only drop roles they own with no objects or grants.
Dropping fails if the role owns database objects, has privileges on objects, or active sessions exist. Use pg_terminate_backend() or revoke privileges first. Supports --if-exists to avoid errors for non-existent roles. Equivalent to running psql -c "DROP ROLE rolname".
Not a core Linux command; requires PostgreSQL installation. Man page in section 1.
CAVEATS
Requires superuser to drop non-owned roles, superusers, or roles with objects/grants/sessions. Fails silently on constraints unless superuser. Does not drop system users, only DB roles.
EXAMPLE
dropuser johnny
dropuser --host=localhost --port=5433 --username=postgres myuser
dropuser --if-exists nonexistent
PRIVILEGES
Role must own no objects and have no active backends; use REASSIGN OWNED and DROP OWNED first if needed.
HISTORY
Introduced in PostgreSQL 6.5 (1999); stable wrapper for DROP ROLE since 8.1 (2005). Maintained across versions with minor option additions like --if-exists in 9.2.
SEE ALSO
createuser(1), psql(1), dropdb(1), DROP ROLE(l)


