Skip to content

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.

  • Align database names with new projects or applications.
  • Standardize naming conventions across multiple environments.
  • Simplify migrations between accounts or hosting providers.

If your ruachost.com account includes cPanel access, you can rename a PostgreSQL database directly from the cPanel interface:

  1. Log in to cPanel.
  2. In the DATABASES section, click PostgreSQL Databases.
  3. Under Current Databases, locate the database you want to rename.
  4. In the Actions column, click Rename.
  5. Enter the new name in the dialog box.
  6. Click Proceed.
  7. cPanel renames the database automatically.

If your account does not include cPanel, you can rename a PostgreSQL database from the command line:

  1. Log in to your server using SSH.

  2. 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.

  3. Run the following SQL command:

    ALTER DATABASE "old_dbname" RENAME TO "new_dbname";
  4. Verify the rename by listing databases:

    Terminal window
    \list