postgresql只有owner或usersuper权限才能修改表结构或drop表

官方文档的一段说明
For most kinds of objects, the initial state is that only the owner (or a superuser) can do anything with the object.
The right to modify or destroy an object is always the privilege of the owner only.
对于大多数类型的对象,初始状态是只有所有者(或超级用户)可以对对象执行任何操作。
修改或销毁对象的权利始终只是所有者的特权。

表s1.u1_table的owner是u1,用户postgres是超级管理员,用户u2拥有表s1.u1_table的所有权限和schema s1的所有权限,用户u2都无法修改该表的表结构或drop该表,只有超级管理员或s1.u1_table的owner才能修改该表的表结构或drop该表

t1=> \c
You are now connected to database “t1” as user “u1”.
t1=> create table s1.u1_table(hid int);
CREATE TABLE
t1=> \c - postgres
You are now connected to database “t1” as user “postgres”.
t1=# select usename,usesuper from pg_user where usename=‘postgres’;
usename | usesuper
----------±---------
postgres | t
t1=# select * from pg_tables where tablename=‘u1_table’;
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity
------------±----------±-----------±-----------±-----------±---------±------------±------------
s1 | u1_table | u1 | | f | f | f | f
t1=# create user u2 password ‘123456’;
CREATE ROLE
t1=# grant all privileges on schema s1 to u2;
GRANT
t1=# grant all privileges on table s1.u1_table to u2;
GRANT
t1=# \c - u2;
You are now connected to database “t1” as user “u2”.
t1=> alter table s1.u1_table add hid2 int;
ERROR: must be owner of table u1_table
t1=> drop table s1.u1_table;
ERROR: must be owner of table u1_table
t1=> \c - postgres
You are now connected to database “t1” as user “postgres”.
t1=# alter table s1.u1_table add hid2 int;
ALTER TABLE
t1=# drop table s1.u1_table;
DROP TABLE

你可能感兴趣的:(postgres,postgresql)