How to rename a PostgreSQL database

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 A2 Hosting account includes cPanel access.

Managed accounts with cPanel

If your A2 Hosting 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.
    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 A2 Hosting 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
    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

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.