How to set password in psql -h -d -U command line?

Started by Shaozhong SHIalmost 4 years ago5 messagesgeneral
Jump to latest
#1Shaozhong SHI
shishaozhong@gmail.com

I tried various ways to set password in psql command line, but got no luck.

Can anyone help?

Regards,

David

#2Karsten Hilbert
Karsten.Hilbert@gmx.net
In reply to: Shaozhong SHI (#1)
Aw: How to set password in psql -h -d -U command line?

I tried various ways to set password in psql command line, but got no luck.

Have you tried all the methods that you showed in your mail or did you try others as well ?

Best regards,
Karsten

#3Joao Ferreira gmail
joao.miguel.c.ferreira@gmail.com
In reply to: Shaozhong SHI (#1)
Re: How to set password in psql -h -d -U command line?

Hello,

I usually use this approach:

PGPASSWORD=secret psql -h 127.0.0.1 -p 5432 -U joao mydatabase

it has the down side that the password is shown in the command. need to be
careful about that aspect

On Thu, Apr 28, 2022 at 10:33 AM Shaozhong SHI <shishaozhong@gmail.com>
wrote:

Show quoted text

I tried various ways to set password in psql command line, but got no luck.

Can anyone help?

Regards,

David

#4Josha Inglis
joshainglis@gmail.com
In reply to: Shaozhong SHI (#1)
Re: How to set password in psql -h -d -U command line?

https://www.postgresql.org/docs/current/libpq-envars.html

Either set the PGPASSWORD environment variable or set up a .pgpass file

Josha

On Thu, 28 Apr 2022 at 19:33, Shaozhong SHI <shishaozhong@gmail.com> wrote:

I tried various ways to set password in psql command line, but got no luck.

Can anyone help?

Regards,

David

--
Kind Regards

Josha Inglis

#5alias
postgres.rocks@gmail.com
In reply to: Josha Inglis (#4)
Re: How to set password in psql -h -d -U command line?

Don't Do This - PostgreSQL wiki
<https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_psql_-W_or_--password&gt;

On Thu, Apr 28, 2022 at 3:13 PM Josha Inglis <joshainglis@gmail.com> wrote:

Show quoted text

https://www.postgresql.org/docs/current/libpq-envars.html

Either set the PGPASSWORD environment variable or set up a .pgpass file

Josha

On Thu, 28 Apr 2022 at 19:33, Shaozhong SHI <shishaozhong@gmail.com>
wrote:

I tried various ways to set password in psql command line, but got no
luck.

Can anyone help?

Regards,

David

--
Kind Regards

Josha Inglis