42501: INSUFFICIENT PRIVILEGE ERROR while querying in Postgresql

社会主义新天地 提交于 2019-12-08 17:02:28

问题


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.



来源:https://stackoverflow.com/questions/18193487/42501-insufficient-privilege-error-while-querying-in-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!