'error in psql connection with Jenkins shell

i am trying to execute psql command in jenkins steps. This command is working in jenkins linux terminal but it seems nohup is not connecting when trying with jenkins steps.

sh """
cat $DBCONNECT1 > new.pem
chmod 400 new.pem
export BUILD_ID=dontKillMe
nohup ssh -i new.pem -N -L 5000:mycluster.us-west-1.rds.amazonaws.com:5000 [email protected] -o StrictHostKeyChecking=no &

#export PGPASSWORD="password";
#psql -h "localhost" -U "myuser" -d "new_db" -c "select * from customer"
"""

error:-

psql: error: could not connect to server: Connection refused Is the server running on host "localhost" (128.1.1.1) and accepting TCP/IP connections on port 5000? could not connect to server: Network is unreachable Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5000?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source