创建用户和表空间:
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;
注解:
对于表空间存储的定义 数据库的逻辑结构如下:数据库是由一系列表空间(tablespace)组成,表空间由若干段(segment)组成,段由若干区(extent)组成,区由若干块(block)组成 当在表空间中创建表时,系统先分配一个初始空间,这个空间大小由initial这个参数决定,此处为64KB,minextents 表示建好表后至少要分配几个区,这里是1个,maxextents 表示表空间最多能分配几个区,这里是无限制
对存储空间的一些定义参数: 初始大小:64KB 空间最小:1KB 空间最大:无限制
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);
---另一个处理
查询当前数据库中表空间是否为自动扩展
select tablespace_name,file_name,autoextensible from dba_data_files;
.通过修改表空间的数据文件为自动扩展达到表空间为自动扩展的目的,并限制文件最大值
alter database datafile '/opt/app/oracle/oradata/caacdb/system01.dbf' autoextend on NEXT 50M maxsize 31G;
alter database datafile '/opt/app/oracle/oradata/caacdb/undotbs01.dbf' autoextend on NEXT 50M maxsize 31G;
alter database datafile '/opt/app/oracle/oradata/caacdb/sysaux01.dbf' autoextend on NEXT 50M maxsize 31G;
alter database datafile '/opt/app/oracle/oradata/caacdb/users01.dbf' autoextend on NEXT 50M maxsize 31G;
5、创建用户和密码,指定上边创建的临时表空间和表空间
create user hc_notify identified by hc_password default tablespace NOTIFYDB temporary tablespace NOTIFYDB_TEMP;
-- 创建用户并指定表空间 create user c##gaokexin identified by gaokexin_password default tablespace gao temporary tablespace gao_temp; 报错 提示错误ORA-65096:公用用户名或角色名无效 解决方案:取名前缀必须为c##,所以用户名也变成了c#gaokexin ORA-65048:在可插入数据库PDBORCL中处理当前DDL语句时出错ORA-00959:表空间‘LOCL_DATA’不存在 解决方案:重启下Oracle服务之后,就不会报这个错了 [oracle@SVR-29-151 ~]$ lsnrctl stop [oracle@SVR-29-151 ~]$ sqlplus "/as sysdba" SQL> shutdown immediate; 数据库已经关闭。 已经卸载数据库。 ORACLE 例程已经关闭。 SQL> quit [oracle@SVR-29-151 ~]$ lsnrctl start [oracle@SVR-29-151 ~]$ sqlplus / as sysdba 已连接到空闲例程。 SQL> startup ORACLE 例程已经启动。 SQL> create user c##gaokexin identified by gaokexin_password default tablespace gao temporary tablespace gao_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;