You cannot change the name of a database that you are currently connected to. To rename a database, login as a superuser or the database owner with CREATEDB privilege. Below is the command to rename a database where current_db_name is the name of the database and new_db_name is the new name.
ALTER DATABASE current_db_name RENAME TO new_db_name;