Oracle维护常用脚本

1、查看表空间使用情况

 

SELECT B.FILE_ID  文件ID,
         B.TABLESPACE_NAME  表空间,
         B.FILE_NAME     物理文件名,
         B.BYTES / 1024 / 1024       总兆数,
         (B.BYTES - SUM(NVL(A.BYTES, 0))) / 1024 / 1024   已使用M,
         SUM(NVL(A.BYTES, 0)) / 1024 / 1024        剩余M,
         SUM(NVL(A.BYTES, 0)) / (B.BYTES) * 100 剩余百分比   FROM DBA_FREE_SPACE A,
       DBA_DATA_FILES B   WHERE A.FILE_ID = B.FILE_ID   GROUP BY B.TABLESPACE_NAME,
       B.FILE_NAME,
       B.FILE_ID,
       B.BYTES   ORDER BY B.TABLESPACE_NAME;

 1、给表空间添加数据文件

 

alter tablespace 空间名 add datafile 
'/dev/rdata_1g_21' size 1000M autoextend off,
'/dev/rdata_1g_25' size 1000M autoextend off,
'/dev/rdata_1g_22' size 1000M autoextend off;

 2、修改在11G中无法导出空表的问题

 

   在sqlplus中,执行如下命令:
   SQL>alter system set deferred_segment_creation=false;
   查看:
   SQL>show parameter deferred_segment_creation;

 1)检查oracle系统临时表空间大小: 

select sum(bytes)/1024/1024 "temp size(M)" from dba_temp_files where tablespace_name='TEMP'; 

2)查询undo表空间大小 

select sum(bytes)/1024/1024 "current undo size(M)" from dba_data_files where tablespace_name='UNDOTBS1';

3)查询SGA和PGA: 

SQL> show parameter sga; 

获得sga_max_size和sga_target的值 

SQL> show parameter pga; 

获得pga_aggregate_target的值 

参考值:

现场服务器是8G内存,SGA设置为4G,PGA设置为1G 

现场服务器是16G内存,SGA设置为10G,PGA设置为2G 

现场服务器是32G内存,SGA设置为20G,PGA设置为4G 

修改方法: 

pfile: 

sga_max_size=4G 

sga_target=4G 

pga_aggregate_target=1G 

spfile: 

SQL> alter system set sga_max_size=4G scope=spfile; 

SQL> alter system set sga_target=4G scope=spfile; 

SQL> alter system set pga_aggregate_target=1G scope=spfile;

查看用户表空间配额

select * from user_ts_quotas;

更改用户的表空间限额:

全局:

grant unlimited tablespace to abc;

针对某个表空间:

alter user abc quota unlimited on test;

回收:

revoke unlimited tablespace from abc;

alter user abc quota 0 on test;

 

猜你喜欢

转载自binyan17.iteye.com/blog/1468852