# password_encryption

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

Source: https://sqlly.app/sql-configuration/postgresql/password-encryption
Last updated: 2026-11-30
License: Text and data [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) (credit SQLly, sqlly.app); code and SQL snippets [MIT](https://opensource.org/license/mit). [Details](https://sqlly.app/license).

**Default**

`scram-sha-256`

**Range**

scram-sha-256, md5

**Restart needed**

No

**Default checked on**

PostgreSQL 18

## What it does

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).

## Default value

`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](https://sqlly.app/sql-configuration/postgresql), or check the [PostgreSQL manual](https://www.postgresql.org/docs/current/runtime-config.html) for every option.

## Related PostgreSQL settings

- [`ssl` Accept TLS connections on the normal PostgreSQL port.](https://sqlly.app/sql-configuration/postgresql/ssl)
