oracle2.20~3.12 | 您所在的位置:网站首页 › datafiles表中状态为recover › oracle2.20~3.12 |
一、创建表空间myspaces CREATE TABLESPACE myspaces DATAFILE 'C:\oraclexe\app\oracle\oradata\XE\myspaces.dbf' SIZE 20M AUTOEXTEND ON NEXT 5M MAXSIZE 100M; 二、使用数据字典查看表空间 例如:查看创建号的myspaces select * from dba_tablespaces where tablespaces_name='MYSPACE'; 查询所有表空间 select * from dba_tablespaces; 三、表空间状态属性 1、在线(ONLINE) ALTER TABLESPACE tablespace_name ONLINE; 2、离线(OFFLINE) ALTER TABLESPACE tablespace_name OFFLINE parameter; 3、只读(READ ONLY) ALTER TABLESPACE tablespace_name READ ONLY; 4、读写(READ WRITE) ALTER TABLESPACE tablespace_name READ WRITE; 一、表空间重命名 1、语法 alter_tablespace 表空间原名称 rename to表空间新名称 2、练习 修改myspace表空间的名称为myspace2 alter tablespace myspace rename to myspace2 3、使用数据字典查看修改结果 select tablespace_name from dba_tablespaces; 二、修改表空间数据文件的大小 myspace.dbf数据文件的大小修改为40M ALTER DATABASE DATAFILE 'C:\oraclexe\app\oracle\oradata\XE\MYSPACE.DBF' RESIZE 40M; 三、增加表空间的数据文件 1、语法 alter tablespace tablespace_name add datafile file_name size number K|M [ autoextend OFF|ON [NEXT number K|M maxsize unlimited|number K|M ] ] [,...]; 2、练习 alter tablespace myspace2 add datafile 'C:\oraclexe\app\oracle\oradata\XE\MYSPACE02.DBF' size 10M autoextend on next 5M maxsize 40M, 'C:\oraclexe\app\oracle\oradata\XE\MYSPACE03.DBF' size 10M autoextend on next 5M maxsize 40M; 四、删除数据文件 1、删除表空间的数据文件的语法 alter tablespce tablespace_name drop datafile file_name; 2、练习 删除myspace03.dbf alter tablespace myspace2 drop datafile 'C:\oraclexe\app\oracle\oradata\XE\MYSPACE03.DBF'; 五、修改表空间中数据文件的自动扩展性 1、语法格式 alter database datafile file_name autoextend OFF|ON [next number K|M maxsize unlimited | number K|M ] 2、练习 关闭myspace02.dbf数据文件自动增长 alter database datafile 'C:\oraclexe\app\oracle\oradata\XE\MYSPACE02.DBF' autoextend OFF; 打开myspace02.dbf数据文件自动增长,每次增长5,最大值为50M alter database datafile 'C:\oraclexe\app\oracle\oradata\XE\MYSPACE02.DBF' autoextend ON next 5M maxsize 50M; 一、修改表空间中数据文件的状态 1、数据文件的状态主要有三种: ONLINE、OFFLINE、和OFFLINE DROP 2、设置数据文件状态的语法 alter database datafile file_name online | offline | offline drop 3、练习 将myspace表空间的myspace02.dbf文件设置为OFFLINE DROP alter database datafile 'C:\oraclexe\app\oracle\oradata\XE\myspace02.dbf' offline drop; 将myspace表空间的myspace02.dbf文件设置为ONLINE状态 第一步先做介质恢复 recover datafile 'C:\oraclexe\app\oracle\oradata\XE\myspace02.dbf' 第二步切换数据文件的在线 alter database datafile 'C:\oraclexe\app\oracle\oradata\XE\myspace02.dbf' online; 二、移动表空间中的数据文件 【任务八】移动myspace表空间中数据文件myspace02.dbf的步骤如下 (1) 修改myspace表空间的状态为OFFLINE; alter tablespace myspace OFFLINE normal (2) 将磁盘中的myspace02.dbf文件移动到新的目录中,例如移动到C:\oraclefile目录中。文件的名称修改为myspace03.dbf alter tablespace myspace rename datafile 'C:\oraclexe\app\oracle\oradata\XE\myspace02.dbf' to 'd:\oraclexe\myspace03.dbf'; (3) 在执行改变表空间MYSPACE状态前要加myspace.dbf的介质恢复 recover datafile 'D:\ORACLEFILE\MYSPACE03.DBF'; (4) 修改myspace2表空间的状态为ONLINE alter tablespace myspace|ONLINE 检查: select tablespace_name ,file_name from dba_data_files where tablespace_name='MYSPACE2' 三、删除表空间 1、语法 drop tablespace tablespace_name 2、练习 删除myspace表空间 drop tablespace myspace including contents and datafiles; 1、创建一个临时表空间mytemp create temporary tablespace mytemp tempfile 'C:\oraclexe\app\oracle\oradata\XE\mytemp.dbf' size 10M autoextend on next 2M maxsize 20M; 2、查看临时表空间mytemp的临时文件信息 select tablespace_name,file_name,bytes from dba_temp_files where tablespace_name = 'MYTEMP'; 3、创建临时表空间temp1、temp2,并将他们所在的组都指定为group1 create temporary tablespace temp1 tempfile 'C:\oraclexe\app\oracle\oradata\XE\temp1.dbf' size 2M tablespace GROUP group1; create temporary tablespace temp2 tempfile 'C:\oraclexe\app\oracle\oradata\XE\temp2.dbf' size 2M tablespace GROUP group1; 一、撤销表空间 1、功能 存放修改的数据 2、语法 create undo tablespace 3、练习 创建一个撤销表空间myundo create undo tablespace myundo datafile 'C:\oraclefile\myundo.dbf' size 10M; 二、管理撤销表空间 修改默认撤销表空间 show parameter undo_tablespace; alter system set undo_tablespace='MYUNDO'; 三、设置撤销表空间保存数据的时间 查看撤销表空间保存数据的时间 show parameter undo_retention; 设置为1200秒 alter system set undo_retention=1200; 四、删除撤销表空间 1、语法 drop tablespace 2、练习 alter system set undo_tablespace='UNDOTBS1'; drop tablespace myundo INCLUDING contents and datafiles; 五、用户管理 1、权限概念 2、权限分类:系统权限(定义)和对象权限(定义) 3、用户的概念 4、角色的概念 1、创建临时表空间 create temporary tablespace temp1 tempfile 'C:\oraclexe\app\oracle\oradata\XE\temp1.dbf' size 2M tablespace GROUP group1; CREATE TEMPORARY TABLESPACE temp2 TEMPFILE 'C:\oraclexe\app\oracle\oradata\XE\temp2.dbf' SIZE 2M TABLESPACE GROUP group1; 2、查询表空间 select group_name,tablespace_name FROM dba_tablespace_groups WHERE group_name='GROUP1'; 一、移动表空间所在组 1、语法 alter tablespace 2、练习 讲临时表空间temp1从group1组移动到group2组中 alter tablespace temp1 tablespace GROUP group2; 测试GROUP1 select group_name,tablespace_name FROM dba_tablespace_groups WHERE group_name='GROUP1'; 测试GROUP2 select group_name,tablespace_name FROM dba_tablespace_groups WHERE group_name='GROUP2'; 二、删除临时表空间 1、语法 drop tablespace 2、练习 删除temp1 drop tablespace temp1 including contents and datafiles; 测试是否已删除 select group_name,tablespace_name FROM dba_tablespace_groups WHERE group_name='GROUP2'; 三、删除默认临时表空间 练习 drop tablespace temp including contents and datafiles; 结论:通过测试我们不可以删除默认临时表空间 1、修改默认临时表空间语法 alter database DEFAULT TEMPORARY TABLESPACE.. 2、练习 alter database DEFAULT TEMPORARY TABLESPACE temp2; 删除temp表空间 drop tablespace temp including contents and datafile; 四、大文件表空间 1、概念 依旧是表空间,但是可以存储更多的数据 2、语法 create bigfiletablespace datafile size autoextend 3、练习 create BIGFILE tablespace mybigspace datafile 'C:\oraclefile\mybigspace.dbf' size 10M; 五、非标准数据块表空间 1、概念 非标准数据块表空间是指其数据块大小不基于标准数据块大小的表空间 2、语法 create tablespace nonstandard 3、练习 create tablespace nonstandard datafile ‘C:\oraclexe\app\oracle\oradata\XE\nostandard.dbf’ size 5M BLOCKSIZE 16K; DBA使用CREATE USER语句创建用户 create user king identified by saint; grant create session,create table, create sequence,create view to king; 综合练习 创建student(teng、buteng)、teacher(liuyunfeng、liyuyu)两组角色 给student分配create session 、 给teacher分配 create session、create table 一、创建用户 create user teng identified by 123456; create user buteng identified by 123456; create user liuyunfeng identified by 123456; create user liyuyu identified by 123456; 二、创建角色 create role teacher; create role student; 三、给student、teacher分配权限 grant create session to student; grant create session,create table to teacher; 四、将权限分配给用户 grant student to teng,buteng; grant teacher to liuyunfeng,liyuyu; 测试使用teng,liuyunfeng登录(normal) 练习: 1、修改teng为654321 alter user teng identified by 654321; 练习: 将scott用户下的emp数据表,查看对象权限分配给teng; 1、创建scott 2、在scott用户下创建数据表对象 3、分配查看权限给teng GRANT select ON emp TO teng; 1、创建用户角色 create user liyuyu identified by 123456; 2、给用户或者角色分配系统权限 grant create session to liyuyu; 3、用户或者角色分配对象权限 假设让liyuyu查询scott用户下的emp,在scott用户下: grant select on emp to liyuyu; 4、测试liyuyu用户是否能看到scott用户emp 使用liyuyu用户登录 select * from scott.emp; 二、测试使用liyuyu用户登录之后是否可以修改emp数据表中的empno为7934这个员工的收入为9000 使用scott用户登录 grant update on emp to liyuyu; 退出scott用户,登录liyuyu用户 update scott.emp set sal=9000 where empno=7934; grant update(empno) on emp to liyuyu; grant select,insert ON dept to liyuyu with grant option; (1)例如:给liyyu用户开放查看emp数据表中empno列标题下的数据值。 使用scott用户登录的时候 第一步创建empno_view视图 create view empno_view as select empno from emp; 第二步给liyuyu分配empno_view视图的查看对象权限 grant select on empno_view to liyuyu; 切换liyuyu用户 测试是不是只能看到emp数据表下的empno select * from scott.empno_view; (2)练习:收回liyuyu用户查询empno_view视图权限 使用scott登录 revoke select on empno_view from liyuyu; 测试liyuyu用户能否看到emp下的empno select * from scott.empno_view;
|
CopyRight 2018-2019 实验室设备网 版权所有 |