Asked by:
When running psql with powershell sits and asks for password

Question
-
Hi There,
Does anyone knows how to fix this here's my example code.
It just waits for password when I run the powershell script.
ps1 script content:
$DBPort='5659'
$DBName='postgres'
$DBUser='User1'
$psqlEx='f:\pgAdmin 4\v4\v4\psql.exe'
$PGPASSWORD='Q%MYVdoX9^9iJ2QrNs$$-!]'
[string] $DBHost='localhost'
$DBSql="select usename from pg_user "
& .\psql.exe -h $DBHost "-U $DBUser" "-p $DBPort" "-c $DBSql" > .\output.csvAlso I've noticed that the password is not passed correctly because of the special characters so I guess those needs to be escaped somehow.
Thank you
Wednesday, March 25, 2020 7:55 PM
All replies
-
Please ask PostGres questions in a PostGres forum.
.\psql.exe -h $DBHost -U $DBUser -w -p $DBPort -c $DBSql
\_(ツ)_/
- Edited by jrv Friday, March 27, 2020 12:09 AM
Wednesday, March 25, 2020 8:38 PM -
Thanks for the replay..
I tough it was a Powershell question.
-W doesn't work, still promts for password.
Thursday, March 26, 2020 2:25 PM -
Thanks for the replay..
I tough it was a Powershell question.
-W doesn't work, still promts for password.
\_(ツ)_/
Thursday, March 26, 2020 3:13 PM -
-w --no-password Never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a .pgpass file, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password. -W --password Force psql to prompt for a password before connecting to a database.
https://w3resource.com/PostgreSQL/connect-to-postgresql-database.php
YOU must ask psql questions in a PostGres forum. To avoid prompts for a password you must configure your system correctly.
\_(ツ)_/
Friday, March 27, 2020 12:09 AM -
Friday, March 27, 2020 12:11 AM