1. 程式人生 > >Oracle 使用者 對 表空間 配額(quota ) 說明

Oracle 使用者 對 表空間 配額(quota ) 說明

. 官網的說明

Oracle 官網對quota的定義如下:

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 tablespace quotas for each Oracle Database username.

有關Oracle Quota 這塊,只在Oracle 的安全管理這塊搜到了一些內容。

Managing Security for Oracle Database Users

1.1 Assigning a Tablespace Quota for the User

You can assign each user a tablespace quota for any tablespace (except a temporary tablespace). Assigning a quota accomplishes the following:

1Users with privileges to create certain types of objects can create those objects in the specified tablespace.

2Oracle 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.

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.

The following CREATE USER statement assigns the following quotas for the test_ts and data_ts tablespaces:

CREATE USER jward

IDENTIFIED BY password

DEFAULT TABLESPACE data_ts

QUOTA 100M ON test_ts

QUOTA 500K ON data_ts

TEMPORARY TABLESPACE temp_ts

PROFILE clerk;

-- 在建立使用者的時候,就指定使用者在特定表空間上的配額

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.

-- 配額的指定可以禁止使用者的物件使用過多的表空間

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.)

If a new quota is less than the old one, then the following conditions remain true:

1If 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.

2If 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.

1.2 Restricting the Quota Limits for User Objects in a Tablespace

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.

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.

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.

1.3 Granting Users the UNLIMITED TABLESPACE System Privilege

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.

Before granting the UNLIMITED TABLESPACE system privilege, you must consider the consequences of doing so.

Advantage:

You can grant a user unlimited access to all tablespaces of a database with one statement.

Disadvantages:

1The privilege overrides all explicit tablespace quotas for the user.

2You 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.

1.4 Listing All Tablespace Quotas

Use the DBA_TS_QUOTAS view to list all tablespace quotas specifically assigned to each user. For example:

SELECT * FROM DBA_TS_QUOTAS;
TABLESPACEUSERNAMEBYTESMAX_BYTESBLOCKSMAX_BLOCKS
------------------------------------------------------
USERSJFEE05120000250
USERSDCRANNEY0-10-1

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.

. Quota 說明

配額大小指的是使用者指定使用表空間的的大小。在1.1 節裡提到,預設情況下,使用者對所有表空間都是沒有配額的,即不受空間的限制。 檢視幾個使用者的建立指令碼來驗證一下:

CREATEUSERSYSTEM

IDENTIFIEDBY<password>

DEFAULTTABLESPACESYSTEM

TEMPORARYTABLESPACE TEMP

PROFILEDEFAULT

ACCOUNTUNLOCK;

-- 2 Roles for SYSTEM

GRANT AQ_ADMINISTRATOR_ROLE TOSYSTEMWITHADMINOPTION;

GRANTDBATOSYSTEMWITHADMINOPTION;

ALTERUSERSYSTEMDEFAULTROLEALL;

-- 5 System Privileges for SYSTEM

GRANTGLOBALQUERYREWRITETOSYSTEM;

GRANTCREATEMATERIALIZEDVIEWTOSYSTEM;

GRANTCREATETABLETOSYSTEM;

GRANT UNLIMITED TABLESPACE TO SYSTEM WITH ADMIN OPTION;

GRANTSELECTANYTABLETOSYSTEM;

CREATEUSERDAVE

IDENTIFIEDBY<password>

DEFAULTTABLESPACEUSERS

TEMPORARYTABLESPACE TEMP

PROFILEDEFAULT

ACCOUNTUNLOCK;

-- 2 Roles for DAVE

GRANTCONNECTTODAVE;

GRANTRESOURCETODAVE;

ALTERUSERDAVEDEFAULTROLEALL;

-- 1 System Privilege for DAVE

GRANT UNLIMITED TABLESPACE TO DAVE;

從這2個指令碼來看,預設情況下,都會對使用者賦 unlimited tablespace 的許可權。這是是在建立的時候指定的,當我們的使用者建立好之後,我們也可以修改使用者的配額。

有關使用者的配額的操作說明

1. 建立使用者時,指定限額

SQL> conn / as sysdba;

Connected.

SQL> create user anqing identified by anqing default tablespace users temporary tablespace temp quota 10M on users;

User created.

查詢使用者配額的資訊:

SQL> select tablespace_name,username,max_bytes fromDBA_TS_QUOTAS where username='ANQING';

TABLESPACE_NAMEUSERNAMEMAX_BYTES

------------------------------ ---------- ----------

USERSANQING10485760

2.更改使用者的表空間限額:

不對使用者做表空間限額控制:

SQL> grant unlimited tablespace to anqing;

Grant succeeded.

這種方式是全域性性的. 即修改使用者多所有表空間的配額。

如果我們想改某個具體的,即針對使用者的某個特定的表空間,可以使用如下SQL

SQL> alter user anqing quota unlimited on users;

User altered.

檢視配額:

SQL> select tablespace_name,username,max_bytes fromDBA_TS_QUOTAS where username='ANQING';

TABLESPACE_NAMEUSERNAMEMAX_BYTES

------------------------------ ---------- ----------

USERSANQING-1

這時候max_bytes -1,即不受限制。

3. 回收使用者對錶空間的配額:

同樣兩種方式,

全域性:

SQL> revoke unlimited tablespace from anqing;

Revoke succeeded.

在檢視配額,已經沒有了相關資訊:

SQL> select tablespace_name,username,max_bytes fromDBA_TS_QUOTAS where username='ANQING';

no rows selected

針對某個特定的表空間:

SQL> alter user anqing quota 0 on users;

User altered.

-------------------------------------------------------------------------------------------------------

QQ:492913789

Email:[email protected]


DBA1 群:62697716(滿);DBA2 群:62697977(滿)DBA3 群:62697850(滿)

DBA 超級群:63306533(滿);DBA4 群: 83829929DBA5群: 142216823

聊天 群:40132017聊天2群:69087192

--加群需要在備註說明Oracle表空間和資料檔案的關係,否則拒絕申請