Re: postgres connection with port option in shell script

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Abhra Kar <abhra(dot)kar(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: postgres connection with port option in shell script
Date: 2018-02-14 15:33:57
Message-ID: CAKFQuwZbtEPhB2ZDbhot+xkb9j-y6uBiNDfkz2+TO1Kac2YDwA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Feb 14, 2018 at 8:21 AM, Abhra Kar <abhra(dot)kar(at)gmail(dot)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(at)$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.
>


https://www.postgresql.org/docs/10/static/libpq-connect.html#LIBPQ-CONNSTRING

​David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Yogesh Sharma 2018-02-14 16:06:01 Regarding pg_multixact/members folder size cleanup in postgres 9.3.6.
Previous Message Andreas Kretschmer 2018-02-14 15:25:21 Re: postgres connection with port option in shell script