How can I change the Database Name in AWS RDS for Postgresql?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
On Amazon RDS for PostgreSQL, changing a database name is a PostgreSQL operation, not an RDS console setting. The usual way is to run ALTER DATABASE ... RENAME TO ..., but you must do it from a different database, ensure no active connections remain on the target database, and then update any applications that still connect using the old name.
Use PostgreSQL's Rename Command
The SQL command itself is simple:
What makes the operation fail in practice is not the syntax, but the surrounding conditions. PostgreSQL will not rename a database while you are connected to that same database, and active sessions can block the rename too.
Connect to a Different Database First
If you want to rename appdb, connect to another database on the same RDS instance, such as postgres.
Example with psql:
Then run the rename command from that session:
That avoids the most common mistake, which is trying to rename the database you are currently using.
Remove Active Connections if Necessary
If other sessions are still connected to the database, PostgreSQL may refuse the rename. In that case, inspect active sessions:
Then terminate them if you have planned the change window:
After the active sessions are gone, retry the rename.
What Changes After the Rename
The RDS instance endpoint does not change. What changes is the database name portion of the connection string.
Before:
After:
That means the operational follow-up is just as important as the SQL command itself:
- Update application configuration
- Update migration jobs or admin scripts
- Update monitoring or backup references that include the old name
Ownership and Permissions Still Apply
RDS does not remove normal PostgreSQL privilege rules. The role performing the rename must still have the authority to rename that database. In many setups, the master user or another privileged administrative role handles the change during a maintenance window.
Plan the Rename Carefully
Even though the command is small, it is still a disruptive change for connected applications. In production, treat it like a short maintenance operation:
- Stop or drain application traffic
- Terminate remaining sessions if necessary
- Rename the database
- Update clients to use the new name
- Validate application connectivity
That sequence is usually much safer than trying to rename a live, heavily used database while clients are reconnecting continuously.
Common Pitfalls
- Trying to rename the database while connected to it is the most common failure mode.
- Forgetting active sessions can make the command appear mysteriously blocked or rejected.
- Assuming the RDS endpoint changes is incorrect; only the database name in the connection target changes.
- Renaming the database without updating app configuration leaves the database change technically successful but operationally broken.
Summary
- On RDS for PostgreSQL, rename the database with
ALTER DATABASE old_name RENAME TO new_name;. - Connect to a different database, such as
postgres, before you run the command. - Terminate active sessions on the target database if needed.
- Update every client connection string that still points at the old database name.

