2

1.when i apply this command in commandprompt it askes me to enter the password and i can perform all the action in database

psql -h localhost -p 5432 -U postgres -f test.sql newdb

2.but when i put this command,it shows me error " 'PGPASSWORD' is not recognized as an internal or external command, operable program or batch file."

PGPASSWORD=root psql -h localhost -p 5432 -U postgres -P root -f test.sql newdb
2
  • 1
    The error message sounds as if you are using Windows, however the syntax of the PGPASSWORD=root ... is for Linux Commented May 4, 2018 at 10:48
  • If the question is answered, then accept them. Commented May 4, 2018 at 12:39

2 Answers 2

2

Ashwin, The PGPASSWORD is not a command it is a system user/global variable which keeps your password stored for you. So, the "psql" command will not ask for password next time. Use the same command that you used early i.e. below one, to connect to database...

psql -h localhost -p 5432 -U postgres -f test.sql newdb

But, this time all you need to do is, set the global variable.

Windows system:

you can set this variable from Environment variable of system properties.

Linux system:

export PGPASSWORD=yourpassword

or, you can add this export inside the ".bashrc" file.

Sign up to request clarification or add additional context in comments.

4 Comments

i have actually used in windows.doesnt it support for windows or what i am not getting it?
Although this answers the OP's question, it's not secure. Use a PostgreSQL password file instead. (Search that linked page for "PGPASSWORD".)
Ashwin, here is the step by step to the setting/creating an environment variable in windows. Once the variable is created then close the old command prompt and open a new command prompt, then try to connect. It will work for you. helpdeskgeek.com/how-to/…
thnks alot vivek and mike :)
-1

Put your variables as:

 PGPASSWORD=%s pg_dump --host=%s --port=%s --username=%s %s -f %s

Change %s by your valid text.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.