> Full Neon documentation index: https://neon.com/docs/llms.txt

# How do I rename a database in my Neon project?

Connect to a different database on the same branch, then run ALTER DATABASE ... RENAME TO.

To rename a database in Neon, connect to a different database on the same branch (for example, the default `neondb`), terminate any active connections to the database you want to rename, then run `ALTER DATABASE <old_name> RENAME TO <new_name>;`. You can also rename a database via the Neon API. After renaming, update any connection strings that referenced the old name. See [Manage databases with SQL](https://neon.com/docs/manage/databases#manage-databases-with-sql).

## Rename with SQL

Postgres won't let you rename a database while you're connected to it, so connect to another database on the same branch first. If you only have one database, create a throwaway:

```sql
CREATE DATABASE rename_helper;
```

Then connect to that database (`psql "...rename_helper"` or pick it in the SQL Editor branch/database selector) and run:

```sql
-- Terminate any open connections to the database being renamed
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname = 'old_db_name'
  AND pid <> pg_backend_pid();

-- Rename it
ALTER DATABASE old_db_name RENAME TO new_db_name;
```

The rename is instant. Data, schemas, tables, roles, and grants are unaffected.

If you created `rename_helper`, drop it after you're done:

```sql
DROP DATABASE rename_helper;
```

## Rename via the API

The Neon API supports renaming through `PATCH /projects/{project_id}/branches/{branch_id}/databases/{database_name}`:

```bash
curl -X PATCH \
  "https://console.neon.tech/api/v2/projects/$PROJECT_ID/branches/$BRANCH_ID/databases/old_db_name" \
  -H "Authorization: Bearer $NEON_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{ "database": { "name": "new_db_name" } }'
```

See [Update a database with the API](https://neon.com/docs/manage/databases#update-a-database-with-the-api).

**Warning: Update your connection strings**

The database name is part of every connection string for the database. After renaming, any application, script, or stored secret that still references the old name will fail to connect. Update them before the rename or right after, and reset role passwords if you want to invalidate old strings immediately.

**Warning: Don't rename neondb_owner or the default role**

You can rename a role with `ALTER ROLE`, but the default role created with your project (typically `neondb_owner`) is referenced by some Console flows and integrations. Renaming it can break Console widgets and integrations that expect the original name. Create a new role instead if you need a different owner. See [Manage roles](https://neon.com/docs/manage/roles).

The hostname portion of your connection string (`ep-cool-darkness-...neon.tech`) is generated by Neon and can't be renamed. To change it, you'd need to create a new compute (which gets a new endpoint ID) and delete the old one.

> **See all database management options**
>
> Console, CLI, API, and SQL workflows for creating, updating, and deleting databases.
>
> [Manage databases](https://neon.com/docs/manage/databases)
