linux系統下創建oracle表空間和用戶權限查詢


創建用戶和表空間: 

1、登錄linux,以oracle用戶登錄(如果是root用戶登錄的,登錄后用 su - oracle命令切換成oracle用戶)

2、以sysdba方式來打開sqlplus,命令如下: sqlplus / as sysdba

3、創建臨時表空間:

--查詢臨時表空間文件的絕對路徑。如果需要的話,可以通過查詢來寫定絕對路徑。一般用${ORACLE_HOME}就可以了  
select name from v$tempfile;  
create temporary tablespace NOTIFYDB_TEMP tempfile '${ORACLE_HOME}\oradata\NOTIFYDB_TEMP.bdf' size 100m reuse autoextend on next 20m maxsize unlimited;  

4、創建表空間:

--查詢用戶表空間文件的絕對路徑:
select name from v$datafile;
create tablespace NOTIFYDB datafile '${ORACLE_HOME}\oradata\notifydb.dbf' size 100M reuse autoextend on next 40M maxsize unlimited default storage(initial 128k next 128k minextents 2 maxextents unlimited);

5、創建用戶和密碼,指定上邊創建的臨時表空間和表空間

create user hc_notify identified by hc_password default tablespace NOTIFYDB temporary tablespace NOTIFYDB_TEMP;

6、賦予權限

grant dba to hc_notify;
grant connect,resource to hc_notify;
grant select any table to hc_notify;
grant delete any table to hc_notify;
grant update any table to hc_notify;
grant insert any table to hc_notify;

經過以上操作,就可以使用hc_notify/hc_password登錄指定的實例,創建我們自己的表了。

 

刪除表空間:

1、查看用戶權限

--查看用戶要具備drop tablespace的權限,如果沒有,先用更高級的用戶(如sys)給予授權
select a2.username,a1.privilege from dba_sys_privs a1 , user_role_privs a2
where a1.privilege = 'DROP TABLESPACE'
and a1.grantee =a2.granted_role

2、刪除臨時表空間

--查看臨時表空間文件
select name from v$tempfile;
--查看用戶和表空間的關系
select USERNAME,TEMPORARY_TABLESPACE from DBA_USERS;
--如果有用戶的默認臨時表空間是NOTIFYDB_TEMP的話,建議進行更改
alter user xxx temporary tablespace tempdefault;
---設置tempdefault為默認臨時表空間
alter database default temporary tablespace tempdefault;
--刪除表空間NOTIFYDB_TEMP及其包含數據對象以及數據文件
drop tablespace NOTIFYDB_TEMP including contents and datafiles; 

3.刪除用戶表空間

--查看表空間文件
select name from v$datafile;
--停止表空間的在線使用
alter tablespace 表空間名稱 offline;
--刪除表空間NOTIFYDB_TEMP及其包含數據對象以及數據文件
drop tablespace NOTIFYDB_TEMP including contents and datafiles; 

Oracle用戶權限查詢相關操作:

--查看所有的用戶
select * from all_users;
--查看當前用戶信息
select * from user_users;
--查看當前用戶的角色
select * from user_role_privs;
--查看當前用戶的權限
select * from user_sys_privs;
--查看當前用戶的表可操作權限
select * from user_tab_privs;

--查看某一個表的約束,注意表名要 大寫
select * from user_constraints where table_name='TBL_XXX';
--查看某一個表的所有索引,注意表名要 大寫
select index_name,index_type,status,blevel from user_indexes where table_name = 'TBL_XXX';
--查看索引的構成,注意表名要 大寫
select table_name,index_name,column_name, column_position FROM user_ind_columns WHERE table_name='TBL_XXX';

--系統數據字典 DBA_TABLESPACES 中記錄了關於表空間的詳細信息
select * from sys.dba_tablespaces;

--查看用戶序列
select * from user_sequences;
--查看數據庫序列
select * from dba_sequences;

轉:http://kingxss.iteye.com/blog/1741076


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM