GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly;
readonly用户可以连接,查看表,但是当它试图做一个简单的选择它获得:
ERROR: permission denied for relation mytable sql state: 42501
这是发生在Postgresql 9.1上
我做错了什么?
这里是Postgresql 9的完整解决方案,最近更新。
CREATE USER readonly WITH ENCRYPTED PASSWORD 'readonly'; GRANT USAGE ON SCHEMA public to readonly; ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly; -- repeat code below for each database: GRANT CONNECT ON DATABASE foo to readonly; \c foo GRANT USAGE ON SCHEMA public to readonly; GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO readonly; GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly;
感谢http://jamie.curle.io/creating-a-read-only-user-in-postgres/几个重要方面