################## managing password security and resources ####################alter user user_name account unlock/open;---- 鎖定 / 開啟使用者 ;alter user user_name password expire;--- 設定口令到期/* 建立口令設定檔 ,failed_login_attempts 口令輸多少次後鎖, password_lock_times 指多少天后口令被自動解鎖 */create profile profile_name limit failed_login_attempts 3 password_lock_times 1/1440;/* 建立口令設定檔 */create profile profile_name limit failed_login_attempts 3 password_lock_time unlimited password_life_time 30 password_reuse_time 30 password_verify_function verify_function password_grace_time 5;/* 建立資源設定檔 */create profile prfile_name limit session_per_user 2 cpu_per_session 10000 idle_time 60 connect_time 480;alter user user_name profile profile_name;/* 設定口令解鎖時間 */alter profile profile_name limit password_lock_time 1/24;/*password_life_time 指口令檔案多少時間到期, password_grace_time 指在第一次成功登入後到口令到期有多少天時間可改變口令 */alter profile profile_name limit password_lift_time 2 password_grace_time 3;/*password_reuse_time 指口令在多少天內可被重用 ,password_reuse_max 口令可被重用的最大次數 */alter profile profile_name limit password_reuse_time 10[password_reuse_max 3];alter user user_name identified by input_password;----- 修改使用者口令drop profile profile_name;/* 建立了 profile 後,且指定給某個使用者,則必須用 CASCADE 才能刪除 */drop profile profile_name CASCADE;alter system set resource_limit=true;--- 啟用自願限制 , 預設是 false/* 配置資源參數 */alter profile profile_name limit cpu_per_session 10000 connect_time 60 idle_time 5;/* 資源參數 (session 級 )cpu_per_session 每個 session 佔用 cpu 的時間 單位 1/100 秒sessions_per_user 允許每個使用者的並行 session 數connect_time 允許串連的時間 單位分鐘idle_time 串連被空閑多少時間後,被自動斷開 單位分鐘logical_reads_per_session 讀塊數private_sga 使用者能夠在 SGA 中使用的私人的空間數 單位 bytes(call 級 )cpu_per_call 每次 (1/100 秒 ) 調用 cpu 的時間logical_reads_per_call 每次調用能夠讀的塊數*/alter profile profile_name limit cpu_per_call 1000 logical_reads_per_call 10;desc dbms_resouce_manager;--- 資源管理員包/* 擷取資源資訊的表或視圖 */select * from dba_users/dba_profiles;###### Managing users ############show parameter os;create user testuser1 identified by kxf_001;grant connect,createtable to testuser1;alter user testuser1 quota 10m on tablespace_name;/* 建立使用者 */create user user_name identified by password default tablespace tablespace_name temporary tablespace tablespace_name quota 15m on tablespace_name password expire;/* 資料庫級設定預設暫存資料表空間 */alter database default temporary tablespace tablespace_name;/* 制定資料庫級的預設資料表空間 */alter database default tablespace tablespace_name;/* 建立 os 級審核的使用者,需知道 os_authent_prefix ,表示 oracle 和 os 口令對應的首碼 ,'OPS$' 為此參數的值,此值可以任意設定 */create user user_name identified by externally default OPS$tablespace_name tablespace_name temporary tablespace tablespace_name quota 15m on tablespace_name password expire;/* 修改使用者使用資料表空間的限額 , 復原資料表空間和暫存資料表空間不允許授予限額 */alter user user_name quota 5m on tablespace_name;/* 刪除使用者或刪除級聯使用者 ( 使用者物件下有對象的要用 CASCADE ,將其下一些對象一起刪除 )*/drop user user_name [CASCADE];/* 每個使用者在哪些資料表空間下有些什麼限額 */desc dba_ts_quotas;select * from dba_ts_quotas where username='...';/* 改變使用者的預設資料表空間 */alter user user_name default tablespace tablespace_name;######### Managing Privileges #############grant create table,create session to user_name;grant create any table to user_name; revoke create any table from user_name;/* 授予許可權文法 ,public 標識所有使用者 ,with admin option 允許能將許可權授予第三者的許可權 */grant system_privs,[......] to [user/role/public],[....] [with admin option];select * from v$pwfile_users;/* 當 O7_dictionary_accessiblity 參數為 True 時,標識 select any table 時,包括系統資料表也能 select , 否則,不包含系統資料表 ; 預設為 false*/show parameter O7;/* 由於 O7_dictionary_accessiblity 為靜態參數,不能動態改變,故加 scope=spfile, 下次啟動時才生效 */alter system set O7_dictionary_accessiblity=true scope=spfile;/* 授予對象中的某些欄位的許可權,如 select 某表中的某些欄位的許可權 */grant [object_privs(column,....)],[...] on object_name to user/role/public,... with grant option;/*oracle 不允許授予 select 某列的許可權 , 但可以授 insert ,update 某列的許可權 */grant insert(column_name1,column_name2,...) on table_name to user_name with grant option;select * from dba_sys_privs/session_privs/dba_tab_privs/user_tab_privs/dba_col_privs/user_col_privs;/*db/os/none 審計被記錄在 資料庫 / 作業系統 / 不審計 預設是 none*/show parameter audit_trail;/* 啟動對錶的 select 動作 */audit select on user.table_name by session;/*by session 在每個 session 中發出 command 只記錄一次, by access 則每個 command 都記錄 */audit [create table][select/update/insert on object by session/access][whenever successful/not successful];desc dbms_fga;--- 進一步設計,則可使用 dbms_fgs 包/* 取消審計 */noaudit select on user.table_name;/* 查被審計資訊 */select * from all_def_audit_opts/dba_stmt_audit_opts/dba_priv_audit_opts/dba_obj_audit_opts;/* 擷取審計記錄 */select * from dba_audit_trail/dba_audit_exists/dba_audit_object/dba_audit_session/dba_audit_statement;########### Managing Role #################create role role_name; grant select on table_name to role_name; grant role_name to user_name; set role role_name;create role role_name;create role role_name identified by password;create role role_name identified externally;set role role_name ; ---- 啟用 roleset role role_name identified by password;alter role role_name not identified;alter role role_name identified by password;alter role role_name identified externally;grant priv_name to role_name [WITH ADMIN OPTION];grant update(column_name1,col_name2,...) on table_name to role_name;grant role_name1 to role_name2;/* 建立 default role, 使用者登入時,預設啟用 default role*/alter user user_name default role role_name1,role_name2,...;alter user user_name default role all;alter user user_name default role all except role_name1,...;alter user user_name default role none;set role role1 [identified by password],role2,....;set role all;set role except role1,role2,...;set role none;revoke role_name from user_name;revoke role_name from public;drop role role_name;select * from dba_roles/dba_role_privs/role_role_privs/dba_sys_privs/role_sys_privs/role_tab_privs/session_roles;