---
title: "Rotate Database Credentials on Railway"
description: "How to regenerate a Railway database password and update the services that use it, including how to limit downtime on standalone databases."
date: 2026-11-20T18:54:40.017Z
updated: 2026-11-24T17:34:44.666Z
topics: ["CI/CD", "Security"]
tags: ["Environment Variables", "Secrets", "Database", "Postgres", "Redis"]
url: https://railway.com/guides/rotate-database-credentials
---

# Rotate Database Credentials on Railway

**TL;DR**

- Regenerate database credentials with Railway.
- Regenerate only updates services that get the password through a reference variable, so replace pasted copies first.
- Avoid editing the password variable or running `ALTER USER` directly.

A database password is a **credential**, and **rotating** it means replacing it with a new one so the old one is no longer valid. On Railway, you rotate a database password in a single step. For how variable changes, deploys, and healthchecks work on Railway, see [Rotate environment variables on Railway without downtime](https://railway.com/guides/rotate-environment-variables-without-downtime).

## How to rotate Railway database credentials

Regenerating a database password in Railway rotates it in a single step. Railway changes the password inside the database and updates the password variable and anything that references it, such as the database URL. For the full walkthrough for your database, see [Rotate PostgreSQL credentials](https://blog.railway.com/p/security-disclosure-recommendation-rotate-postgresql-database-credentials), [Rotate MySQL credentials](https://blog.railway.com/p/security-disclosure-recommendation-rotate-mysql-database-credentials), [Rotate Redis credentials](https://blog.railway.com/p/security-disclosure-recommendation-rotate-redis-database-credentials), or [Rotate MongoDB credentials](https://blog.railway.com/p/security-disclosure-recommendation-rotate-mongodb-database-credentials).

### Before you regenerate

Regenerate only updates services that get the password through a reference variable. Replace any pasted copy of the password or connection string with a reference:

- PostgreSQL: `${{ Postgres.DATABASE_URL }}`
- MySQL: `${{ MySQL.MYSQL_URL }}`
- Redis: `${{ Redis.REDIS_URL }}`
- MongoDB: `${{ MongoDB.MONGO_URL }}`

Use the name of your own database service in place of `Postgres`, `MySQL`, `Redis`, or `MongoDB`. Services in other projects and applications outside Railway can’t use references, so you’ll update those by hand afterward.

### Regenerate the password

When you’re ready, regenerate the password:

1. Open your database service.
2. Go to the Database tab and open Config.
3. In the Connection section, click Regenerate:

![The Regenerate button is located in Database → Config.](https://cms.railway.com/media/d80183a1-e557-457a-8106-d4298552b355-0fd8ef6a-5b31-454d-a925-b1841477c3a8-83830338-3ed0-4d8f-b6f4-9b5efa395d24-dec76695-851c-499f-afc8-09572c2ebab7-image.png)

On a standalone database, Regenerate restarts the database and drops all connections. Services that use the old password can’t reconnect until Railway redeploys them, so there will be some downtime. A high availability cluster doesn’t restart, because its members adopt the new password and keep serving connections. In either case, Railway then redeploys the running services that reference the password through Railway variables.

### After you regenerate

Finish the rotation:

1. Railway redeploys services that reference the password automatically. If a redeploy fails, check the service’s deploy logs and redeploy it manually.
2. Update the password by hand in pasted copies, services in other projects, and apps outside Railway, then redeploy the ones in your project. Until you do, they fail with an authentication error.
3. Check each service’s deploy logs for authentication errors. To confirm nothing still uses the old password and to end open sessions, use the guide for your database.

**Avoid editing the password directly**

Avoid editing the password variable or running ALTER USER (or the equivalent for your database). Neither change updates the other, so they fall out of sync and cause connections to fail. See [Using the Database View](https://docs.railway.com/databases/database-view).

### **Zero-downtime option for standalone databases**

If you can’t accept the downtime caused by a database restart, you can rotate manually with a second database user: Create the new user, update the database service’s variables to use it, redeploy your services, verify, then drop the old user. This avoids redeploying the database.

Make sure the database service’s user and password variables (`POSTGRES_USER` and `POSTGRES_PASSWORD` for PostgreSQL), as well as `DATABASE_URL`, are updated to the new user. This lets a later Regenerate or `databasePasswordReset` rotate the correct user.

# **FAQ**

**Will rotating DATABASE\_URL break services that reference it?**

Regenerate redeploys any service that uses a reference variable, such as `${{ Postgres.DATABASE_URL }}`, with the new password. Pasted copies aren’t updated, so they fail until you change them by hand.

**How do I know the old credential is no longer in use?**

Check the database for a “last used” date. Your database’s rotation guide shows how to list open sessions. Then check your deploy logs for authentication errors, such as `password authentication failed` in PostgreSQL.

**Can I roll back if the new credential fails?**

A database password regenerated in Railway can’t be rolled back, because the old password stops working.

## **Summary**

Replace pasted copies of the password with reference variables so every service picks up the change when you regenerate it. Downtime can’t always be avoided: regenerating a standalone database’s password, and databases with volumes, have no overlap period. In these cases, rotate during low-traffic periods and deploy right after changing the credential to keep the gap as short as possible, or use the zero-downtime option above.

See also:

- [Rotate environment variables on Railway without downtime](https://railway.com/guides/rotate-environment-variables-without-downtime)
- [Rotate third-party API keys on Railway](https://railway.com/guides/rotate-third-party-api-keys)
- [Automate credential rotation on Railway](https://railway.com/guides/automate-credential-rotation)
- [Managing Secrets on Railway](https://railway.com/guides/managing-secrets-on-railway)
- [Using the Database View](https://docs.railway.com/databases/database-view)
- [Variables](https://docs.railway.com/variables)

