USER_TS_QUOTAS视图、DBA_TS_QUOTAS视图、表空间权限关系


第一步、创建表空间jason,创建jason用户默认表空间位jason

create tablespace jason datafile'/home/oracle/orabase/oradata/ORACLE/jason01.dbf' size 100M autoextend on next 10M maxsize unlimited;
create user jason identified by jason defaulttablespace jason temporary tablespace temp;

授予connectdba权限(授予权限之后,系统默认授予用户unlimited tablespace权限)

grant connect to JASON;
grant dba to JASON;
SQL> select username,default_tablespacefrom dba_users where username='JASON';
USERNAME                       DEFAULT_TABLESPACE
------------------------------------------------------------
JASON                          jason
SQL> create table student as select *from dba_tables


第二步、创建表空间test,同时修改用户jason默认表空间为test表空间。


create tablespace test datafile '/home/oracle/orabase/oradata/ORACLE/test01.dbf'size 100M autoextend on next10M maxsize unlimited;
alter user jason default tablespace test;
SQL> select username,default_tablespacefrom dba_users where username='JASON';
USERNAME                       DEFAULT_TABLESPACE
------------------------------------------------------------
JASON                          test
SQL>

查看user_ts_quotas视图发现MAX_BYTES为零,MAX_BLOCKS为零。

SQL> select * from user_ts_quotas;
TABLESPACE_NAME                     BYTES  MAX_BYTES    BLOCKS MAX_BLOCKS DROPPED
------------------------------ -------------------- ---------- ---------- -------
JASON                              458752          0         56          0 NO

查看dba_ts_quotas视图不记录test表空间。

SQL> select * from dba_ts_quotas whereTABLESPACE_NAME='JASON';
TABLESPACE_NAME       USERNAME      BYTES  MAX_BYTES    BLOCKS MAX_BLOCKS DROPPED
SQL>


1、当用户拥有unlimited tablespace权限且原默认表空间存在数据对象时,更改用户默认表空间后,原默认表空间被记录于user_ts_quotas视图当中。MAX_BYTESMAX_BLOCKS为零,表示无空间配额,因拥有unlimited tablespace权限可无限制使用,但不记录于dba_ts_quotas视图中。

2、当撤销了unlimited tablespace权限后,只有使用alter user xxx quota [n/unlimited] on tablespace_name的方式来给某个用户授予某些表空间的使用权限,即使是该用户的默认表空间也无法使用。

3、只要使用了alter user xxx quota [n/unlimited] on tablespace_name命令都会记录到user_ts_quotas视图当中,不管n0还是其它值,但只有当n=0时,在dba_ts_quotas视图中看不到记录,非零值才会记录到dba_ts_quotas视图当中(0值表示在该表空间上无空间配额,但只要具有unlimited tablespace权限就可以无限使用表空间)。

4、关于DROPED字段的含义是这样的:当表空间被删除,user_ts_quotas也会显示出来,例如

SQL> select * from user_ts_quotas;
TABLESPACE_NAME                     BYTES  MAX_BYTES    BLOCKS MAX_BLOCKS DROPPED
------------------------------ -------------------- ---------- ---------- -------
JASON                                   0   10485760          0       1280 YES
SQL> create tablespace jason datafile'/home/oracle/orabase/oradata/ORACLE/jason01.dbf' size 100M reuse autoextend on next 10M maxsize unlimited;
SQL> select * from user_ts_quotas;
TABLESPACE_NAME                     BYTES  MAX_BYTES    BLOCKS MAX_BLOCKS DROPPED
------------------------------ ---------- -------------------- ---------- -------
JASON                                   0   10485760          0       1280 NO
SQL>

当删除了jason表空间后,dropped的值是yes,当重新创建了jason表空间后发现配额限制继续生效,即使将用户的默认表空间设为jason表空间,配额限制依然生效.

DBA_TS_QUOTAS describes tablespace quotas for the current user. USER_TS_QUOTAS view does not display the USERNAME column.

ColumnDatatypeNULLDescription
TABLESPACE_NAMEVARCHAR2(30)NOT NULLTablespace name
USERNAMEVARCHAR2(30)NOT NULLUser with resource rights on the tablespace
BYTESNUMBER
Number of bytes charged to the user
MAX_BYTESNUMBER
User's quota in bytes, or -1 if no limit
BLOCKSNUMBERNOT NULLNumber of Oracle blocks charged to the user
MAX_BLOCKSNUMBER
User's quota in Oracle blocks, or -1 if no limit
DROPPEDVARCHAR2(3)
Whether the tablespace has been dropped