postgres, psql and a bat file

I'm going around in circles and so need some help.

I want to be able to run an .sql against a database which is a scheduled task via a bat file. However when i run the bat file manually I get prompted for a password. I enter the password and then get told that....

"psql: FATAL: password authentication failed for user "(my windows login)"
'-h' is not recognised as an internal or external command, 
operable program or batch file. 

At the moment my bat reads...

@echo off
"D:\Program Files (x86)\PostgreSQL\9.1\bin\psql.exe"
-h localhost -U postgres -d database_name -f D:/scripts/SQL/test.sql
pause

First thing, what cmd do i need to add to populate the password request

What am I doing wrong with the rest of the statement to get it to load the .sql

Thanks

Answers


by adding this line to your config file (pg_hba.conf), you can tell postgres to allow local connections without authentication

local      <database>  <user>  trust

http://www.postgresql.org/docs/9.1/static/auth-pg-hba-conf.html


All that needs to go into a single line in your batch file (it seems you have two lines):

@echo off
"D:\Program Files (x86)\PostgreSQL\9.1\bin\psql.exe" -h localhost -U postgres -d database_name -f D:/scripts/SQL/test.sql
pause

To avoid the password prompt, set the environment variable PGPASSWORD before calling psql:

@echo off
setlocal
set PGPASSWORD=my_very_secret_password
"D:\Program Files (x86)\PostgreSQL\9.1\bin\psql.exe" -h localhost -U postgres -d database_name -f D:/scripts/SQL/test.sql
pause
endlocal

The setlocal/endlocal commands are there to make sure the variable is cleared after the batch file was executed.

To avoid having the password in plain text in the batch file you can create a pgpass.conf file that contains the password. For details please see the manual: http://www.postgresql.org/docs/current/static/libpq-pgpass.html


Need Your Help

Creating a custom UIScrollView Scroller

iphone objective-c ios xcode

Okay, I have been all over the internet trying to find the answer to this, I am trying to create a custom UIScrollView scroller.

How to get remote machine OS version in .Net, without WMI?

c# .net

Is there any way to get OS version of remote machine in .Net(C#)?