PostgreSQL Tutorial PostgreSQL Advanced PostgreSQL Database Account Management PostgreSQL References
PostgreSQL Tutorial PostgreSQL Advanced PostgreSQL Database Account Management PostgreSQL References

PostgreSQL - Rename a User



The PostgreSQL ALTER USER statement is used to rename a user in the PostgreSQL database. An error occurs if user_name do not exist or new_name already exist in the database.

Only a database superuser can rename user accounts. The current session user cannot be renamed. To rename the current session user, connect as a different user in the database and run the ALTER USER statement. Because MD5-encrypted passwords use the user name as cryptographic salt, renaming a user clears their MD5 password.

Syntax

The syntax to rename a user using ALTER USER statement in PostgreSQL is given below:

ALTER USER 
  user_name RENAME TO new_name;

Parameters

user_name Required. Specify the name of the user to rename in the PostgreSQL database.
new_name Required. Specify the new name to assign to the user_name.

Example: Rename a user

In the example below, the ALTER USER statement is used to rename a user called jeffrey to jeff in the PostgreSQL database.

ALTER USER 
  jeffrey RENAME TO jeff;