Renaming a PostgreSQL database

Learn how to rename a PostgreSQL database on both managed and unmanaged cPanel accounts with this detailed guide including instructions, code snippets, and visual aids.

This article explains how to rename a PostgreSQL database.

Renaming a PostgreSQL database

You may need to rename a PostgreSQL database from time to time, such as when you migrate data from one account or hosting provider to another, or during site development.

The steps to rename a PostgreSQL database depend on whether or not your hosting.com account includes cPanel access.

Managed accounts with cPanel

If your hosting.com account includes cPanel access, you can use cPanel to quickly and easily rename a PostgreSQL database. To do this, follow these steps:

  1. Log in to cPanel.

    📘

    Note

    If you do not know how to log in to your cPanel account, please see this article.

  2. In the DATABASES section of the cPanel home screen, click PostgreSQL Databases:
    cPanel - PostgreSQL Databases icon

  3. Under Current Databases, locate the database you want to rename.

  4. In the Actions column, click Rename:
    cPanel - PostgreSQL Databases - Rename

    The Rename Database dialog box appears.

  5. In the New name text box, type the new name for the database:
    cPanel - PostgreSQL Databases - Rename dialog box

  6. Click Proceed. cPanel renames the database.

Unmanaged accounts without cPanel

If your hosting.com account does not include cPanel, you can quickly and easily rename a PostgreSQL database from the command line. To do this, follow these steps:

  1. Log in to your server using SSH.

  2. At the command prompt, type the following command to connect to PostgreSQL. Replace dbname with the name of a database that is not the database you want to rename, and replace username with a PostgreSQL username that has access privileges to the database:

    psql dbname username
    

    🚧

    Important

    You cannot rename a database while you are currently connected to it.

  3. To rename the database, type the following command. Replace old_dbname with the name of the database that you want to rename, and replace new_dbname with the database's new name:

    ALTER DATABASE "old_dbname" RENAME TO "new_dbname"
    
  4. To verify that the database was renamed, type the following command to list the databases:

    \list
    

Related Articles