2

How to close connection using psql when executed from shell script

1 Answer 1

3

If you run

psql -c '/* SQL statement */'

or

psql -f script.sql

the connection will automatically be closed as soon as the command is done

Sign up to request clarification or add additional context in comments.

2 Comments

Laurenz Albe, Thanks for your answer, i have scheduled job through jenkins, which hit my postgres DB in every 1 hour and in between i am getting this error "Failed to get SSH fingerprint from DB: pq: remaining connection slots are reserved for non-replication superuser connections" I doubt it could be because script does not closing the connection. according to your answer, it should close the connection, any idea why i am getting this error?
There are many other connections to the database. Examine pg_stat_activity to find out where they come from.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.