1

Someone created a database and I am a super user in PG Admin. When I tried to access the database tables by clicking on it, I received the error message "permission denied for relation table_name". It's a table for the Mayan database. I tried all kinds of methods, but I am unfamiliar with this and not sure how to go about doing it. I opened the SQL editor and entered the GRANT commands to grant myself access, but I keep getting "permission denied". I am using PG Admin.

Can anyone tell me how can I be granted access to the table?

Steve Piercy
  • 13,693
  • 1
  • 44
  • 57
Cherple
  • 725
  • 3
  • 10
  • 24
  • Can you share what GRANT commands you have tried? – dave_slash_null Aug 14 '17 at 16:39
  • Removed angle brackets around "table_name" because SO does not render them inline unless it is code. Improved grammar. – Steve Piercy Aug 14 '17 at 20:57
  • maybe I am doing it wrongly, im not sure. I opened PG Admin, clicked on the database, on the tool bar I selected the SQL icon where I can enter SQL statements, and entered this: "GRANT ALL PRIVILEGES ON DATABASE mayan TO myuser". It responded saying no priviledges were granted for "mayan". – Cherple Aug 15 '17 at 07:44

1 Answers1

3

To access a table you have to grant privileges to the tables with GRANT. First enter to the database and open a SQL editor then execute one of the next queries:

-- For all privileges
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO user

-- For viewing privileges
GRANT SELECT ON ALL TABLES IN SCHEMA public TO user

Note that you have to specify the schema.

Dan
  • 1,771
  • 1
  • 11
  • 19
  • I selected the database.. open sql editor.. entered either of the mentioned statement.. I get the error "ERROR: permission denied for relation django_migrations. SQL state: 42501" – Cherple Aug 16 '17 at 06:36
  • Are you using django? or other platforms? 'cause, using pure postgres won't give you that error. If so... perhaps you should see documentation about the platforms you're using. For some info in Django with postgress [enter here](https://stackoverflow.com/a/42050358/8379001) – Dan Aug 16 '17 at 16:14