42501: INSUFFICIENT PRIVILEGE ERROR while querying

2019-06-16 20:57发布

问题:

I am trying to query a database table in postgresql, but every time I run the below query it gives me the INSUFFICIENT PRIVILEGE error. What possibly could be the reason for such permission denied error. Also, I am using pgadmin tool in windows to connect the database which is in Linux environment. Below is the query I am running

> > SELECT appid,hash 
>       FROM app
>       WHERE appid=1;

While running the same query I am getting the below Error

ERROR:  permission denied for relation app

********** Error **********

ERROR: permission denied for relation app
SQL state: 42501

回答1:

The user running the query will need permissions to that table. You can grant them to that user with the GRANT statement. The below is an example that grants to PUBLIC

GRANT SELECT ON tablename TO PUBLIC;

Also I have seen SELinux cause isses and places such as here mention it. I am not exactly sure of the command to turn SELinux off but you can see if it is running by using

selinuxenabled && echo enabled || echo disabled


回答2:

It simply means that you have no permission to access app table. Request your root or database administrator to grant you the permission to access app table. if your are the root or have granting privilege you can use grant command to grant your self permission to use all sql statements on table or database
For Example:

               grant all privileges on database money to cashier;


before that you have to login as root or user that have granting privileges
for more details on this command refer to http://www.postgresql.org/docs/8.1/static/sql-grant.html



回答3:

If it's DB2 then go to command console of DB2, select your respective Database and select Authorities option by right click on the Database then add your respective DB2 user and grant required access.