zwbetz-gh / zwbetz

My personal site
https://zwbetz.com/
MIT License
16 stars 5 forks source link

Problem on execute query from bash on Postgres #16

Closed barbatrukko closed 2 years ago

barbatrukko commented 2 years ago

I created file as you wrote on your article. Credential are the same used from a jar file running on the same server

psql: error: could not connect to server: FATAL: password authentication failed for user "myuser" FATAL: password authentication failed for user "myuser"

psql 12.4 on ubuntu 18.4.5

zwbetz-gh commented 2 years ago

I assume you followed this article?

https://zwbetz.com/connect-to-a-postgresql-database-and-run-a-query-from-a-bash-script/

In order to help you, you'll need to post your bash script file here. Otherwise I have nothing to work from.

zwbetz-gh commented 2 years ago

It’s also possible that your password has special characters that are being (unintentionally) interpreted by bash.

So in your .env file change this:

PGPASSWORD="some_password"

To use single quotes:

PGPASSWORD='some_password'

barbatrukko commented 2 years ago

Hi, yes this was the problem. In the password there is $ char. now I used ' instead of " and works

Tnx

zwbetz-gh commented 2 years ago

Glad to hear that worked.

I updated the articles to use single quotes https://github.com/zwbetz-gh/zwbetz/commit/208def8cbd275f61eb9c7d8f055e6ec786bedd3e

Closing this