问题原文
原帖链接 · FatFreddy · CC BY-SA 4.0
postgres 9.6 Debian GNU/Linux 9
is use following simplyfied bash script wich gets called from a users crontab, myid is a passed parameter:
#!/bin/bash
...
PGPASSFILE="/home/user/.pgpass"
PGCONNECT=" psql -U myuser -w -h 000.000.000.000 -d mydatabase -p 5432"
PGCOMMAND1="SELECT something, somemmore FROM schema.table WHERE id= ${myid}"
PGRESULT=`$PGCONNECT -A -F ";" -t -c "$PGCOMMAND1"`
RETCODE1=$?
...
PGCOMMAND2="SELECT schema.functionname(${myid});"
PGRESULT=`$PGCONNECT -A -F ";" -t -c "$PGCOMMAND2"`
RETCODE2=$?
if [ $RETCODE1 -eq 0 ] && [ $RETCODE2 -eq 0 ]; then
mailx -s sendme_asuccessemail
else
echo -e "ret1: $RETCODE1\n" >> $MAIL_FILE
echo -e "ret2: $RETCODE2\n" >> $MAIL_FILE
mailx -s sendme_errormailwith retcode1=2
fi
and most of the time all is ok ( the script runs 60 times a day to different times ). once per week or less i get a errormail with psql exit status 2 in RETCODE1 as a result of the select.
from the manpage:
2 if the connection to the server went bad and the session was not
interactive
it may happen, this script is called per usercrontab, that it gets executeted twice or more on the same time with different myid. The second command always gets called, which does the real work.
How can i narrow down the error ? What does the error realy mean ? Can i ignore it ?
已采纳解答
原帖链接 · asktyagi · CC BY-SA 4.0
psql exit code 2 can be ignored if it is not too frequent, reason could be network or db health. To dig more you can add debug steps to script which shows network connectivity and db health(server is busy and loaded with queries) before doing real work.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
