0

I'm trying to connect to a postgres database from outside the psql command line (so before doing sudo -u postgres psql) but it seems that I'm not able to pass authentication. Here's the error after I try to run a script that connects to that database from the command line:

error: password authentication failed for user "bobby"

"bobby" is my Operating System user name, I noticed that the postgres database contains a superuser called postgres though

I'm new to all this postgres stuff so I'm a bit confused why it's trying to authenticate using my OS user name rather than my psql user name, or rather how I would go about authenticating using the psql user name rather than my OS user name because I know they're separate from each other.

Any help would be appreciated. Thanks in advance.

user3226932
  • 2,042
  • 6
  • 39
  • 76

1 Answers1

0

You need to add your system user name to posgres database

$ psql -d template1 -U postgres
template1=# CREATE USER bobby WITH PASSWORD 'myPassword'
template1=# CREATE DATABASE mydatabase
template1=# GRANT ALL PRIVILEGES ON DATABASE mydatabase to bobby

Done and quit

Then you can access the database with

bobby=#psql mydatabase
Jerry Chen
  • 715
  • 7
  • 21