I have script [1] that is executed by Postgres daemon (WAL archiver) and fails with exit code 12; see [2]. But if I execute the same script on a terminal/ssh session, it succeeds; see [3].
User BasketCase on freenode IRC channel #rsync tried to diagnose it, but couldn't get far. See [4] for the conversation.
This does not happen on all the machines its used on, but this is the second time I have faced this.
Any help will be highly appreciated.
Thanks in advance.
[1] WAL archiving script
#!/bin/bash
# $1 is the %p substituted by postgres in archive_command
# $2 is the %f substituted by postgres in archive_command
# This script backs up the WAL file to every replica, and
# exits with the last failure code, if any.
final_exit_code=0
replicas=$(grep REPLICA /some/file | sort | uniq | cut -d = -f 2-)
for replica_url in $replicas; do
echo Sending WAL file to $replica_url
rsync --timeout=10 -avz -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10 -i /opt/PostgresPlus/CloudDB/data/cluster_ssh.key' "$1" root@$replica_url:/mnt/pcs/wal_archive/"$2"
exit_code=$?
if [ $exit_code -ne 0 ] ; then final_exit_code=$exit_code ; fi
done
exit $final_exit_code
[2] Sending WAL file to 10.33.177.184 rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: error in rsync protocol data stream (code 12) at io.c(600) [sender=3.0.6] LOG: archive command failed with exit code 12 DETAIL: The failed archive command was: ./wal_archive.sh pg_xlog/0000000100000005000000EE 0000000100000005000000EE
[3] $ ./wal_archive.sh pg_xlog/0000000100000005000000EE 0000000100000005000000EE Sending WAL file to 10.33.177.184 Warning: Permanently added '10.33.177.184' (RSA) to the list of known hosts. sending incremental file list 0000000100000005000000EE
sent 5180930 bytes received 31 bytes 941992.91 bytes/sec total size is 16777216 speedup is 3.24
su
) the postgres daemon account? (2) Which Linux distro are you using?