PostgreSQL – How to Rename a User
To rename a user in PostgreSQL, you can use the ALTER USER
statement. Here’s the basic syntax:
ALTER USER old_username RENAME TO new_username;
where old_username
is the current username you want to rename and new_username
is the new username you want to assign.
Below is an example:
ALTER USER myuser RENAME TO newuser;
This sql statement will rename the user “myuser” to “newuser.”
You typically need superuser or the appropriate permissions to rename a user. If the user owns database objects like tables or schemas, those objects will still be owned by the renamed user after the operation. You may need to adjust object ownership as needed.