Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Databases and Redis

pg_dump or psql fails with fe_sendauth: no password supplied

Your error

fe_sendauth: no password supplied2 more lines it can show

Fix it fast

Most common cause, 1 of 3

The job runs with nobody to type the password and no password source

Give the job a password file it can read.

Fix
printf '%s\n' 'localhost:5432:dbdev:app_user:REPLACE_ME' > /home/backup/.pgpass-dbdev
chmod 0600 /home/backup/.pgpass-dbdev
# crontab line
0 2 * * * PGPASSFILE=/home/backup/.pgpass-dbdev pg_dump -h localhost -U app_user -d dbdev -F c -f /backups/dbdev.dump
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

fe_sendauth: no password supplied is libpq saying the server asked for a password and the client had none. It hits cron and CI jobs with no password source, runs with -w, and -h localhost, which swaps peer login on the socket for password login over TCP. Give the job a password file or use the socket. PostgreSQL 13 to 19.

  • Applies to PostgreSQL 19.0 and 18.7 (client and server), libpq from PostgreSQL 13 onward (same message)
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Run the exact command by hand in a terminal, as the same OS user the job uses. If it now asks for a password, the job simply has no password source (cause 1). If it fails the same way without asking, look for -w (cause 2). If it works only when you leave out -h, the server uses different login rules for the socket and for TCP (cause 3).

Run this first
whoami
pg_dump -h localhost -U app_user -d dbdev -f /tmp/test.dump
pg_dump -U app_user -d dbdev -f /tmp/test.dump

Then find the line you see in this list and open its fix:

  1. 1The job runs with nobody to type the password and no password sourceThe command prompts for Password: in a terminal but fails in cron, a CI step or docker exec without a TTY
  2. 2The command passes -w or --no-passwordThe error appears at once in a terminal too, and the script or wrapper has -w or --no-password in the pg_dump arguments
  3. 3-h localhost uses a TCP rule that wants a password, while the socket uses peersudo -u postgres pg_dump dbdev works, but adding -h localhost or -h 127.0.0.1 gives the error

What does the error look like?

  • fe_sendauth: no password supplied
  • connection to server at "localhost" (127.0.0.1), port 5432 failed: fe_sendauth: no password supplied
  • The same fe_sendauth text stays in English on a French or German system, because libpq does not translate that one string

Cause 1 of 3

The job runs with nobody to type the password and no password source

You seeThe command prompts for Password: in a terminal but fails in cron, a CI step or docker exec without a TTY

Check

libpq raises fe_sendauth: no password supplied when the server's authentication request arrives and the password it holds is empty. In a terminal pg_dump asks for it; a batch job has nobody to answer, so it needs a password from the connection settings, PGPASSWORD or a password file.

Check
env | grep -E '^PG(PASSWORD|PASSFILE|HOST|USER)='

Fix

Give the job a password file it can read. Point PGPASSFILE at it so the job does not depend on HOME, and keep its mode at 0600 or libpq ignores it. In CI, set PGPASSWORD from the secret store for that step only; the PostgreSQL docs discourage that variable on shared machines because some systems let other users read process environments.

Fix
printf '%s\n' 'localhost:5432:dbdev:app_user:REPLACE_ME' > /home/backup/.pgpass-dbdev
chmod 0600 /home/backup/.pgpass-dbdev
# crontab line
0 2 * * * PGPASSFILE=/home/backup/.pgpass-dbdev pg_dump -h localhost -U app_user -d dbdev -F c -f /backups/dbdev.dump

Verify

The same command with -w added finishes without a prompt, which proves the password comes from the file.

Verify
PGPASSFILE=/home/backup/.pgpass-dbdev pg_dump -w -h localhost -U app_user -d dbdev -f /tmp/test.dump && echo OK

Confirmed by postgresql.org

Did this fix it?

Cause 2 of 3

The command passes -w or --no-password

You seeThe error appears at once in a terminal too, and the script or wrapper has -w or --no-password in the pg_dump arguments

Check

-w tells pg_dump never to prompt. If the server wants a password and none is available from a password file or the environment, the connection fails right away. The flag is meant for unattended jobs, so a copied backup script often carries it.

Check
grep -n -E -- '(^| )-w( |$)|--no-password' backup.sh

Fix

Keep -w only where a password source is set up, as in cause 1. For a one-off run by hand, drop -w so pg_dump can ask, or add -W to make it ask before the first connection attempt.

Fix
pg_dump -W -h localhost -U app_user -d dbdev -f /tmp/dbdev.sql

Verify

pg_dump asks for the password once and writes the dump file.

Verify
ls -l /tmp/dbdev.sql

Confirmed by postgresql.org

Did this fix it?

Cause 3 of 3

-h localhost uses a TCP rule that wants a password, while the socket uses peer

You seesudo -u postgres pg_dump dbdev works, but adding -h localhost or -h 127.0.0.1 gives the error

Check

When no host is given, the connection goes over the Unix-domain socket, and pg_hba.conf judges it by its local lines. Naming localhost makes it a TCP connection, matched by host lines. Peer login works only on local connections, so a role that never had a password can log in over the socket and fails over TCP.

Check
sudo -u postgres psql -c "SELECT line_number, type, database, user_name, address, auth_method FROM pg_hba_file_rules;"

Fix

For a backup on the same machine, run pg_dump as the matching OS user and leave out -h, so the socket and peer rule apply. If the job must use TCP, give the role a password and a password source as in cause 1.

Fix
# socket + peer, no password needed
sudo -u postgres pg_dump -d dbdev -F c -f /backups/dbdev.dump
# or set a password for TCP logins
sudo -u postgres psql -c "\\password app_user"

Verify

The dump finishes and pg_restore can list what is inside it.

Verify
sudo -u postgres pg_restore --list /backups/dbdev.dump | head

Confirmed by postgresql.org

Did this fix it?

How do I stop it coming back?

  • Write backup jobs with an explicit PGPASSFILE and the -w flag, so a missing password fails fast in the log instead of waiting on a prompt.
  • Prove a new backup job through the scheduler itself, with a test entry a few minutes ahead, because a run from your own shell hides a missing password source.
  • Write down in the backup script whether it uses the socket (no -h) or TCP, since the two follow different pg_hba.conf lines.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.