I've enabled the archive_mode with wal_level = hot_standby on a master server. I intended to send the wal logs to a nfs share with:

archive_command = 'test ! -f /mnt/psql_wal/%f && cp -i %p /mnt/psql_wal/%f'

But it keeps telling me this:

sh: /var/lib/pgsql/archive_wal.sh: Permission denied
LOG:  archive command failed with exit code 126
DETAIL:  The failed archive command was: test ! -f /mnt/psql_wal/000000010000000000000001 && cp -i pg_xlog/000000010000000000000001 /mnt/psql_wal/000000010000000000000001
cp: failed to access ‘/mnt/psql_wal/000000010000000000000001’: Permission denied

Basic nfs permissions issue, you may think, but no. The following command works:

sudo -H -u postgres cp -i /var/lib/pgsql/data/pg_xlog/000000010000000000000001 /mnt/psql_wal/000000010000000000000001

Is the archive command running under a different user?

  • Try giving complete access 777 to path /mnt/psql_wal to postgres user Commented Oct 11, 2017 at 13:21
  • 1
    Can you elaborate on where /var/lib/pgsql/archive_wal.sh does come from and whether it has anything to do with the failure immediately below? Commented Oct 11, 2017 at 17:15
  • @DanielVérité, that line was a copy/paste mistake, but the content of that script results in precisely the same commands: test ! -f /mnt/psql_wal/000000010000000000000001 && cp -i pg_xlog/000000010000000000000001 /mnt/psql_wal/000000010000000000000001 Commented Oct 11, 2017 at 23:01

1 Answer 1


You are probably a victim of selinux or something like it, in which the same system OS account can have different permissions depending whether it is running as a deamon or from a command line (and, it often seems, depending on the barometric pressure, the phase of the moon, and what you had for breakfast).

You can turn it off, or put it into permissive mode where it allows the access and just logs a gripe.

  • 1
    Bingo! Thank you, @jjanes, that was it. After running sudo setenforce 0 the archive_command worked like a charm. Commented Oct 12, 2017 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.