“psql: could not connect to server: Connection refused” Error when connecting to remote database

cd /etc/postgresql/9.x/main/ open file named postgresql.conf sudo vi postgresql.conf add this line to that file listen_addresses=”*” then open file named pg_hba.conf sudo vi pg_hba.conf and add this line to that file host all all 0.0.0.0/0 md5 It allows access to all databases for all users with an encrypted password restart your server sudo /etc/init.d/postgresql restart

Postgresql: Scripting psql execution with password

You may wish to read a summary of the ways to authenticate to PostgreSQL. To answer your question, there are several ways provide a password for password-based authentication: Via the password prompt. Example: psql -h uta.biocommons.org -U foo Password for user foo: In a pgpass file. See libpq-pgpass. Format: <host>:<port>:<database>:<user>:<password> With the PGPASSWORD environment variable. … Read more