PostgreSQL Cheat Sheet/Rename database

Rename an existing database.

Section: Database and Role Lifecycle

Rename database

sql
sql
ALTER DATABASE appdb RENAME TO appdb_prod;
Explanation

Cannot rename the currently connected database.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Database and Role Lifecycle
Create database
Create a new database in the cluster.
OpenIn sheetsqlsame section
Create database with owner
Create a database with explicit owner and template.
OpenIn sheetsqlsame section
Drop database
Delete a database permanently.
OpenIn sheetsqlsame section
Create login role
Create a role that can log in.
OpenIn sheetsqlsame section
Create role with privileges
Create a role with explicit capability flags.
OpenIn sheetsqlsame section
Change role password
Update a role password.
OpenIn sheetsqlsame section