# Renaming a PostgreSQL database

> Rename a PostgreSQL database, with steps for accounts that have cPanel and for servers managed from the command line.

Source: https://helpcenter.ruachost.com/developers/databases/renaming-a-postgresql-database/

> **PostgreSQL is available on Managed VPS only:**
Ruachost shared hosting supports MySQL (MariaDB) databases, not PostgreSQL. To use PostgreSQL, choose a [Managed VPS](https://ruachost.com/vps).

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?

- 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

### Managed Accounts with cPanel

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.

### Unmanaged Accounts without cPanel

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:

   ```bash
   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:

   ```bash
   \list
   ```

> **Important Notes:**
- Always back up your database before renaming.
- Update application configuration files to reflect the new database name.
- Ensure no active connections are using the database during the rename.
- Clear cache in applications that rely on the database to avoid mismatches.
