The login prompt waited, but the database behind it was off-limits until the right second factor unlocked the gate. Multi-Factor Authentication (MFA) for pgcli is no longer optional—it is the baseline for securing direct database access.
Pgcli is the popular CLI tool for PostgreSQL users who value autocomplete, syntax highlighting, and speed. But speed without security is a liability. MFA adds a strong second layer, forcing attackers to overcome more than just a password.
Implementing MFA in pgcli starts with integrating an identity provider that supports modern authentication flows—TOTP, WebAuthn, or push-based approval. Whether you connect via local network or remote server, the MFA handshake needs to happen before pgcli establishes a database session. This prevents credential stuffing and limits damage from stolen passwords.
To set this up, configure pgcli to route all connections through a secure proxy or gateway that enforces MFA. Common patterns include wrapping pgcli behind an SSH bastion with MFA enforcement or using a cloud database firewall. Align the MFA provider's session duration with your security policy to avoid silent credential reuse.