Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres permission denied for relation <table>

I'm trying to learn Postgres and Ive made two basic tables and I can't join them together.

here is my list Of relations:

 Schema |     Name     |   Type   |  Owner
--------+--------------+----------+----------
 public | login        | table    | postgres
 public | login_id_seq | sequence | postgres
 public | users        | table    | test
(3 rows)

When I use the command

SELECT * FROM users JOIN login ON users.name = login.name;

I get

ERROR: permission denied for relation login

I have no idea what to do or what I did wrong.

like image 283
Joe Escobedo Avatar asked Mar 16 '18 05:03

Joe Escobedo


1 Answers

You should grant the SELECT permission to user test:

GRANT SELECT ON login TO test;

If if might allow test to modify login, you should grant other permissions as well:

GRANT SELECT, INSERT, UPDATE, DELETE ON login TO test;

You should execute these statements as database owner or as user postgres. In general, you can use

psql -Upostgres -dtest

if you're running this command on the same machine where the Postgres server is running.

You may also change the ownership of login to test:

ALTER TABLE login OWNER TO test;
ALTER SEQUENCE login_id_seq OWNER TO test;

But have to execute this as user postgres as well.

Edit: You can try to change the user with

SET ROLE 'postgres';

as suggested by @lat long.

like image 65
clemens Avatar answered Sep 26 '22 03:09

clemens