ORACLE使用者PROFILE詳解,oracleprofile詳解

來源:互聯網
上載者:User

ORACLE使用者PROFILE詳解,oracleprofile詳解

ORACLE使用者PROFILE詳解  

一、官網說明

Oraclerecommends that you use the Database Resource Manager rather than the SQLstatement to establish resource limits. The Database Resource Manager offers amore flexible means of managing and tracking resource use.

Purpose:

Use the CREATE PROFILE statement to create a profile, which is a set oflimits on database resources. If you assign the profile to a user, then thatuser cannot exceed these limits.

Oracle系統中的profile可以用來對使用者所能使用的資料庫資源進行限制。使用create profile命令建立一個profile,用它來實現對資料庫資源的限制使用。如果把該profile分配給使用者,則該使用者所能使用的資料庫資源都在該profile的限制之內。

Prerequisites:

To create aprofile, you must have the CREATE PROFILE system privilege.

To specifyresource limits for a user, you must:

(1).Enable resource limits dynamically  with the ALTER SYSTEM statement or with the initializationparameter RESOURCE_LIMITS. This parameter does not apply to password resources.Password resources are always enabled.

(2). Create aprofile that defines the limits using the CREATE PROFILE statement.

(3). Assign theprofile to the user using the CREATE USER or ALTER USER statement.

二、PROFILE管理

Profile是口令限制、資源限制的命名集合。建立oracle資料庫時,oracle會自動建立名為DEFAULT的profile,初始化的DEFAULT沒有進行任何口令和資源限制。

1、使用PROFILE有以下一些注意事項:

(1)、建立PROFILE時,如果只設定了部分口令或資源限制選項,其他選項會自動使用預設值(DEFAULT的相應選項)。

(2)、建立使用者時,如果不指定PROFILE選項,oracle會自動將DEFAULT分配給相應的資料庫使用者。

(3)、一個使用者只能分配一個PROFILE。如果要同時系統管理使用者的口令和資源,那麼在建立PROFILE時應該同時指定口令和資源選項。

(4)、使用PROFILE管理口令時,口令管理選項總是處於被啟用狀態。但如果使用PROFILE管理資源,必須要啟用資源限制。

    2、條件

建立profile必須要有CREATEPROFILE的系統許可權。

(1)、動態地使用altersystem或使用初始化參數resource_limit使資源限制生效。該改變對密碼資源無效,密碼資源總是可用。

SQL>show parameter resource_limit

 NAME                                 TYPE        VALUE

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

resource_limit                   boolean     FALSE

 SQL>alter system set resource_limit=true;

 系統已更改。

 SQL>show parameter resource_limit

 NAME                                 TYPE        VALUE

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

resource_limit                       boolean     TRUE

 

     (2)、使用create profile建立一個定義對資料庫資源進行限制的profile。

SQL> create profile db_pro limit idle_time 30connect_time 480; 

IDLE_TIME Specify the permitted periods of continuousinactive time during a session, expressed in mimutes(分鐘). Long-running queries andother operations are not subject to this limit.

CONNECT_TIME Specifythe total elapsed time limit for a session, expressed in minutes.

其它資源比如:

session_per_user   限制一個使用者名稱可進行的串連

cpu_per_session   一次會話使用者可使用的server的cpu時間(白分秒)

cpu_per_call   使用者進程對資料庫一次調用用時(百分秒)

private_sga   限制一個使用者可佔用記憶體

    (3)、使用create user 或 alter user命令把profile分配給使用者。

SQL>create user lxh identified by lxh profile test;

使用者已建立。               --建立使用者時指定profile

SQL> alter user lxh profiletest;        --修改使用者的profile

SQL> alter user lxh profiledefault;       --還原預設值

    (4)、修改PROFILE

SQL>alter profile test limit idle_time 60;

 設定檔已更改

    (5)、刪除PROFILE

SQL>drop profile test;

設定檔已刪除。

SQL>drop profile test cascade;

         注意:

  1). 已指派的profile,刪除時必須加cascade選項。

  2). 必須要有create profile許可權,才能建立profile。

  3). DEFAULT為預設profile,不能刪除。

 

三、Profile建立文法及解釋

 

CREATE PROFILE profile

LIMIT { resource_parameters

         |password_parameters

         }

          [ resource_parameters

          | password_parameters

          ]... ;

 

<resource_parameters>

{ { SESSIONS_PER_USER

 | CPU_PER_SESSION

 | CPU_PER_CALL

 | CONNECT_TIME

 | IDLE_TIME

 | LOGICAL_READS_PER_SESSION

 | LOGICAL_READS_PER_CALL

 | COMPOSITE_LIMIT

 }

 { integer | UNLIMITED | DEFAULT }

| PRIVATE_SGA

 { integer [ K | M ] | UNLIMITED | DEFAULT }

}

     < password_parameters >

{ { FAILED_LOGIN_ATTEMPTS

 | PASSWORD_LIFE_TIME

 | PASSWORD_REUSE_TIME

 | PASSWORD_REUSE_MAX

 | PASSWORD_LOCK_TIME

 | PASSWORD_GRACE_TIME

 }

 { expr | UNLIMITED | DEFAULT }

| PASSWORD_VERIFY_FUNCTION

     { function | NULL| DEFAULT }}

 

四、文法解釋

 

profile:設定檔的名稱。Oracle資料庫以以下方式強迫資源限制:

      1.如果使用者超過了connect_time或idle_time的會話資源限制,資料庫就復原當前事務,並結束會話。使用者再次執行命令,資料庫則返回一個錯誤,

      2.如果使用者試圖執行超過其他的會話資源限制的操作,資料庫放棄操作,復原當前事務並立即返回錯誤。使用者之後可以提交或復原當前事務,必須結束會話。

       提示:可以將一條分成多個段,如1小時(1/24天)來限制時間,可以為使用者指定資源限制,但是資料庫只有在參數生效後才會執行限制。

     Unlimited:分配該profile的使用者對資源使用無限制,當使用密碼參數時,unlimited意味著沒有對參數加限制。

      Default:指定為default意味著忽略對profile中的一些資源限制,Default profile初始定義對資源不限制,可以通過alterprofile命令來改變。

 

 Resource_parameter部分:

       Session_per_user:指定限制使用者的並發會話的數目。

      Cpu_per_session:指定會話的CPU時間限制,單位為百分之一秒。

      Cpu_per_call:指定一次調用(解析、執行和提取)的CPU時間限制,單位為百分之一秒。

      Connect_time:指定會話的總的連線時間,以分鐘為單位。

      Idle_time:指定會話允許連續不活動的總的時間,以分鐘為單位,超過該時間,會話將斷開。但是長時間執行查詢和其他動作的不受此限制。

      Logical_reads_per_session:指定一個會話允許讀的資料區塊的數目,包括從記憶體和磁碟讀的所有資料區塊。

      Logical_read_per_call:指定一次執行SQL(解析、執行和提取)調用所允許讀的資料區塊的最大數目。

      Private_sga:指定一個會話可以在共用池(SGA)中所允許分配的最大空間,以位元組為單位。(該限制只在使用共用伺服器結構時才有效,會話在SGA中的私人空間包括私人的SQL和PL/SQL,但不包括共用的SQL和PL/SQL)。

      Composite_limit:指定一個會話的總的資源消耗,以service units單位表示。Oracle資料庫以有利的方式計算       cpu_per_session,connect_time,logical_reads_per_session和private-sga總的service units

      

Password_parameter部分:

      

      Failed_login_attempts:指定在帳戶被鎖定之前所允許嘗試登陸的的最大次數。

      Password_life_time:指定同一密碼所允許使用的天數。如果同時指定了password_grace_time參數,如果在grace period內沒有改變密碼,則密碼會失效,串連資料庫被拒絕。如果沒有設定password_grace_time參數,預設值unlimited將引發一個資料庫警告,但是允許使用者繼續串連。

      Password_reuse_time和password_reuse_max:這兩個參數必須互相關聯設定,password_reuse_time指定了密碼不能重用前的天數,而password_reuse_max則指定了當前密碼被重用之前密碼改變的次數。兩個參數都必須被設定為整數。

      1.如果為這兩個參數指定了整數,則使用者不能重用密碼直到密碼被改變了password_reuse_max指定的次數以後在password_reuse_time指定的時間內。

       如:password_reuse_time=30,password_reuse_max=10,使用者可以在30天以後重用該密碼,要求密碼必須被改變超過10次。

      2.如果指定了其中的一個為整數,而另一個為unlimited,則使用者永遠不能重用一個密碼。

      3.如果指定了其中的一個為default,Oracle資料庫使用定義在profile中的預設值,預設情況下,所有的參數在profile中都被設定為unlimited,如果沒有改變profile預設值,資料庫對該值總是預設為unlimited。

      4.如果兩個參數都設定為unlimited,則資料庫忽略他們。

      Password_lock_time:指定登陸嘗試失敗次數到達後帳戶的縮定時間,以天為單位。

      Password_grace_time:指定寬限天數,資料庫發出警告到登陸失效前的天數。如果資料庫密碼在這中間沒有被修改,則到期會失效。

      Password_verify_function:該欄位允許將複雜的PL/SQL密碼驗證指令碼做為參數傳遞到create profile語句。Oracle資料庫提供了一個預設的指令碼,但是自己可以建立自己的驗證規則或使用第三方軟體驗證。對Function名稱,指定的是密碼驗證規則的名稱,指定為Null則意味著不使用密碼驗證功能。如果為密碼參數指定運算式,則該運算式可以是任意格式,除了資料庫標量子查詢。

 

五、舉例:

      

 1.建立一個profile:

       createprofile new_profile

             limit password_reuse_max 10

                    password_reuse_time 30;

 

 2.設定profile資源限制:

      

 create profile app_user limit

 sessions_per_user unlimited

 cpu_per_session unlimited

 cpu_per_call 3000

 connect_time 45

 logical_reads_per_session default

 logical_reads_per_call 1000

 private_sga 15k

 composite_limit 5000000;

              總的resourcecost不超過五百萬service units。計算總的resource cost的公式由alter resource cost語句來指定。

      

  3.設定密碼限制profile:

      

     createprofile app_users limit

 failed_login_attempts 5

 password_life_time 60

 password_reuse_time 60

 password_reuse_max 5

 password_verify_function verify_function

 password_lock_time 1/24

 password_grace_time 10;

             

   4.將設定檔分配給使用者:

        SQL>alter user dinya profile app_user;

   使用者已更改。   

       SQL> alter user dinya profile default;

   使用者已更改。

 

6變更密碼

        1、查詢user密碼

       SQL> select user#,name ,password from user$ where name='SDXJ';

      

         85 SDXJ                           666F8605B1CA3CFF

        2、修改密碼      

         SQL>alter user sdxj identified by values '666F8605B1CA3CFF';


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.