lapots
lapots

Reputation: 13395

set user and password for `psql`

What is the correct way to run .sql script using psql?

When I do like this

psql D:\scripts\script.sql

It requires password. I pass my db password pass but it shows error

password authentication failed for user PC_ADMIN

(i.e. my windows user). But my db user has the name postgres.

How to set in command psql D:\scripts\script.sql\ user and password?

Upvotes: 0

Views: 190

Answers (2)

Rahul Tripathi
Rahul Tripathi

Reputation: 172378

Try like this:

psql -U username -d myDataBase -a -f script.sql

Upvotes: 1

serakfalcon
serakfalcon

Reputation: 3531

you have to send the user flag to the script,

psql D:\scripts\script.sql -U whateveruser

OR

psql D:\scripts\script.sql --username=whateveruser

otherwise it will assume that the user is the current OS account.

Upvotes: 1

Related Questions