oracle初始化化表空间用户权限

时间:2021-12-03 09:08:32

  oracle单实例安装完毕,需要初始化表空间、用户、等信息。不积跬步,何以至千里!

用sys账户登录oracle数据库,以此来完成所有操作!

01、创建临时表空间

create temporary tablespace dzswjdb_temp   --表空间名字
tempfile '/home/oracle/app/oracle/data/dzswjdb_temp.dbf'   --数据文件的物理位置
size 1000M
autoextend on
next 500M maxsize 2000M    
extent management local

02、创建数据表空间

create tablespace dzswjdb_data
datafile '/home/oracle/app/oracle/data/dzswjdb_data.dbf'
size 1000M
autoextend on
next 500M maxsize unlimited
extent management local
segment space management auto;

03、创建用户

create user  sztq  identified by sztqz2017    --用户/密码
default tablespace dzswjdb_data              --数据表空间
temporary tablespace dzswjdb_temp;

04、用户授权

grant connect,resource,dba to sztq;          --测试环境可以授权dba,生产建议还是按需设置角色
grant unlimited tablespace to sztq;            --对表空间的增长限制(多注意表空间的使用率)

-- grant/revoke system privileges          --授权/回收权限
-- grant/revoke role privileges


题外话,删除用户及表空间(如果表空间是多个账户共用,就不能这样删表空间,后续补充)

01、删除用户及对象

drop user xxx  cascade;   --用户

说明: 删除了user,只是删除了该user下的schema objects,是不会删除相应的tablespace的。

02、删除tablespace

drop tablespace tablespace_name including contents and datafiles;    --表空间 ,注意针对单用户对应单个表空间切全部分给此用户

注意区别:

--删除空的表空间,但是不包含物理文件
drop tablespace tablespace_name;
--删除非空表空间,但是不包含物理文件
drop tablespace tablespace_name including contents;
--删除空表空间,包含物理文件
drop tablespace tablespace_name including datafiles;
--删除非空表空间,包含物理文件
drop tablespace tablespace_name including contents and datafiles;

--如果其他表空间中的表有外键等约束关联到了本表空间中的表的字段,就要加上cascade constraints
drop tablespace tablespace_name including contents and datafiles cascade constraints;