I just created a new user that I want to have access to a limited number of our public tables. The user is created and I granted privs to one public table for now. I then logged into the DB as that user and tried to run a SELECT on the table that the user should be able to get to but I must of missed a step or did something wrong because when I run the query I get:
relation [table] does not exist
Below are the steps I took, in order.
CREATE USER pqb2b WITH PASSWORD 'foo'
select * from pg_user;
usename | usesysid | usecreatedb | usesuper | usecatupd | passwd | valuntil | useconfig
----------+----------+-------------+----------+-----------+----------+---- |
postgres | 10 | t | t | t | ******** | |
pgb2b | 17267767 | t | f | f | ******** | infinity |
(1 rows)
GRANT ALL on b_users to pgb2b;
SELECT
schemaname||'.'||tablename
FROM
pg_tables
WHERE
has_table_privilege (
'pgb2b',
schemaname||'.'||tablename,
'select'
)
AND
schemaname NOT IN (
'pg_catalog',
'information_schema'
);
public.b_users
(1 row)
~ postgres$ psql -U pgb2b mydb
psql (9.0.3)
Type "help" for help.
mydb=> select * from b_users;
ERROR: relation "b_users" does not exist
LINE 1: select * from b_users;
mydb=> \d+ b_users
Did not find any relation named "b_users".
Note for others who may see this, though it may not apply to this particular question --
If you are not using the public schema, you need to update the search_path
SET search_path TO my_schema, public;
Credit: Why does PostgreSQL's \dt show only public schema tables?
Even though I was granting privileges to my pgb2b user, I forgot to specify usage for that user:
GRANT usage on schema public to pgb2b;
This fixed the issue. I found this post about setting up PostgreSQL user permissions very helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With