// postgresql · security & access

password_encryption

How CREATE ROLE and ALTER ROLE store new passwords: SCRAM-SHA-256 or the legacy MD5 hash.

Par défaut
scram-sha-256
Range
scram-sha-256, md5
Restart needed
Non
Default checked on
PostgreSQL 18

Ce que cela fait

SCRAM-SHA-256 is the default and the only format to choose on a new server. MD5 is deprecated and slated for removal; PostgreSQL 18 already warns when a statement sets an MD5 password (md5_password_warnings, on by default).

Valeur par défaut

scram-sha-256. scram-sha-256 since PostgreSQL 14 (md5 before). Same in PostgreSQL 18.

Check the current value

SHOW password_encryption;

SELECT setting, unit, boot_val, context, source, pending_restart
FROM pg_settings
WHERE name = 'password_encryption';

Change it

SET password_encryption = 'scram-sha-256';   -- this session
ALTER ROLE reporting SET password_encryption = 'scram-sha-256';   -- new sessions of one role

ALTER SYSTEM SET password_encryption = 'scram-sha-256';
SELECT pg_reload_conf();

No restart. Any role can SET it for a session or with SET LOCAL for one transaction; a server-wide ALTER SYSTEM change applies after a reload (context is user).

When to change it

Leave it alone; check it after restoring or migrating from old servers, where an md5 value can ride along and silently hash every password you reset from then on.

What can go wrong

It affects only future passwords: existing roles keep their old verifier until they set a new one. A role whose stored verifier is still MD5 cannot log in where pg_hba.conf demands scram-sha-256, which is the usual post-migration 'password authentication failed'.

Questions about password_encryption

What is the default value of password_encryption in PostgreSQL?

scram-sha-256. scram-sha-256 since PostgreSQL 14 (md5 before). Same in PostgreSQL 18.

Does changing password_encryption require a restart?

No. No restart. Any role can SET it for a session or with SET LOCAL for one transaction; a server-wide ALTER SYSTEM change applies after a reload (context is user).

When should I change password_encryption?

Leave it alone; check it after restoring or migrating from old servers, where an md5 value can ride along and silently hash every password you reset from then on.

Back to all PostgreSQL settings, or check the PostgreSQL manual for every option.

// one client for every engine

Check password_encryption on your own server

SQLly runs the query above against PostgreSQL and the other engines in this reference, from one desktop app on macOS, Windows and Linux.

Texte et données de cette page : CC BY 4.0, en citant SQLly (sqlly.app). Code et extraits SQL : MIT. Détails de la licence