psql command at prompt. (postgresql database)

Asked

Viewed 14,274 times

2

Good morning, everyone,

I’m trying to make a script with extension. bat to make automatic update in the bank,.

I am doing as follows to access my bank through windows pronpt. psql -U bank user -w bank password

but I get the following message fe_sendauth:no passoword supplied

OBS:I know that when typing( psql -U user of the bank ) it asks for the password but, this is exactly what I want not to appear. I want to enter the password by command. inserir a descrição da imagem aqui

5 answers

3

Always came the password question postgres in my examples also...

So in my .BAT created a line with the following command:

SET PGPASSWORD=postgres

(password of my example is postgres, did not need quotes or anything...)

after that, I added a new line in . bat to execute the command I needed as follows, and did not ask me password:

echo on
C:\"Program Files"\PostgreSQL\9.5\bin\psql.exe -h LOCALHOST -U postgres -d nomedabasedados -c "Update nometabela  set dt_atualizacao = LOCALTIMESTAMP where cod_oper = %OPERADORA% " 

3


Create a password file containing a line as

*:*:teste:postgres:senha

The file has to be %APPDATA%\postgresql\pgpass.conf

To find out which directory %APPDATA% type in the prompt:

echo %APPDATA%
  • That’s exactly it but I still don’t understand how to do it and how to use it. It could be clearer

  • @thiagoxavier After you create the file you will no longer need to enter the password. You don’t need to do anything. What exactly didn’t you understand? How to create the file?

  • Yes, it is the block structure in the case I did so: *:*localhost:5432:test:postgres:123 following the structure Hostname : port : database : username : password but when I go to the prompt and type psql -U postgres it still asks for the password I am editing the txt file that is in folder C: Users Thiago Appdata Roaming postgresql

  • @thiagoxavier Use the line exactly as I posted.

  • thanks thanks worked out. I’m sorry I didn’t understand before

1

Add -w as follows:

psql -d mydb -U myuser -W
  • but if I type the way it is there will be asked password.I want to know if you have a command that passes the password and it runs straight without showing the message "password for postgres user".

  • add to your command the "-W"

  • I did so but still ask for the password. I also put -w password. I edited the document just above

0

Update the pg_hba.conf file, add the line

"host all postgres 127.0.0.1/32 trust"

So your local host connection with the postgres user will not ask for password

O -W force ask password, it does not help you at all.

For min this change worked.

Plus if you’re using a . bat to connect, you can add the following variables to your script

This makes the script not ask user

set PGUSER=postgres

This makes the script not ask for password

set PGPASSWORD=postgres

-2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.