Renaming a PostgreSQL database
You may need to rename a PostgreSQL database when migrating data, restructuring accounts, or during site development. On ruachost.com, the steps depend on whether your hosting account includes cPanel access or is an unmanaged account.
Why Rename a Database?
Section titled “Why Rename a Database?”- Align database names with new projects or applications.
- Standardize naming conventions across multiple environments.
- Simplify migrations between accounts or hosting providers.
Steps to Rename a PostgreSQL Database
Section titled “Steps to Rename a PostgreSQL Database”Managed Accounts with cPanel
Section titled “Managed Accounts with cPanel”If your ruachost.com account includes cPanel access, you can rename a PostgreSQL database directly from the cPanel interface:
- Log in to cPanel.
- In the DATABASES section, click PostgreSQL Databases.
- Under Current Databases, locate the database you want to rename.
- In the Actions column, click Rename.
- Enter the new name in the dialog box.
- Click Proceed.
- cPanel renames the database automatically.
Unmanaged Accounts without cPanel
Section titled “Unmanaged Accounts without cPanel”If your account does not include cPanel, you can rename a PostgreSQL database from the command line:
-
Log in to your server using SSH.
-
At the command prompt, connect to PostgreSQL using a database other than the one you want to rename:
Terminal window psql dbname username⚠️ Important: You cannot rename a database while connected to it.
-
Run the following SQL command:
ALTER DATABASE "old_dbname" RENAME TO "new_dbname"; -
Verify the rename by listing databases:
Terminal window \list