Coming soon. The Wiki is in active development, so features and these docs may still change. Early adopters: contact us for access.

Database Password

Change or rotate the PostgreSQL password the Wiki signs in with, by hand, from a secret manager or on a schedule, without stopping the servers

1. Overview

The Wiki signs in to PostgreSQL with the URL you give it in DATABASE_URL. Each server also keeps the URL, encrypted with CONFIG_ENCRYPTION_KEY, in its bootstrap file, so it can start without the environment variable later. This page is about changing that password afterwards. Available on every license tier.

You want toDo this
Change the password once, by handChange it in PostgreSQL and in the environment
Let the Wiki rotate it, now or on a scheduleSettings → Database
Let a secret manager rotate itGive the URL as a file
Rotate with no refused sign-in at allUse two logins

The password is never shown, logged or returned by the API, wherever it is stored.

2. Where a server gets its credentials

When a server starts it tries, in this order:

  1. DATABASE_URL (or the file named by DATABASE_URL_FILE), when set;
  2. DATABASE_URL_STANDBY (or DATABASE_URL_STANDBY_FILE), when set;
  3. the URL saved in its bootstrap file, and the other logins it has used or been given.

The first that signs in is used and saved in the bootstrap file, with the others kept as fallbacks. So the environment wins: put a new password in DATABASE_URL, restart, and the server uses it. A server whose saved password stopped working, and that has nothing newer, starts in recovery mode, which says the credentials were refused.

A URL from the environment must reach the same installation. The server compares the installation ID in the database with the one it saved. A DATABASE_URL that points at another installation's database is refused (shown as Wrong database) and the saved one is used. To move an installation to another database on purpose, use recovery mode or restore a backup.

While a server runs, connections it already has stay open after a password change: PostgreSQL only checks a password when a connection is opened. Before it opens a new one, the server checks the login it uses, and when PostgreSQL refuses it the server moves to the next credential that works, so no request fails.

3. Change the password by hand

  1. Change it in PostgreSQL — ALTER ROLE wiki PASSWORD '…'; (use \password wiki in psql so the password doesn't reach the server log). Running servers keep working on the connections they have.
  2. Put the new URL where the servers read it — DATABASE_URL in each server's environment, the Kubernetes secret, or the file DATABASE_URL_FILE names.
  3. Restart the servers, one at a time — Each signs in with the new password and saves it. With DATABASE_URL_FILE no restart is needed: a server reads the file again when a sign-in is refused.

Between the first and the last step a server that needs a new connection has only the old password. Do the steps close together, or use two logins so there is always one that works.

4. Settings → Database

Super admins find the logins under Settings → Database: the database the servers connect to, the stored logins with their state, the rotation schedule, and what each server signs in with.

Settings → Database: the connection, two stored logins with Rotate now, the rotation schedule and the servers
Settings → Database: the connection, two stored logins with Rotate now, the rotation schedule and the servers
  • Stored logins. A few seconds after its first start, a server stores the login it uses (and a second one from DATABASE_URL_STANDBY) encrypted in the database, where every server reads it. Add a second login or Replace a login stores a role you created in PostgreSQL; the page tests that it signs in and can act as the owner of the tables before it is saved.
  • Test credentials makes the server you are on sign in with every credential it holds and shows which work.
  • Rotate now makes a new random password for one login.
  • Rotation schedule rotates one password whenever the newest is older than the days you choose (30, 60 or 90, or your own number up to 365). Off by default.
  • The server address, port and database name are shown but can't be changed here: they come from each server's start configuration.

5. What a rotation does

The Rotate now dialog names the login that gets a new password
The Rotate now dialog names the login that gets a new password
  1. The new password is handed out — It is stored encrypted and every running server takes it, without using it yet. The page shows how many servers hold it.
  2. The password is changed — When every running server holds it, the login changes its own password in PostgreSQL. This usually takes a few seconds.
  3. Servers move to it — Nobody restarts anything, and each server saves the new password in its bootstrap file.

If a running server doesn't take the new password within 5 minutes, or a server stops before taking it while only one login is stored, the rotation is given up: nothing was changed, the page says why, and super admins get an alert.

SituationWhat happens
Two logins are storedThe login the servers aren't using is changed, then becomes the preferred one. No sign-in is refused.
One login is storedThe login in use is changed. A server opening a new connection in the instant before it takes the change can meet one refused sign-in, and retries. The page says so before you confirm.
A server is off (one login)Refused: a server that is off can't learn the new password. Start it or add a second login. An administrator can rotate anyway (Rotate although these servers are off); that server then needs the new password from its environment or recovery mode before it starts. A stopped server leaves Settings → Clustering by itself about a day after it stopped, and then no longer counts.
A server is off (two logins)Allowed once: the server still starts on the login that didn't change. A second rotation is refused until it has been started, has left the list, or an administrator rotates anyway. A server that stopped before any login was stored is never in the way.
Something else signs in as the same roleA backup tool or dashboard using that login stops working: the new password is never shown. Give such tools their own role.

When your environment or secret also holds the password. After a rotation from this page, the copy in DATABASE_URL or your secret is out of date. Running servers are fine (they hold the stored logins) and the system check warns. A new server that has only that secret can't start until you update it. If a secret manager owns the password, leave rotation here off and let it rotate; see below.

6. Two logins

With two logins that act as one owner role, one password can change while the servers run on the other. Create them once:

CREATE ROLE wiki NOLOGIN CREATEROLE;              -- owns the database and its tables
CREATE ROLE wiki_a LOGIN NOINHERIT PASSWORD '…';
CREATE ROLE wiki_b LOGIN NOINHERIT PASSWORD '…';
GRANT wiki TO wiki_a, wiki_b;
GRANT CONNECT ON DATABASE wiki TO wiki_a, wiki_b;
DATABASE_URL=postgres://wiki_a:…@db.internal:5432/wiki?sslmode=verify-full
DATABASE_URL_STANDBY=postgres://wiki_b:…@db.internal:5432/wiki?sslmode=verify-full
DATABASE_OWNER_ROLE=wiki
  • DATABASE_OWNER_ROLE makes every connection act as that role, so tables have one owner whichever login is used. Set it from the first start, on every server.
  • The names are yours to choose. CREATEROLE is needed only for plugins that keep their own tables.
  • An installation that started with one login that owns its tables can stay that way: rotation works with one login, with the brief refused sign-in described above.

7. Secret managers

When Vault, AWS Secrets Manager, an external secrets operator or a similar tool owns the password, let the servers read it from a file the tool keeps current:

DATABASE_URL_FILE=/run/secrets/database-url
DATABASE_URL_STANDBY_FILE=/run/secrets/database-url-standby   # optional
  • Each file holds one URL. A server reads it again when PostgreSQL refuses a sign-in (at most every 5 seconds), so a rotated password needs no restart.
  • A tool that rotates by switching between two users (AWS's alternating-users rotation, for example) fits the two logins above: give both URLs.
  • A tool that changes the one password in place leaves a short gap between the change in PostgreSQL and the new file. Servers keep their open connections during it; a second login closes the gap.
  • Leave the rotation schedule in Settings → Database off, so only one side changes passwords. The page reminds you when a server signs in with a credential from its environment.

8. Environment variables

VariableMeaning
DATABASE_URLThe preferred login. Wins over the saved one at every start when it reaches the same installation
DATABASE_URL_FILEA file holding that URL, read again while the server runs. A path that doesn't exist counts as not set
DATABASE_URL_STANDBY, DATABASE_URL_STANDBY_FILEA second login for the same database, used when the first is refused
DATABASE_OWNER_ROLEThe role connections act as. Needed when the logins don't own the tables themselves

All of them are listed with the others under Environment variables.

9. System check, alerts and events

  • The system check has Database credentials (each server: a credential it holds is refused or points at another installation, or its environment holds an out-of-date password) and Database password rotation (the last change was given up, or the schedule is overdue).
  • A rotation that is given up, or a scheduled one that can't run, alerts super admins with a link to the page.
  • Events: database.credential.rotate and database.credential.update (before and after, blocking) and database.credential.rotation_failed (after). They carry the login name and the reason, never a password.

10. Permissions

PermissionWhoAllows
database:adminSuper admins onlyViewing the page, testing, storing and removing logins, rotating, and the schedule

Every rotation, stored or removed login and schedule change is recorded in the audit log, without the password.