關於orapwd命令entries參數的探究

來源:互聯網
上載者:User

關於orapwd命令entries參數的探究

今日早上看Oracle官方文檔《Administrator's Guide》時,在密碼檔案章節,關於orapwd命令entries參數的說明如下:

This argument specifies the number of entries that you require the password file to accept. This number corresponds to the number of distinct users allowed to connect to the database as SYSDBA or SYSOPER. The actual number of allowable entries can be higher than the number of users, because theORAPWD utility continues to assign password entries until an operating system block is filled. For example, if your operating system block size is 512 bytes, it holds four password entries. The number of password entries allocated is always a multiple of four.

大意是,entries參數並不是指多少個使用者可被賦予sysdba或sysoper許可權。實際數量可能高於entries參數指定的值,這與作業系統的block size有關。

按它的說法,作業系統的block size為512位元組,entries指定為1的話,我可以給4個使用者賦予sysdba或sysoper許可權。

好奇,忍不住研究了一下。

一、查看作業系統的block size,本機為RHEL 6.3

[root@node2 ~]# tune2fs -l /dev/sdb |grep 'Block size'
Block size:              4096

block size為4096位元組,為512的8倍,按照上面的邏輯,可以給最多32個使用者賦予sysdba或sysoper許可權。

二、建立密碼檔案

[oracle@node2 dbs]$ orapwd file=orapworcl password=oracle entries=1 force=y

三、構造使用者進行測試

      如果能給最多32個使用者賦予sysdba或sysoper許可權的話,那麼建立32個使用者並賦予sysdba許可權不會有問題,賦予第33個使用者sysdba許可權的時候會報錯,實驗一下。

      首先建立32個使用者並賦予sysdba許可權,指令碼如下:

 

declare
sqltext1 varchar2(100);
sqltext2 varchar2(100);
begin
  for i in 1..32
  loop
  sqltext1 := 'create user test'||i||' identified by test'||i;
  sqltext2 := 'grant sysdba to test'||i;
  execute immediate sqltext1;
  execute immediate sqltext2;
  end loop;
end;

 

      執行結果如下:

declare
*
ERROR at line 1:
ORA-01996: GRANT failed: password file
'/u01/app/oracle/product/11.2.0.1/db_1/dbs/orapworcl' is full
ORA-06512: at line 10

建立32個使用者並賦予sysdba許可權竟然沒有成功。

四、查看建立成功的使用者和被賦予sysdba許可權的使用者

 

SQL> select username from dba_users where username like 'TEST%';

USERNAME
------------------------------
TEST4
TEST5
TEST2
TEST1
TEST3

6 rows selected.

SQL> select username from v$pwfile_users where username !='SYS' and sysdba='TRUE';

USERNAME
------------------------------
TEST1
TEST2
TEST3
TEST4

 

    發現只成功建立了5個使用者且只有4個使用者被賦予sysdba許可權。

    難道官方文檔關於entries的說明有誤?將operating system block size is 512 bytes作為關鍵字在百度上搜了下,原來oracle所謂的block size和系統的block size不一致,可根據select distinct lebsz from x$kccle進行查詢,lebsz指的是log file的塊大小,它也等於作業系統塊大小

    Linux: file Block size is selected at the time of high-level formatting。

    The log block size is platform. specific, and can be found out using the following query: (size in bytes)

    most platforms have log block size of 512, but HPUX has 1k, and tru64 has blocksize of 2k if my memory serves me well.

    具體解釋可見:

五、查詢Oracle的block size

SQL> select distinct lebsz from x$kccle;

    LEBSZ
----------
      512

看來,原生block size是512,這也不難解釋當entries指定為1的時候,最多隻能給4個使用者賦予sysdba的許可權。

如果是這樣的話,那我將entries指定為5,則可以給8個使用者賦予sysdba許可權,下面來試試。

六、刪除上面建立的5個使用者

 

declare
sqltext varchar2(100);
begin
  for i in 1..5
  loop
  sqltext := 'drop user test'||i;
  execute immediate sqltext;
  end loop;
end;

 

七、重新建立密碼檔案,將entries指定為5

[oracle@node2 dbs]$ orapwd file=orapworcl password=oracle entries=5 force=y

八、建立8個使用者並賦予sysdba許可權

 

declare
sqltext1 varchar2(100);
sqltext2 varchar2(100);
begin
  for i in 1..8
  loop
  sqltext1 := 'create user test'||i||' identified by test'||i;
  sqltext2 := 'grant sysdba to test'||i;
  execute immediate sqltext1;
  execute immediate sqltext2;
  end loop;
end;

 

    語句執行沒有問題

九、建立第9個使用者並賦予sysdba許可權

 

SQL> create user test9 identified by test9;

User created.

SQL> grant sysdba to test9;
grant sysdba to test9
*
ERROR at line 1:
ORA-01996: GRANT failed: password file
'/u01/app/oracle/product/11.2.0.1/db_1/dbs/orapworcl' is full

  果然出現報錯!

  由此來看, 官方文檔中所說的 “if your operating system block size is 512 bytes, it holds four password entries. The number of password entries allocated is always a multiple of four” 確實沒錯!

相關文章

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.