0

I have seen all the questions here on stackoverflow about similar topic, but I would like to know why this happens, where is the problem, and what to do to set it up correctly. I am learning to code, so I apologize for any misunderstandings. Please, have patience with me.

My case is -

I cannot run psql command from terminal.

Respond is -

psql: FATAL:  role "some_name" does not exist

after I write down and hit enter -

sudo -u postgres -i

everything just works and I can run psql command. I need to write sudo -u postgres -i command every time I open terminal, again and again.

I would like to kindly thanks to any respond.

If you got more questions I can give you more information.

Here see some additional info:

[postgres@localhost ~]$ psql
psql (9.6.6)
Type "help" for help.

postgres=# \du
                                   List of roles
 Role name |                         Attributes                         | Member
 of 
-----------+------------------------------------------------------------+-------
----
 matus     |                                                            | {}
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

Another:

[postgres@localhost ~]$ whoami
postgres

So, I have two opened terminals, one as postgres and another as user_name where I can do other stuff, using db somehow.

Vao Tsun
  • 47,234
  • 13
  • 100
  • 132
Matthew
  • 33
  • 6
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Jan 10 '18 at 03:30

1 Answers1

1

from your description I suppose you have peer authentication in hba file. To check it connect to db with psql (your sudo -u postgres method) and:

t=# show hba_file ;
      hba_file
---------------------
 /pg/d10/pg_hba.conf
(1 row)
t=# \! grep local /pg/d10/pg_hba.conf | grep -v "#"
local   all             all                                     peer

if you see peer above trust, or just peer, than this is the case. from manuals:

https://www.postgresql.org/docs/current/static/auth-methods.html#AUTH-PEER

The peer authentication method works by obtaining the client's operating system user name from the kernel and using it as the allowed database user name (with optional user name mapping)

formatting mine.

so in order to avoid

psql: FATAL: role "some_name" does not exist

just create such db user:

create user some_name;

or change peer to trust in hba.conf

Vao Tsun
  • 47,234
  • 13
  • 100
  • 132
  • thank you very much, I have changed authentication to `trust`, but the other problem was that i created user/role manually in postgres, and it was not the same name as default user name in the OS, so I used `ALTER USER user RENAME TO new_name_of_user;` to have name of user in postgres the same as default in the OS, and than grant him some `PRIVILEGES`. – Matthew Jan 10 '18 at 12:35