postgreSQL: grant select on all tables in schema FOO to FOOROLE - database-schema

EDIT: Found it. I thought USAGE was an explanation, not a key word. :-)
What else must occur in addition to
GRANT SELECT ON ALL TABLES IN SCHEMA FOO to FOOROLE
in order for FOOROLE to be able to select from, say, FOO.CUSTOMER? Is there some general schema-access privilege that must also be granted?
FOOROLE was created with LOGIN and can log into the database, but is being denied:
ERROR: permission denied for schema foo
LINE 1: select * from foo.customer
********** Error **********
ERROR: permission denied for schema foo
SQL state: 42501
Character: 15 (caret points to the first character of "foo")

USAGE is the generic permission I was seeking.

Related

How to query the role assigned to table in Redshift? ( & roles assigned to user, permission to role )

I have provisioned the redshift Serverless workspace. I have created sample tables, roles and user. Assigned permission to roles and roles to table. all working fine as accepted. I have to fetch the roles and permission via SQL query . seems like redshift do not give permission to query following key tables like
select * from pg_role;
ERROR: permission denied for relation pg_role [ErrorId: 1-62b24d6a-2506f055101eddb375a1614c]
similar
SELECT user_name,role_name,admin_option FROM svv_user_grants;
ERROR: permission denied for relation svv_user_grants [ErrorId: 1-62b24e36-77998cd06d89764f40fb5589]
SELECT role_name,role_owner FROM svv_roles
ERROR: permission denied for relation svv_roles [ErrorId: 1-62b24e4d-68d1bd5866d49a653339e204]
results for this query is always empty
select * FROM information_schema.role_table_grants
Wondering if someone know how to query users(s) assign to roles and those roles to tables ( plus roles permission like select / update etc ).
thanks !
To get table-level role access details, you can use svv_relation_privileges view. As you can see output is below.
select * from svv_relation_privileges WHERE namespace_name = 'security_testing'

Grant privileges on tables in other database

Context
I want to grant privileges to a specific user, on the public schema in database mydb.
Currently, I connect as user postgres on database mydb, and run :
GRANT insert, update, delete, truncate ON ALL TABLES IN SCHEMA public TO myuser
My Issue
I would feel more comfortable naming the target database in the query, rather than relying on the connection being on the correct database.
For example, I wouldn't want to accidentally give accesses on the postgres database, rather than on mydb.
Question
Is there a way to target tables in another database in a GRANT query ?
I couldn't find a way to do so in the doc (perhaps I overlooked a paragraph ?) and the following do not work :
# grant insert on all tables in schema mydb.public to myuser;
ERROR: syntax error at or near "."
LINE 1: grant insert on all tables in schema mydb.public to...
^
# grant insert on mydb.public.mytable1 to myuser;
ERROR: cross-database references are not implemented: "mydb.public.mytable1"
No, as the error message says, cross-database references are not implemented.
This is a security feature: There is no way to affect another database than the one you are connected to with an SQL statement (unless you are using something like dblink or foreign data wrappers).

Have access to table and function, but not the table within the function

I ran into a peculiar problem with my database that I haven't been able to solve since yesterday.
So I created a user that has access to the function "write_match_history()" and access to the table "match_history," and I can use this user to query match history as well as write to it directly using sql. However, when I try to run "write_match_history," I get the following error:
error: error: permission denied for relation match_history
Here are the accesses I've granted to this user:
drop OWNED by d_write;
drop user if exists d_write;
create user d_write with encrypted password 'supersecret';
grant execute on function write_match_history(a,b,c,d,e,f) to d_write;
grant usage on schema d to d_write;
grant insert on table d.match_history to d_write;
grant select on table d.match_history to d_write;
grant select on all SEQUENCES in SCHEME d to d_write;
grant insert on all tables in schema d to d_write;
grant select on all talbes in schema d to d_write;
These permissions are everything I've tried so far. Let me know if you need more information.
Thanks!
Well, what is the owner of the function write_match_history(a,b,c,d,e,f). Do it allow to insert/update on table match_history. If not, please try it. I think the problem is here.

Permission denied on schema in PostgreSQL

I can't find why I am getting an permission denied error in my database.
The role owns the schema and has access to the table, but still the log says:
ERROR: permission denied for schema myschema at character 20
QUERY: SELECT 1 FROM ONLY "myshema"."mytable" x WHERE "id" OPERATOR(pg_catalog.=) $1 FOR KEY SHARE OF x
There is a foreign key in a table referring to a table in the schema in question, to which the table owner role does not have permission. Foreign key checks are done with the permissions of the role that own the table, not the role performing the query.
The query is actually doing the internal foreign key check.
Found an explanation on sharingtechknowledge.blogspot.fi

pgAdmin error - relation "[name of function/Views/Trigger Functions]" does not exist

I'm just new to pgAdmin, so I don't really know what causes these errors:
ERROR: relation "ongoingprojects" does not exist
LINE 1: SELECT * FROM ongoingProjects;
^
********** Error **********
ERROR: relation "ongoingprojects" does not exist
SQL state: 42P01
Character: 15
Even if the function/view exists in the schema. Why does it give that error? And what should I do to fix it?
Pay careful attention to the error message:
ERROR: relation "ongoingprojects" does not exist
Note that it is complaining about ongoingprojects when your SQL talks about ongoingProjects. You probably created the table with something like:
create table "ongoingProjects" ( ...
PostgreSQL folds all identifiers (table names, column names, ...) to lower case unless they are double quoted. Once you've created the table as "ongoingProjects", you'll have to double quote the name everywhere and exactly match that case:
select * from "ongoingProjects";
The usual practice with PostgreSQL is to create tables with unquoted names in lower case with word separated using underscores:
create table ongoing_projects ( ...
so that you don't have worry about quoting.
Here is the link to the relevant part of the manual
For me the issue was having a schema named differently than the database.
Two solutions:
1) Modify schema name to match db name
or
2) Prepend table in query with schema name, eg: SELECT * FROM my_schema.ongoingProjects;