千家信息网

只有select权限也能锁表?read and select

发表于:2025-02-07 作者:千家信息网编辑
千家信息网最后更新 2025年02月07日,有个客户问我说,为啥只有select权限,也可以for update锁表。我懵了一下,不确认啊,我先测试了下,如下所示:create user test11 identified by test11;
千家信息网最后更新 2025年02月07日只有select权限也能锁表?read and select

有个客户问我说,为啥只有select权限,也可以for update锁表。

我懵了一下,不确认啊,我先测试了下,如下所示:

create user test11 identified by test11;

create user test12 identified by test12;

grant connect,resource to test11,test12;

create table test11.objects as select * from dba_objects;

grant select on test11.objects to test12;

会话1:

会话2:

可以看到,确实仅有可读的权限下,是可以for update的。

为啥可以for update,似乎不符合逻辑,点太小了,只能在官方文档那个上搜了,不得不夸一句,oracle官方文档真的详细。只能想着在官方文档上看看有没有线索,一查,发现还真有!

如下:

SELECT Query the table with the SELECT statement, including SELECT ... FOR UPDATE.

可以看到,select确实包含了 for update权限。

不一样的是,除了select之外,还有一个read表示查询,但是read不包含 for update。这个是12.1之后才有的变化。

READ Query the table with the SELECT statement. Does not allow SELECT ... FOR UPDATE.

Note: This privilege is available starting with Oracle Database 12 c Release 1 (12.1.0.2).

为啥select会有for update权限呢,可能是出于希望查询能够强制一致性的关系。

但这个其实对于大多数查询场景来说,for update的锁表权限还是太大了,所以在12.1开始,分离除了更小的read权限,用以满足客户需求。

0