Re: create batch script to import into postgres tables

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: pepevo <pepevo(at)yahoo(dot)com>, cgerard999(at)gmail(dot)com
Cc: Christopher Browne <cbbrowne(at)gmail(dot)com>, Pgsql-admin <pgsql-admin(at)postgresql(dot)org>, Pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: create batch script to import into postgres tables
Date: 2020-06-19 14:33:27
Message-ID: 61c306a5-932a-fdea-89dd-ec27fcaba37c@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general

On 6/19/20 7:17 AM, pepevo wrote:
> I understand your post about "password does not take an argument, it is
> meant to be used as is. The purpose is to force a password prompt." When
> I used -W and --password=.  That's what I said I will try pgpassfile.
> Thought it like mysq/oracle can indicate out without creating password
> file.

If you want to expose your password in the script file then:

https://www.postgresql.org/docs/12/app-psql.html

Usage
Connecting to a Database

"An alternative way to specify connection parameters is in a conninfo
string or a URI, which is used instead of a database name. This
mechanism give you very wide control over the connection. For example:

$ psql "service=myservice sslmode=require"
$ psql postgresql://dbmaster:5433/mydb?sslmode=require

This way you can also use LDAP for connection parameter lookup as
described in Section 33.17. See Section 33.1.2 for more information on
all the available connection options."

So:

psql
postgresql://PSmasteruser:mypassword(at)hostname(dot)amazonaws(dot)com:5432/PSCIDR

or

psql 'dbname=PSCIDR user=PSmasteruser host=hostname.amazonaws.com port=
5432 password=mypassword '

>
> Thank you again.
>
> Bach-Nga
>
> Sent from my Metro By T-Mobile 4G LTE Android Device
>
>
> -------- Original message --------
> From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
> Date: 6/19/20 09:58 (GMT-05:00)
> To: Pepe TD Vo <pepevo(at)yahoo(dot)com>, cgerard999(at)gmail(dot)com
> Cc: Christopher Browne <cbbrowne(at)gmail(dot)com>, Pgsql-admin
> <pgsql-admin(at)postgresql(dot)org>, Pgsql-general <pgsql-general(at)postgresql(dot)org>
> Subject: Re: create batch script to import into postgres tables
>
> On 6/19/20 6:53 AM, Pepe TD Vo wrote:
> > Thank you sir and I am sorry for the typo not having "--" on password.
> > I did spelling out with --password=mypassword
>
> Please go back and read my post again.
>
> >
> >>> echo select count(*) from tableA; | "C:\Program
> > Files\PostgreSQL\11\bin\psql" -U PSmasteruser -d PSCIDR -h
> > hostname.amazonaws.com -p 5432 --password=mypassword
> >
> > even -W for password
> >>> echo select count(*) from tableA; | "C:\Program
> > Files\PostgreSQL\11\bin\psql" -U PSmasteruser -d PSCIDR -h
> > hostname.amazonaws.com -p 5432 -W=mypassword
> >
> > none of them work, still prompt me for password to type in.  I will look
> > into the pgpassfile which I know it will fail again.
> >
> >
> > very respectfully,
> >
> > **
> > *Bach-Nga
> >
> > *No one in this world is pure and perfect.  If you avoid people for
> > their mistakes you will be alone. So judge less, love, and forgive
> > more.EmojiEmojiEmoji
> > To call him a dog hardly seems to do him justice though in as much as he
> > had four legs, a tail, and barked, I admit he was, to all outward
> > appearances. But to those who knew him well, he was a perfect gentleman
> > (Hermione Gingold)
> >
> > **Live simply **Love generously **Care deeply **Speak kindly.
> > *** Genuinely rich *** Faithful talent *** Sharing success
> >
> >
> >
> >
> > On Friday, June 19, 2020, 09:19:35 AM EDT, Adrian Klaver
> > <adrian(dot)klaver(at)aklaver(dot)com> wrote:
> >
> >
> > On 6/19/20 4:12 AM, Pepe TD Vo wrote:
> >  > thank you,   I tried that too, remove the quote around the echo and it
> >  > prompt for password, as I mentioned no matter I put -P mypassword no
> >  > matter what I spell out password=mypassword still argument error
> >
> > Once again -P has nothing to do with password. Also --password does not
> > take an argument, it is meant to be used as is. The purpose is to force
> > a password prompt. This is all spelled out here:
> >
> > https://www.postgresql.org/docs/12/app-psql.html
> >
> > Also spelled out in above is:
> >
> > " It is also convenient to have a ~/.pgpass file to avoid regularly
> > having to type in passwords. See Section 33.15 for more information."
> >
> > And Section 33.15:
> >
> > https://www.postgresql.org/docs/12/libpq-pgpass.html
> >
> > "The file .pgpass in a user's home directory can contain passwords to be
> > used if the connection requires a password (and no password has been
> > specified otherwise).  ..."
> >
> > Read more at link for how to do that.
> >
> >
> >  >
> >  >  >>echo select count(*) from tableA; | "C:\Program
> >  > Files\PostgreSQL\11\bin\psql" -U PSmasteruser -d PSCIDR -h
> >  > hostname.amazonaws.com -p 5432
> >  >
> >  >  >> echo select count(*) from tableA; | "C:\Program
> >  > Files\PostgreSQL\11\bin\psql" -U PSmasteruser -d PSCIDR -h
> >  > hostname.amazonaws.com -p 5432 password=mypassword
> >  >
> >  > all usernames are same password.
> >  >
> >  > thank you so much for all input.
> >  >
> >  > v/r,
> >  >
> >  > **
> >  > *Bach-Nga
> >
> > --
> > Adrian Klaver
> > adrian(dot)klaver(at)aklaver(dot)com <mailto:adrian(dot)klaver(at)aklaver(dot)com>
> >
> >
>
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message jim schmidt 2020-06-19 14:37:54 Re: Deleting more efficiently from large partitions
Previous Message Tom Lane 2020-06-19 14:14:02 Re: how to insert row with specific oid

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2020-06-19 14:52:54 Re: create batch script to import into postgres tables
Previous Message Adrian Klaver 2020-06-19 13:58:02 Re: create batch script to import into postgres tables