Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2734880
  • 博文数量: 423
  • 博客积分: 7770
  • 博客等级: 少将
  • 技术积分: 4766
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-09 11:58
个人简介

Oracle/DB2/Postgresql/Mysql/Hadoop/Greenplum/Postgres-xl/Mongodb

文章分类

全部博文(423)

文章存档

2019年(3)

2018年(6)

2017年(27)

2016年(23)

2015年(30)

2014年(16)

2013年(31)

2012年(73)

2011年(45)

2010年(14)

2009年(30)

2008年(30)

2007年(63)

2006年(32)

分类: Oracle

2009-08-27 08:02:16


                             管理数据库表空间
SQL>create user han identified by han default tablespace tank
SQL>grant connect,resource to han;
切换用户:han/han
SQL> create table t (id integer,name char(20));
SQL> insert into t values(0,'han');
SQL> select * from t;
SQL> commit;
SQL> insert into t values(1,'dfdf');
切换用户:system/system
SQL> alter tablespace tank read only; --> 修改表空间为:只读 (不能执行.)

切换用户:han/han
SQL> commit; ---提交完,修改表空间更为只读.
SQL> insert into t values(5, 'dfdf'); 不能插入数据:
SQL> delete from t where id=0;  不能删除数据
SQL> truncate table t;  不能清空表数据.

SQL> drop table t; 可以删除表:

更换用户:system/system
SQL>  alter tablespace tank read write; 将表改为读写模式:

可以将大量的静态数据设置为只读表空间:

SQL> alter tablespace tank offline; 将表空间离线:

更换用户:tank/tank
SQL>select * from tt; 不查询数据库:
 
更换用户:system/system
alter tablespace tank online :挂上表空间.
 
 
 

查看表空间使用情况语句:
col tablespace_name format a10;
select f.tablespace_name,a.total,u.used,f.free,round((u.used/a.total)*100) "% used",
  round((f.free/a.total)*100) "% Free"
  from
  (select tablespace_name, sum(bytes/(1024*1024)) total
       from dba_data_files group by tablespace_name) a,
  (select tablespace_name, round(sum(bytes/(1024*1024))) used
       from dba_extents group by tablespace_name) u,
  (select tablespace_name, round(sum(bytes/(1024*1024))) free
       from dba_free_space group by tablespace_name) f
WHERE a.tablespace_name = f.tablespace_name
and a.tablespace_name = u.tablespace_name;
 
 
 
向表空间里增加数据文件达到达到扩大表空间大少.
  1  alter tablespace tank add datafile
  2  '/u01/oradata/tank/tank2.dbf'size 20M
  3* autoextend on next 10M maxsize 100M
SQL> /
 
创建表空间时指定大小为自动增长.
Create tablespace user_data
'/u01/oradata/tank/tank4.dbf'size 100M
autoextend on next 10M maxsize 500M;
 
查看数据文件的状态:
select file_name,tablespace_name,autoextensible from dba_data_files;

阅读(1419) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~