Skip to main content

PostgreSQL Grant Privileges To a Role

Hi all,

If you have lots of user and table/schema on your database you can not give permission per table but you can follow this steps. It's gonna be manual process but sometimes you can not give whole privileges on entire schema in your databases to users/roles. So, in that case you should generate your scripts.

GRANT SELECT ON ALL TABLES IN SCHEMA schema_name TO your_role;
GRANT USAGE ON SCHEMA schema_name TO your_role;
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA schema_name TO
your_role;


If you don't want to give all privileges and make specific for users also you can generate a sql script for whole schema for user or your all users like;

Generate GRANT script for granting privileges whole schemas for a role;
SELECT DISTINCT 'GRANT SELECT ON ALL TABLES IN SCHEMA '|| schemaname || 'TO user_role;' FROM pg_stat_user_tables;

Generate USAGE script for whole schemas;
SELECT DISTINCT 'GRANT USAGE ON SCHEMA '|| schemaname || 'TO user_role;' FROM pg_stat_user_tables;

You may want to executing privileges on whole functions;
SELECT DISTINCT 'GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA '|| schemaname || 'TO user_role;' FROM pg_stat_user_tables;

Or you can type script bellow for functions, it's gonna be fine.

SELECT DISTINCT 'GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA '|| schemaname ||' TO '|| rolname || ';' from pg_stat_user_tables, pg_roles;

Other way, you prefer to grant all privileges based on database, so you can use bellow script;

GRANT ALL PRIVILEGES ON DATABASE databasename TO your_role;


Loves,

Comments

Popular posts from this blog

PostgreSQL ile Logical Replication Slot

Logical Replication Slot   Logical Decoding Replication Slot yazısına buradan ulaşabilirsiniz. Giriş bilgisi bu yazıda yer almaktadır.  Logical Replication, logical decoding kullanır. Logical decoding, veritabanı tabloları üzerinde commit edilmiş processlerin karşı tarafa row-by-row aktarılmasıdır. Oluşturulan her bir slot sadece bir veritabanı için kullanılabilir. Bir veritabanında birden fazla birbirinden bağımsız slot oluşturulabilir. Logical replication Slot'lar alıcı tarafla ilgili herhangi bilgiye sahip olmadıkları için yukarıda bahsettiğim disk size'ının dolması durumunun yaşanması kontrol edilmeyen bir sistemde kaçınılmaz olacaktır. Unlogged veya temp tables slot ile karşı tarafa aktarılmadığı unutulmamalıdır. Logical Replication kullanılmadan önce wal_level=logical olarak set edilmeli ve max_replication_slots değeri en az 1 olarak set edilmeli. Logical Replication Slot oluşturulması Physical Replication Slot ile benzerdir. Logical Replication Slo...

Collapsible Group Box in Peoplesoft Pages

Hello, With using collapsible Group boxes you can minimize all fields and free up space in your pages. If your page has lots of field and you can make it understandable. Before use it, you should decide to where you want to use Collapsible Group Boxes. In your page; Add a new group box which include your fields that you want to hide or show all of them. Double click head of group box and open Group Box Properties. Give a name for group box's label in Label tab.

ORA-02429

I created some indexes for a table. When I try to delete index which belong to that table, I got error ORA-02429.  To overcome with this issue I did something as bellow; alter table TABLE_NAME drop constraint INDEX_NAME; drop index INDEX_NAME; Loves,