linux中怎么创建oracle表空间

发布时间:2021-07-28 16:43:31 作者:Leah
来源:亿速云 阅读:749

linux中怎么创建oracle表空间 ,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

1 、 登录服务器
2 、 查看磁盘空间是否够大df -h
 
    -h更具目前磁盘空间和使用情况 以更易读的方式显示
  [root@rac1 ~]# df -h
  Filesystem Size Used Avail Use% Mounted on
  /dev/sda1 2.9G 2.3G 521M 82% /
  none 209M 0 209M 0% /dev/shm
  /dev/sda2 4.5G 1.8G 2.5G 42% /u01
  /dev/sde1 512M 80M 433M 16% /ocfs
   -H根上面的-h参数相同,不过在根式化的时候,采用1000而不是1024进行容量转换
  [root@rac1 ~]# df -H
  Filesystem Size Used Avail Use% Mounted on
  /dev/sda1 3.1G 2.4G 546M 82% /
  none 219M 0 219M 0% /dev/shm
  /dev/sda2 4.8G 1.9G 2.7G 42% /u01
  /dev/sde1 537M 84M 454M 16% /ocfs
  -k以单位显示磁盘的使用情况
  [root@rac1 ~]# df -k
  Filesystem 1K-blocks Used Available Use% Mounted on
   su - oracle              切换到oracle用户(linux的一个用户名)


3 、 在/home/oracle/oradata 目录下新建一个文件夹,后面创建表空间需要用到
     cd /home/oracle/oradata
     mkdir abc


4 、 sqlplus “/ as sysdba”   ( 以dba身份登录数据库, 系统的超级用户)


5 、创建临时表空间
创建用户前必须要先创建临时表空间和数据库表空间两个表空间,否则用系统默认的表空间不好。
#磁盘空间足够的话,临时表空间设置成5g就满足了,数据库表空间设置成5g但最好不要超过20G,看具体磁盘情况吧


#查询临时表空间文件的绝对路径。如果需要的话,可以通过查询来写定绝对路径。一般用${ORACLE_HOME}就可以了  
select name from v$tempfile;


#表空间自动扩展1:${ORACLE_HOME} 
create temporary tablespace NOTIFYDB_TEMP tempfile '${ORACLE_HOME}\oradata\NOTIFYDB_TEMP.bdf' size 1024m reuse autoextend on next 20m maxsize unlimited;  


#表空间自动扩展2:
create temporary tablespace abc_temp tempfile'/home/oracle/oradata/abc/abc_temp.dbf' size  5g autoextend on next 100m maxsize 10240m extent management local;




#一般来讲表空间不要设置为自动扩展:
create temporary tablespace ngcclog_tmp01 tempfile'/data/oradata/hbstylog/ngcclog_tmp01.dbf' size 5g  autoextend off  ;


说明:
1)abc_temp 临时表空间名字
2)/home/oracle/oradata/abc 存放数据库文件的地方,一般是安装数据库后有控制文件,数据文件和日志文件的文件夹,再加上要创建表空间的名字+dbf (数据文件)
3)1024m     表空间的初始大小
4)100m       表空间的自动增长大小
5)10240m     表空间最大的大小


 
6 、创建数据表空间


--查询用户表空间文件的绝对路径:
select name from v$datafile;


#表空间自动扩展的:${ORACLE_HOME}
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);


#表空间自动扩展的:
create tablespace abc logging datafile'/home/oracle/oradata/abc/abc.dbf' size 1024m autoextend on next 100m maxsize 10240m extent management local;


#一般来讲表空间不要设置为自动扩展:
create tablespace ngcc_log_dataspc_main  datafile'/data/oradata/hbstylog/ngcc_log_dataspc_main01.dbf' size 5g autoextend off;
 
7 、创建用户并指定表空间
create user abc identified by abc default tablespace abc temporary tablespace abc_temp;


create user ngcc_log identified by ngcc_log default tablespace ngcc_log_dataspc_main temporary tablespace ngcclog_tmp01;


8 、给用户授予权限
grant dba to abc; (给abc 用户授予了dba 所有权限)
grant dba to ngcc_log;
grant connect,resource to ngcc_log;   // grant  resource to ngcc_log 这是对表空间授权
grant select any table to ngcc_log;
grant delete any table to ngcc_log;
grant update any table to ngcc_log;
grant insert any table to ngcc_log;


经过以上操作,就可以使用ngcc_log/ngcc_log; 登录指定的实例,创建我们自己的表了。


删除表空间:

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;

-- 建一个用户 并附权限的语句的其他写法:

 create user repl@'%' identified by '123';
grant select ON  *.* to repl@'%'; 

 grant 权限  ON  数据库.表 to 用户@'地址'; 

关于linux中怎么创建oracle表空间 问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。

推荐阅读:
  1. oracle查看表空间创建语句
  2. Oracle 如何创建表空间

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

linux oracle

上一篇:Java中怎么创建Excel 散点图

下一篇:LIUNUX中怎么截取txt文件内容

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》