1、创建undo表空间
create undo tablespace xff_undo datafile
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\xff_undo1.dbf’
size 20m reuse autoextend on;
2、修改默认undo表空间
alter system set undo_tablespace=xff_undo;
3、查看undo中的transaction占用的block数目
select addr,used_ublk from v$transaction;
4、查看undo中的历史信息汇总
select begin_time,end_time,undoblks from v$undostat;
5、设置undo的过期时间(单位是s)
alter system set undo_retention=100;
6、决定undo大小
1)每秒钟undo的大小
select max(undoblks/(end_time-begin_time)*24*3600) from v$undostat;
2)undo的过期时间
show parameter undo_retention
3)oracle block的大小
show parameter db_block_size
4)上面三项相乘即为undo所需要的大小
Category Archives: Oracle
oracle之datafile,tablespace
1、创建一般tablespace
create tablespace xifenfei datafile ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\
xifenfei.DBF’ size 10m reuse autoextend on next 10m maxsize UNLIMITED ;
2、创建temp tablespace
create temporary tablespace xff_temp tempfile
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\xff_temp.dbf’ size 10m;
3、创建undo tablespace
create undo tablespace xff_undo datafile
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\xff_undo.dbf’ size 10m;
4、更改数据库的默认临时表空间
alter database default temporary tablespace xff_temp;
5、查询表空间类型
select tablespace_name,contents from dba_tablespaces;
6、查询默认临时表空间
select * from database_properties where property_name like ‘%TEMP_TABLE%’;
7、表空间变为只读状态
alter tablespace xifenfei read only;
note:该表空间中的objects可以被drop,因为表的记录是放在数据字典(system)中
8、表空间变为读写状态
alter tablespace xifenfei read write;
9、表空间offline
alter tablespace xifenfei offline;
note:如果有数据没有commit,会自动被commit掉
10、表空间online
alter tablespace xifenfei online;
11、查看表空间剩余大小
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 order by "% Free";
12、表空间自增长
alter database datafile ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\XIFENFEI.DBF
‘ autoextend on next 2m maxsize 100m;
13、表空间中添加数据文件
alter tablespace xifenfei add datafile ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\OR
CL\XIFENFEI1.DBF’ size 20m;
14、查看表空间是否是自增长
select file_name,autoextensible from dba_data_files;
15、修改表空间大小
alter database datafile ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\
XIFENFEI1.DBF’ resize 15m;
16、查询临时表空间
select tablespace_name,file_name from dba_temp_files;
17、datafile rename
1)alter tablespace xifenfei rename datafile
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\ XIFENFEI1.DBF’ to
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\abc\ XIFENFEI1.DBF’
note:target文件必须存在,表空间必须离线
2) alter database rename file ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\XIFENFEI1.DBF’
to ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\orcl\XIFENFEI1.DBF’
note:target文件必须存在,数据库必须mount状态
18、删除表空间中的某个datafile
alter tablespace xifenfei drop datafile
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\XIFENFEI1.DBF’;
19、删除表空间
drop tablespace xifenfei including contents and datafiles;
oracle之redo file
1、切换日志文件
alter system switch logfile;
2、增加联机日志组
alter database add logfile group 4 (‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\
REDO04_1.LOG’,’C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\REDO04_2.LOG’) size 10m;
3、添加联机日志文件
alter database add logfile member ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\RE
DO04_3.LOG’ to group 4;
4、删除联机日志组
alter database drop logfile group 1;
note:不会删除对应文件(见13、14)
5、删除联机日志文件
ALTER DATABASE DROP LOGFILE MEMBER ‘c:/LOCATION_DUST/REDO0N_N.LOG’;
note:不会删除对应文件(见13、14)
6、归档当前联机日志文件
alter system archive log current
7、dos删除文件
del filename
8、dos强制删除文件夹(无提示)
rd C:\oracle\product\10.2.0\oradata\orcl\A /s/q
note:/s删除一个非空文件夹 /q无提示
9、联机重做日志文件重命名或者移动
1)shutdown 数据库
2)拷贝redo文件到需要的位置(或者并重命名)
3)startup mount数据库
4) alter database rename file ‘C:\oracle\product\10.2.0\oradata\orcl\REDO01.LOG’
to ‘C:\oracle\product\10.2.0\oradata\orcl\REDO01.rdo’;
5)open 数据库
10、清空redo log file
1)不归档情况下
alter database clear logfile group 1;
2)归档情况下
alter database clear unarchived logfile group 1;
Oracle Database Online Documentation
windows下oracle手工创建和删除数据库
创建oracle_sid为feifei的数据库
1、设置oracle_sid:set oracle_sid=feifei
2、建立pfile文件:文件名为:initfeifei.ora
内容为:
feifei.__db_cache_size=79691776 feifei.__java_pool_size=4194304 feifei.__large_pool_size=4194304 feifei.__shared_pool_size=100663296 feifei.__streams_pool_size=12582912 audit_file_dest='C:\oracle\product\10.2.0/admin/feifei/adump' background_dump_dest='C:\oracle\product\10.2.0/admin/feifei/bdump' compatible='10.2.0.1.0' control_files='C:\oracle\product\10.2.0\oradata\feifei\control01.ctl','C:\oracle\product\10.2.0\oradata\feifei\control02.ctl','C:\oracle\product\10.2.0\oradata\feifei\control03.ctl' core_dump_dest='C:\oracle\product\10.2.0/admin/feifei/cdump' db_block_size=8192 db_domain='' db_file_multiblock_read_count=16 db_name='feifei' db_recovery_file_dest='C:\oracle\product\10.2.0\flash_recovery_area' db_recovery_file_dest_size=2147483648 dispatchers='(PROTOCOL=TCP) (SERVICE=feifeiXDB)' job_queue_processes=10 log_archive_dest_1='location=C:\oracle\product\10.2.0\archive' open_cursors=300 pga_aggregate_target=20971520 processes=150 remote_login_passwordfile='EXCLUSIVE' resource_limit=TRUE sga_target=209715200 sort_area_size=65536#test undo_management='AUTO' undo_tablespace='UNDOTBS1' user_dump_dest='C:\oracle\product\10.2.0/admin/feifei/udump' utl_file_dir='c:\temp'
note:如果不是很熟悉可以从其他数据库拷贝
3、建立pfile文件中的相关的文件夹
4、建立oracle服务进程,并创建oracle密码文件
oradim -new -sid %ORACLE_SID% -intpwd MYSECRETPASSWORD -startmode M
5、执行sqlplus /nolog和connect sys/MYSECRETPASSWORD as sysdba(conn / as sysdba)(两种不同的认证方式)
6、执行startup nomount命令
7、执行create database命令
create database feifei
logfile group 1 ('C:\oracle\product\10.2.0\oradata\feifei\redo1.log') size 10M,
group 2 ('C:\oracle\product\10.2.0\oradata\feifei\redo2.log') size 10M,
group 3 ('C:\oracle\product\10.2.0\oradata\feifei\redo3.log') size 10M
character set WE8ISO8859P1
national character set utf8
datafile 'C:\oracle\product\10.2.0\oradata\feifei\system.dbf'
size 50M
autoextend on
next 10M maxsize unlimited
extent management local
sysaux datafile 'C:\oracle\product\10.2.0\oradata\feifei\sysaux.dbf'
size 10M
autoextend on
next 10M
maxsize unlimited
undo tablespace UNDOTBS1
datafile 'C:\oracle\product\10.2.0\oradata\feifei\undo.dbf'
size 10M
default temporary tablespace temp
tempfile 'C:\oracle\product\10.2.0\oradata\feifei\temp.dbf'
note:可以把create database写在notepad中,然后通过@path执行
8、添加需要的表空间
create tablespace Usersdatafile 'C:\oracle\product\10.2.0\oradata\feifei\user01.dbf' size 50M autoextend on next 10M maxsize unlimited
9、执行相关的sql脚本,主要有:
C:\oracle\product\10.2.0\db_1\RDBMS\ADMIN\catalog.sql(主要是数据字典)
C:\oracle\product\10.2.0\db_1\RDBMS\ADMIN\catproc.sql(主要是pl/sql相关操作)
C:\oracle\product\10.2.0\db_1\sqlplus\admin\pupbld.sql(主要是sqlplus相关操作)
至此手工创建数据库基本完成,当然在生产系统中,创建数据库要比这个复杂的多,主要集中在创建的pfile文件和create database命令的复杂
删除oracle_sid=feifei数据库
1、注销掉windows服务的oracle进程oradim -delete -sid feifei
2、删除oracle创建的相关文件主要是:
1)C:\oracle\product\10.2.0\oradata\feifei下的文件
2)C:\oracle\product\10.2.0\admin\feifei下的文件
3)C:\oracle\product\10.2.0\db_1\database下文件名有feifei的文件
