Re: postgres connection with port option in shell script - Mailing list pgsql-general

From David G. Johnston
Subject Re: postgres connection with port option in shell script
Date
Msg-id CAKFQuwZbtEPhB2ZDbhot+xkb9j-y6uBiNDfkz2+TO1Kac2YDwA@mail.gmail.com
Whole thread Raw
In response to postgres connection with port option in shell script  (Abhra Kar <abhra.kar@gmail.com>)
Responses Re: postgres connection with port option in shell script
List pgsql-general
On Wed, Feb 14, 2018 at 8:21 AM, Abhra Kar <abhra.kar@gmail.com> wrote:

Hi,

      I want to get postgres connection in script file. I am executing below command and successfully getting connected --- 


psql postgresql://$USER:$PASSWORD@$HOST/$DATABASE <<END



If all you are going to do is substitute environment variables into a URI why not just identify the environment variables that psql uses directly, set those, and call "psql" directly.​

select * from abc;


This is executing with default 5432 port.If postgres is installed to any other port then port option need to be include here[Don't want to take port from .pgpass file].


​You couldn't even if you wanted to.​  Did you maybe mean the .pg_service.conf file?

You should strongly consider using .pgpass instead of "$PASSWORD" - especially depending upon where perform the export.
 

How I can modify this command with PORT option.



​David J.

pgsql-general by date:

Previous
From: Andreas Kretschmer
Date:
Subject: Re: postgres connection with port option in shell script
Next
From: Yogesh Sharma
Date:
Subject: Regarding pg_multixact/members folder size cleanup in postgres 9.3.6.