查看重做日志文件基本属性
select group#,sequence#,members,bytes,archived,status from v$log;
增加重做日志文件组
alter database add logfile group 4 '/opt/oracle/oradb/oradata/inomc/logfile4.log' size 100M;
增加重做日志文件组成员
alter database add logfile member '/opt/oracle/oradb/oradata/inomc/logfile11.log' to group 1;
切换重做日志
alter system switch logfile;
删除重做日志文件组
alter database drop logfile group 4;
如果此时文件组为当前日志文件组或者是活动的文件组,则会提示ora-01623或者是ora-01624的错误,这时需要执行如下操作,然后才能删除日志文件组
alter system switch logfile;
alter database drop logfile group 4;
删除非活动的重做日志文件组成员
alter database drop logfile member '/opt/oracle/oradb/oradata/inomc/logfile11.log';
如果要删除的日志组成员为当前日志文件组,则会提示ora-01609的错误,需要执行如下操作后,才能删除成员
alter system switch logfile;
alter database drop logfile member '/opt/oracle/oradb/oradata/inomc/logfile11.log';
清除归档日志
alter database clear logfile group 3;(已经归档)
alter database clear unarchived logfile group 3;(未进行归档)
管理归档日志
查看数据库归档方式,两种方法:
1.
sqlplus / as sysdba
archive log list
如果显示如下信息,表明为归档模式
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /opt/oracle/oradb/archivelog
Oldest online log sequence 1
Next log sequence to archive 9
Current log sequence 9
如果显示如下信息,表明为非归档模式
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /opt/oracle/oradb/archivelog
Oldest online log sequence 1
Current log sequence 9
2. 查看动态性能视图
select log_mode from v$database
如果返回结果值为:ARCHIVELOG表明为归档模式
如果返回结果值为:NOARCHIVELOG表明为非归档模式
修改数据库为归档模式
1. 关闭数据库
shutdown --即shutdown normal模式
2. 如果有必要,先备份数据库,因为改变数据库的归档模式会修改控制文件等主要信息。
3. 启动数据库到mount状态
startup mount
4. 打开归档模式
alter database archivelog;
5. 打开数据库
alter database open;
修改数据库为非归档模式
1. 关闭数据库
shutdown --即shutdown normal模式
2. 如果有必要,先备份数据库,因为改变数据库的归档模式会修改控制文件等主要信息。
3. 启动数据库到mount状态
startup mount
4. 关闭归档模式
alter database noarchivelog
5. 打开数据库
alter database open;
修改归档进程数
alter system set log_archive_max_processes=3
修改归档目录
alter system set log_archive_dest_1=’location=/opt/oracle/oradb/archivelog’
管理表空间
查看已经存在表空间的基本信息
select tablespace_name,status,extent_management,segment_space_management from dba_tablespaces;
其中extent_management为extent的管理方式,segment_space_management为segment的管理方式
查看表空间的默认存储参数
select tablespace_name "tablespace",
initial_extent "initial_ext",
next_extent "next_ext",
min_extents "min_ext",
max_extents "max_ext",
pct_increase
from dba_tablespaces;
查看表空间大小及对应数据文件
select tablespace_name tablespace_name,
file_name file_name,
bytes / 1024 / 1024 as bytes
from dba_data_files
union all
select tablespace_name tablespace_name,
file_name file_name,
bytes / 1024 / 1024 as bytes
from dba_temp_files
查看表空间的空间使用状况
select d.tablespace_name,
space "sum_space(m)",
blocks sum_blocks,
space - nvl(free_space, 0) "used_space(m)",
round((1 - nvl(free_space, 0) / space) * 100, 2) "used_rate(%)",
free_space "free_space(m)"
from (select tablespace_name,
round(sum(bytes) / (1024 * 1024), 2) space,
sum(blocks) blocks
from dba_data_files
group by tablespace_name) d,
(select tablespace_name,
round(sum(bytes) / (1024 * 1024), 2) free_space
from dba_free_space
group by tablespace_name) f
where d.tablespace_name = f.tablespace_name(+)
union all --if have tempfile
select d.tablespace_name,
space "sum_space(m)",
blocks sum_blocks,
used_space "used_space(m)",
round(nvl(used_space, 0) / space * 100, 2) "used_rate(%)",
nvl(free_space, 0) "free_space(m)"
from (select tablespace_name,
round(sum(bytes) / (1024 * 1024), 2) space,
sum(blocks) blocks
from dba_temp_files
group by tablespace_name) d,
(select tablespace_name,
round(sum(bytes_used) / (1024 * 1024), 2) used_space,
round(sum(bytes_free) / (1024 * 1024), 2) free_space
from v$temp_space_header
group by tablespace_name) f
where d.tablespace_name = f.tablespace_name(+)
创建表空间
create tablespace imap_db datafile '/opt/oracle/oradb/oradata/inomc/imap_db01.dbf' size 10M autoextend on next 1M extent management local segment space management auto maxsize unlimited;
注:此语句创建一个extent的管理方式为local且segment的空间管理方式为auto的表空间,且无最大大小限制。
删除表空间
drop tablespace imap_db including contents and datafiles;
创建临时表空间
create temporary tablespace lmtemp tempfile '/opt/oracle/oradb/oradata/inomc/lmtemp01.dbf' size 20M autoextend on next 1M extent management local;
删除临时表空间
drop tablespace lmtemp including contents and datafiles;
查看临时表空间的空间使用
select * from dba_temp_free_space;
创建undo表空间
create undo tablespace undo2 datafile '/opt/oracle/oradb/oradata/inomc/undo2.dbf' size 10M autoextend on next 1M;
数据库只能使用一个undo表空间,如果想使用新创建的undo表空间,需要执行如下语句:
alter system set undo_tablespace=undo2 scope=spfile(此时不能使用scope=both,否则,原来的undo表空间的回滚数据将会被自动提交),参数值在下次启动时生效。
删除undo表空间
drop tablespace undo2 including contents and datafiles;
使表空间离线
alter tablespace users offline normal;(system表空间,undo表空间,temporary表空间不能离线)
使表空间上线
alter tablespace users online;
修改表空间
添加数据文件
alter tablespace users add datafile '/opt/oracle/oradb/oradata/inomc/user02.dbf' size 10M autoextend on next 1M;
删除数据文件
alter tablespace users drop datafile '/opt/oracle/oradb/oradata/inomc/user02.dbf';
添加临时数据文件
alter tablespace temp add tempfile '/opt/oracle/oradb/oradata/inomc/temp02.dbf' size 10M autoextend on next 1M;
删除临时数据文件
alter tablespace temp drop tempfile '/opt/oracle/oradb/oradata/inomc/temp02.dbf';
改变数据文件大小
alter database datafile '/opt/oracle/oradb/oradata/inomc/users01.dbf' resize 6M;
修改数据文件的可扩展性
alter database datafile '/opt/oracle/oradb/oradata/inomc/users01.dbf' autoextend on next 1M;
重命名表空间
alter tablespace users rename to userstabs;
删除表空间
drop tablespace users including contents and datafiles;(不能删除系统表空间及默认临时表间,当前的undo表空间)作者: fengerapple 时间: 2013-1-25 17:22
Thank you very much for sharing!The good man!The good life of peace!