Oracle用户对表空间配额(quota)配置过程与配额说明

教程发布:风哥 教程分类:ITPUX技术网 更新日期:2022-02-12 浏览学习:55

[color=rgb(75,75,75)]Oracle用户对表空间配额(quota)配置过程与配额说明
[color=rgb(75,75,75)]一. 官网的说明
[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)]Oracle 官网对quota的定义如下:[color=rgb(75,75,75)] A limit on a resource, such as a limit on the amount of database storage used by a database user. A database administrator can set[color=#1a8bc8]http://download.oracle.com/docs/cd/E11882_01/win.112/e10845/glossary.htm#i432555]tablespace quotas for each Oracle Database [color=#1a8bc8]http://download.oracle.com/docs/cd/E11882_01/win.112/e10845/glossary.htm#i432581]username.
[color=rgb(75,75,75)] [color=rgb(75,75,75)]有关Oracle Quota 这块,只在Oracle 的安全管理这块搜到了一些内容。[color=rgb(75,75,75)] Managing Security for Oracle Database Users[color=rgb(75,75,75)] [color=#1a8bc8]http://download.oracle.com/docs/cd/E11882_01/network.112/e16543/users.htm#DBSEG10220]http://download.oracle.com/docs/cd/E11882_01/network.112/e16543/users.htm#DBSEG10220

[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)]1.1 Assigning a Tablespace Quota for the User[color=rgb(75,75,75)] You can assign each user a tablespace quota for any tablespace (except a temporary tablespace). Assigning a quota accomplishes the following:[color=rgb(75,75,75)](1)Users with privileges to create certain types of objects can create those objects in the specified tablespace.[color=rgb(75,75,75)](2)Oracle Database limits the amount of space that can be allocated for storage of a user's objects within the specified tablespace to the amount of the quota.[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)] By default, a user has no quota on any tablespace in the database. If the user has the privilege to create a schema object, then you must assign a quota to allow the user to create objects. At a minimum, assign users a quota for the default tablespace, and additional quotas for other tablespaces in which they can create objects.[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)] The following CREATE USER statement assigns the following quotas for the test_ts and data_ts tablespaces:[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)]CREATE USER jward[color=rgb(75,75,75)] IDENTIFIED BY password[color=rgb(75,75,75)] DEFAULT TABLESPACE data_ts[color=rgb(75,75,75)] QUOTA 100M ON test_ts[color=rgb(75,75,75)] QUOTA 500K ON data_ts[color=rgb(75,75,75)] TEMPORARY TABLESPACE temp_ts[color=rgb(75,75,75)] PROFILE clerk;

[color=rgb(75,75,75)] [color=rgb(75,75,75)][color=darkorchid] [color=rgb(75,75,75)][color=purple]-- [color=purple]在创建用户的时候,就指定用户在特定表空间上的配额[color=rgb(75,75,75)] [color=rgb(75,75,75)] You can assign a user either individual quotas for a specific amount of disk space in each tablespace or an unlimited amount of disk space in all tablespaces. Specific quotas prevent a user's objects from using too much space in the database.

[color=rgb(75,75,75)] [color=rgb(75,75,75)]-- 配额的指定可以禁止用户的对象使用过多的表空间[color=rgb(75,75,75)] [color=rgb(75,75,75)] You can assign quotas to a user tablespace when you create the user, or add or change quotas later. (You can find existing user quotas by querying the USER_TS_QUOTAS view.) 。[color=rgb(75,75,75)] [color=rgb(75,75,75)] If a new quota is less than the old one, then the following conditions remain true:[color=rgb(75,75,75)] [color=rgb(75,75,75)] (1)If a user has already exceeded a new tablespace quota, then the objects of a user in the tablespace cannot be allocated more space until the combined space of these objects is less than the new quota.[color=rgb(75,75,75)] [color=rgb(75,75,75)] (2)If a user has not exceeded a new tablespace quota, or if the space used by the objects of the user in the tablespace falls under a new tablespace quota, then the user's objects can be allocated space up to the new quota.

[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)]1.2 Restricting the Quota Limits for User Objects in a Tablespace[color=rgb(75,75,75)] You can restrict the quota limits for user objects in a tablespace by using the ALTER USER SQL statement to change the current quota of the user to zero.[color=rgb(75,75,75)] After a quota of zero is assigned, the objects of the user in the tablespace remain, and the user can still create new objects, but the existing objects will not be allocated any new space.[color=rgb(75,75,75)] For example, you could not insert data into one of this user's exiting tables. The operation will fail with an ORA-1536 space quota exceeded for tables error.

[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)]1.3 Granting Users the UNLIMITED TABLESPACE System Privilege[color=rgb(75,75,75)] To permit a user to use an unlimited amount of any tablespace in the database, grant the user the UNLIMITED TABLESPACE system privilege. This overrides all explicit tablespace quotas for the user. If you later revoke the privilege, then you must explicitly grant quotas to individual tablespaces. You can grant this privilege only to users, not to roles.[color=rgb(75,75,75)] Before granting the UNLIMITED TABLESPACE system privilege, you must consider the consequences of doing so.
[color=rgb(75,75,75)] [color=rgb(75,75,75)]Advantage:[color=rgb(75,75,75)] You can grant a user unlimited access to all tablespaces of a database with one statement.[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)]Disadvantages:[color=rgb(75,75,75)] (1)The privilege overrides all explicit tablespace quotas for the user.[color=rgb(75,75,75)] (2)You cannot selectively revoke tablespace access from a user with the UNLIMITED TABLESPACE privilege. You can grant selective or restricted access only after revoking the privilege.

[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)]1.4 Listing All Tablespace Quotas[color=rgb(75,75,75)] Use the DBA_TS_QUOTAS view to list all tablespace quotas specifically assigned to each user. For example:[color=rgb(75,75,75)] [color=rgb(75,75,75)] SELECT * FROM DBA_TS_QUOTAS; TABLESPACE USERNAME BYTES MAX_BYTES BLOCKS MAX_BLOCKS
---------- --------- -------- ---------- ------- ----------
USERS JFEE 0 512000 0 250USERS DCRANNEY 0 -1 0 -1

[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)] When specific quotas are assigned, the exact number is indicated in the MAX_BYTES column. This number is always a multiple of the database block size, so if you specify a tablespace quota that is not a multiple of the database block size, then it is rounded up accordingly.Unlimited quotas are indicated by -1.

[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)]二. Quota 说明[color=rgb(75,75,75)] 配额大小指的是用户指定使用表空间的的大小。在1.1 节里提到,默认情况下,用户对所有表空间都是没有配额的,即不受空间的限制。 查看几个用户的创建脚本来验证一下:

[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)]CREATE USER SYSTEM[color=rgb(75,75,75)] IDENTIFIED BY [color=rgb(75,75,75)] DEFAULT TABLESPACE SYSTEM[color=rgb(75,75,75)] TEMPORARY TABLESPACE TEMP[color=rgb(75,75,75)] PROFILE DEFAULT[color=rgb(75,75,75)] ACCOUNT UNLOCK;[color=rgb(75,75,75)] [i]-- 2 Roles for SYSTEM[color=rgb(75,75,75)] GRANT AQ_ADMINISTRATOR_ROLE TO SYSTEM WITH ADMIN OPTION;[color=rgb(75,75,75)] GRANT DBA TO SYSTEM WITH ADMIN OPTION;[color=rgb(75,75,75)] ALTER USER SYSTEM DEFAULT ROLE ALL;[color=rgb(75,75,75)] [i]-- 5 System Privileges for SYSTEM[color=rgb(75,75,75)] GRANT GLOBAL QUERY REWRITE TO SYSTEM;[color=rgb(75,75,75)] GRANT CREATE MATERIALIZED VIEW TO SYSTEM;[color=rgb(75,75,75)] GRANT CREATE TABLE TO SYSTEM;[color=rgb(75,75,75)] GRANT UNLIMITED TABLESPACE TO SYSTEM WITH ADMIN OPTION;[color=rgb(75,75,75)] GRANT SELECT ANY TABLE TO SYSTEM;

[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)]CREATE USER ITPUX[color=rgb(75,75,75)] IDENTIFIED BY [color=rgb(75,75,75)] DEFAULT TABLESPACE USERS[color=rgb(75,75,75)] TEMPORARY TABLESPACE TEMP[color=rgb(75,75,75)] PROFILE DEFAULT[color=rgb(75,75,75)] ACCOUNT UNLOCK;[color=rgb(75,75,75)] [i]-- 2 Roles for DAVE[color=rgb(75,75,75)] GRANT CONNECT TO ITPUX;[color=rgb(75,75,75)] GRANT RESOURCE TO ITPUX;[color=rgb(75,75,75)] ALTER USER DAVE DEFAULT ROLE ALL;[color=rgb(75,75,75)] [i]-- 1 System Privilege for ITPUX[color=rgb(75,75,75)] GRANT UNLIMITED TABLESPACE TO [font=MS Shell Dlg 2]ITPUX;
[color=rgb(75,75,75)] [color=rgb(75,75,75)] 从这2个脚本来看,默认情况下,都会对用户赋 unlimited tablespace 的权限。这是是在创建的时候指定的,当我们的用户创建好之后,我们也可以修改用户的配额。

[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)]有关用户的配额的操作说明

[color=rgb(75,75,75)]1. 创建用户时,指定限额[color=rgb(75,75,75)] [color=rgb(75,75,75)]SQL> conn / as sysdba;[color=rgb(75,75,75)]Connected.[color=rgb(75,75,75)]SQL> create user anqing identified by anqing default tablespace users temporary tablespace temp quota 10M on users;[color=rgb(75,75,75)]User created.
[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)]查询用户配额的信息:[color=rgb(75,75,75)]SQL> select tablespace_name,username,max_bytes from DBA_TS_QUOTAS where username='ANQING';[color=rgb(75,75,75)] [color=rgb(75,75,75)]TABLESPACE_NAME USERNAME MAX_BYTES[color=rgb(75,75,75)]------------------------------ ---------- ----------[color=rgb(75,75,75)]USERS ANQING 10485760

[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)]2.更改用户的表空间限额:
[color=rgb(75,75,75)] [color=rgb(75,75,75)]不对用户做表空间限额控制:[color=rgb(75,75,75)] [color=rgb(75,75,75)]SQL> grant unlimited tablespace to anqing;[color=rgb(75,75,75)]Grant succeeded.[color=rgb(75,75,75)] [color=rgb(75,75,75)]这种方式是全局性的. 即修改用户多所有表空间的配额。
[color=rgb(75,75,75)] [color=rgb(75,75,75)]如果我们想改某个具体的,即针对用户的某个特定的表空间,可以使用如下SQL:[color=rgb(75,75,75)] [color=rgb(75,75,75)]SQL> alter user anqing quota unlimited on users;[color=rgb(75,75,75)]User altered.
[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)]查看配额:[color=rgb(75,75,75)]SQL> select tablespace_name,username,max_bytes from DBA_TS_QUOTAS where username='ANQING';[color=rgb(75,75,75)] [color=rgb(75,75,75)]TABLESPACE_NAME USERNAME MAX_BYTES[color=rgb(75,75,75)]------------------------------ ---------- ----------[color=rgb(75,75,75)]USERS ANQING -1[color=rgb(75,75,75)] [color=rgb(75,75,75)]这时候max_bytes 为-1,即不受限制。

[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)]3. 回收用户对表空间的配额:[color=rgb(75,75,75)]同样两种方式,[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)]全局:[color=rgb(75,75,75)]SQL> revoke unlimited tablespace from anqing;[color=rgb(75,75,75)]Revoke succeeded.

[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)]在查看配额,已经没有了相关信息:[color=rgb(75,75,75)]SQL> select tablespace_name,username,max_bytes from DBA_TS_QUOTAS where username='ANQING';[color=rgb(75,75,75)]no rows selected
[color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)] [color=rgb(75,75,75)]针对某个特定的表空间:[color=rgb(75,75,75)]SQL> alter user anqing quota 0 on users;[color=rgb(75,75,75)]User altered.

本文标签:
网站声明:本文由风哥整理发布,转载请保留此段声明,本站所有内容将不对其使用后果做任何承诺,请读者谨慎使用!
【上一篇】
【下一篇】