Postgres on Manjaro

I feel like the newbie corner is my home on these forums, there's so much to learn :slight_smile:

I just ran which psql and I got:

/usr/bin/psql

As far as I know /usr/bin/ is where all installed programs usually sit, so I thought to myself, cool, I should be able to just run psql, but I was wrong. I got:

➜  ~ psql
psql: error: could not connect to server: FATAL:  role "jwan" does not exist

I know the server is running, because I ran sudo systemctl status postgresql and it tells me it is Active (running).

I suspect when I run psql certain assumptions are being made on my behalf and I've no idea what those are. Can you please tell me?

The narrative I had in mind was:

  1. connect to postgres
  2. run a command to see what databases I have
  3. pick a database and connect to it, or create a new database

Is the above narrative "valid"?

You can, and you did run it successfully.

This looks like the program was executed but you encountered a rights/permissions issue within postgres.

Unless someone with more postgresql experience comes along you might want to read up on how roles and permissions work within postgres.

Also, you might take a look at the graphical tool pgadmin4

1 Like

A very easy way to solve this problem is to run sudo su postgres, so you can use the user postgres. This user should have access to your postgres cluster, so you can run psql again. Personally, my standard user account doesn't need access to my postgres cluster. So I change to the user postgres or I create a specific role for my programs, if they need access to the cluster.

From postgres, you can create new roles with specific access rights. I recommend the postgres documentation.

1 Like

you need to tell the psql command to which database and server it should connect to.
from man psql:
psql [option...] [dbname [username]]

Thanks @LeaRain, is sudo necessary here? I thought to switch to a user, we did su - postgres?

I guess this depends on the user configuration, my postgres user doesn't accept a password. sudo -u postgres psql is also a possibility, if you don't want to use the su part.

su - postgres switches to the user postgres. If you run it as a normal user, you will be prompted for the password to the postgres account.

sudo su - postgres runs su - postgres as root which bypasses the need to enter postgres's password

sudo -u postgres <command> runs command as the user postgres.

3 Likes

Thank you, you're right!

On linux can a user exist without a password? The reason I ask is because I don't remember ever setting a password for the postgres user when I installed PostgreSQL

yes, it can exist without a password.

It is also possible something set the password for you.

The former is more likely.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

Forum kindly sponsored by