Upgrade Password Encryption to scram-sha-256
Check which password algorithm a Managed PostgreSQL service uses, find the roles that still have an md5 password, and move them to scram-sha-256 one at a time, without downtime.
How Password Encryption Works
PostgreSQL stores a verifier for each password, computed with the algorithm set by the
password_encryption parameter at the moment the password is set: scram-sha-256 or md5.
Changing the parameter does not touch the existing verifiers. A role keeps its md5 verifier
until its password is set again.
scram-sha-256 is the recommended algorithm. PostgreSQL 18 deprecates md5 passwords: setting
one prints WARNING: setting an MD5-encrypted password with the detail that support will be
removed in a future release. See
Password authentication in the PostgreSQL documentation.
On Managed PostgreSQL, password_encryption applies to every way a password is set: SQL
CREATE ROLE ... PASSWORD and ALTER ROLE ... PASSWORD, but also exo dbaas user create and
exo dbaas user reset-credentials.
Check the Service Setting
The algorithm used for the next password:
SHOW password_encryption;A new service returns scram-sha-256. The value stored in the service configuration:
exo dbaas show SERVICE_NAME -z ZONE --settings=pgParameters:
SERVICE_NAME: name of the Managed PostgreSQL service, for examplemy-postgresql.ZONE: zone the service runs in, for examplech-gva-2.
On a new service the output contains "password_encryption": "scram-sha-256". If the value is
md5, set it:
exo dbaas update SERVICE_NAME -z ZONE -f \
--pg-settings='{"password_encryption":"scram-sha-256"}'Parameters:
SERVICE_NAME: name of the Managed PostgreSQL service.ZONE: zone the service runs in.-f: applies the update without confirmation. Without it, the command asks for confirmation and, in a script, applies nothing.
The new value applies to new sessions within seconds, without a restart.
Find the Roles Still on md5
The verifiers themselves cannot be read: avnadmin is not a superuser, and both catalogs that
hold them refuse it:
ERROR: permission denied for table pg_authid
ERROR: permission denied for view pg_shadowThe service logs do not tell either. Every connection is logged with method=md5, for SCRAM
roles too, because the authentication rule of the service is md5. PostgreSQL treats that rule
as “md5 or SCRAM”: a role with a SCRAM verifier authenticates with SCRAM, a role with an md5
verifier with md5. Both keep working during the migration.
Test from the client instead. libpq 16 and later, including psql 16 and later, accept the
require_auth parameter, which refuses any method other than the one you name:
psql "host=HOST port=PORT dbname=defaultdb user=ROLE_NAME sslmode=require require_auth=scram-sha-256" \
-c "SELECT 'scram-sha-256'"Parameters:
HOST,PORT: hostname and port of the service, fromexo dbaas show SERVICE_NAME -z ZONE --uri.ROLE_NAME: the role to test.psqlreads its password fromPGPASSWORDor~/.pgpass.
A role with a SCRAM verifier connects. A role with an md5 verifier fails with:
authentication method requirement "scram-sha-256" failed: server requested a hashed passwordTo list the roles that can log in, excluding the predefined pg_ roles and the platform roles:
SELECT rolname
FROM pg_roles
WHERE rolcanlogin
AND rolname NOT LIKE 'pg\_%'
AND rolname NOT LIKE '\_%'
AND rolname <> 'postgres'
ORDER BY rolname;The excluded _aiven, _avnadmin_* and postgres roles are managed by the platform.
Check Your Clients
A client that cannot authenticate with SCRAM keeps working while its role has an md5 verifier,
and fails as soon as you rotate that role. Check the client library of each application before
you rotate its role.
Clients built on libpq, such as psql, psycopg, pdo_pgsql and the Ruby pg gem, need libpq
10 or later. Drivers with their own protocol implementation, such as pgjdbc, node-postgres, pgx
and Npgsql, list SCRAM support in their release notes. The drivers at the versions shown in the
connection pages linked below all authenticate with SCRAM.
If a client cannot be upgraded yet, leave its role on md5 until it can. Do not set
password_encryption back to md5 for the whole service: every password set afterwards,
including generated ones, would get an md5 verifier.
Rotate a Platform-Managed User
For users whose password the platform holds, such as users created with exo dbaas user create,
rotate with the CLI:
exo dbaas user reset-credentials SERVICE_NAME USERNAME -z ZONEParameters:
SERVICE_NAME: name of the Managed PostgreSQL service.USERNAME: name of the user.ZONE: zone the service runs in.
A new password is generated, with a SCRAM verifier. To choose the password, add
--password PASSWORD, with 8 to 256 characters. Read it back and update the applications:
exo dbaas user reveal-secrets SERVICE_NAME USERNAME -z ZONEDo not use ALTER ROLE ... PASSWORD for these users: after a change in SQL, reveal-secrets
returns an empty password. See
Manage Users and Databases.
Rotate a SQL Role
For roles whose password you manage in SQL, set the password again. It can be the same password: the new verifier uses the current algorithm, so the application does not need a new credential.
SHOW password_encryption;
ALTER ROLE ROLE_NAME PASSWORD 'ROLE_PASSWORD';Parameters:
ROLE_NAME: name of the role.ROLE_PASSWORD: the password, new or unchanged.
password_encryption can be changed per session, so check it in the session that sets the
password.
Tip
ALTER ROLE ... PASSWORD sends the password in clear text to the server. In psql, the
\password ROLE_NAME meta-command prompts for the password and sends only the verifier,
computed on the client with the current password_encryption.
Then run the require_auth test above for that role, from the machine and with the driver the
application uses.
Connection Pools
Clients connect through the pools with SCRAM as well. After a rotation, the pgbouncer port can
refuse the new password with FATAL: SASL authentication failed for a few seconds, while the
pg port already accepts it. Retry the connection rather than rolling the password back.
A pool created with a username accepts only that user. Read the pools and their users with:
exo api get-dbaas-service-pg SERVICE_NAME -z ZONE -q '"connection-pools"[].[name,username]'