Make PostgreSQL advisory-lock string hashing optional
Author: lesebCreated Sep 23, 2026Updated Sep 23, 2026
Labelsenhancement
I have found these related issues/pull requests
No
Description
PgAdvisoryLock::new(string) derives a numeric PostgreSQL advisory-lock key using HKDF and SHA-256. As a result, sqlx-postgres unconditionally compiles hkdf and sha2, even when an application:
- Does not use advisory locks, or
- Uses
PgAdvisoryLock::with_key(i64)with an explicit numeric key.
Downstream applications cannot remove these dependencies through Cargo features.
This matters for dependency minimization and environments where cryptographic implementations must come exclusively from approved modules, including FIPS-oriented builds. Numeric advisory-lock keys do not require client-side cryptographic hashing.
Prefered solution
- Add a default-enabled
advisory-lock-hashingfeature tosqlx-postgres. - Gate
PgAdvisoryLock::new(string)and its string-to-key derivation behind it. - Keep
PgAdvisoryLock::with_key(i64)available without the feature. - Make
hkdfoptional. - Make
sha2optional and enable it through every feature that requires it, including password authentication where applicable. - Forward the feature through the
sqlxfacade.
Is this a breaking change? Why or why not?
Yes, potentially. This breaks default-features = false consumers that call PgAdvisoryLock::new(). They must enable advisory-lock-hashing. Default-feature and numeric-key users are unaffected.
Source: transact-rs/sqlx