Parameter · Connections and Authentication / Authentication
password_encryption
Chooses the algorithm for encrypting passwords.
- Default:
scram-sha-256 - Type: enum
- Values: md5 · scram-sha-256
- Applies: Session (any user)
In plain words
When you set a password with CREATE ROLE … PASSWORD or ALTER ROLE … PASSWORD, PostgreSQL never stores the password itself, only a hash. This setting picks the hash: scram-sha-256 (default, strong) or the old md5.
It only affects passwords set from now on. MD5 is deprecated since PostgreSQL 18.
For DBAs and operators
The choice is applied when the password is set; existing hashes in pg_authid.rolpassword keep their format (md5… or SCRAM-SHA-256$4096:…). If the client sends an already-hashed password (psql's \password, libpq's PQencryptPasswordConn), the server stores what it got regardless of this setting.
Interaction with pg_hba.conf: method md5 accepts both MD5 and SCRAM secrets (it uses SCRAM when the stored secret is SCRAM); method scram-sha-256 accepts only SCRAM secrets, so users with old MD5 hashes fail with FATAL: password authentication failed for user "app" plus a DETAIL like User "app" does not have a valid SCRAM secret.
PostgreSQL 18: MD5 passwords are deprecated. Setting one emits WARNING: setting an MD5-encrypted password / DETAIL: MD5 password support is deprecated and will be removed in a future release of PostgreSQL. (controlled by md5_password_warnings).
Migration: set password_encryption = 'scram-sha-256', have every user re-set the password, then switch pg_hba.conf to scram-sha-256. Find leftovers with:
SELECT rolname FROM pg_authid WHERE rolpassword LIKE 'md5%';
Old clients (libpq < 10, old JDBC/ODBC drivers) cannot do SCRAM; upgrade them first.
How to change it
Any user can change it for their session with SET.
See it in context
Related parameters
scram_iterations md5_password_warnings authentication_timeout