Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Case: a read-only role directly has read-only access to newly created tables under a schema without separate authorization.

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Case: a read-only role directly has read-only access to newly created tables under a schema without separate authorization.

First of all, you need to know that the newly created table under the default schema of PostgreSQL will not have the permission of select for an ordinary user, so I need to modify the default permission of PostgreSQl to give select to ordinary users in advance. I need to use the command alter default privileges.

Session1 (user:postgres):

# psql

Create role role1 password '123456' login

Create schema schema1

Grant usage on schema schema1 to role1

Testdb=#\ dn+ schema1

List of schemas

Name | Owner | Access privileges | Description

-+-

Schema1 | postgres | postgres=UC/postgres+ |

| | role1=U/postgres |

Alter default privileges in schema schema1 grant select on tables to role1

Testdb=#\ ddp+

Default access privileges

Owner | Schema | Type | Access privileges

-+-

Postgres | schema1 | table | role1=r/postgres

Create table schema1.t1 (C1 int,c2 varchar (10))

Insert into schema1.t1 values (1 recorder aaaa')

Testdb=#\ dp+

Access privileges

Schema | Name | Type | Access privileges | Column privileges | Policies

-+-

Schema1 | T1 | table | postgres=arwdDxt/postgres+ | |

| | role1=r/postgres | | |

Session2 read_only:

# psql-h 172.16.101.54-p 5432 testdb role1

Testdb= > select * from schema1.t1

C1 | c2

-- +-

1 | aaa

(1 row)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report