备份 Oracle

  1. 表单位
    1. 备份指定表
      exp icdmain/icd rows=y indexes=n compress=n buffer=65536 feedback=100000 file=exp_icdmain_table_yyyymmdd.dmp log=exp_icdmain_table_yyyymmdd.log tables=icdmain.commoninformation,icdmain.serviceinfo,icdmain.dealinfo
    2. 恢复所有的表
      imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=y file=exp_icdmain_table_yyyymmdd.dmp log=imp_icdmain_table_yyyymmdd.log
    3. 恢复其中一部分表
      imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=y file=exp_icdmain_table_yyyymmdd.dmp log=imp_icdmain_table_yyyymmdd.log tables=commoninformation,serviceinfo
  2. 用户单位
    1. 备份指定用户的所有对象
      exp icdmain/icd rows=y indexes=n compress=n buffer=65536 feedback=100000 owner=icdmain file=exp_icdmain_user_yyyymmdd.dmp log=exp_icdmain_user_yyyymmdd.log
    2. 恢复指定用户的所有对象
      imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=y file=exp_icdmain_user_yyyymmdd.dmp log=imp_icdmain_user_yyyymmdd.log
    3. 恢复指定用户的的一部分表
      imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=y file=exp_icdmain_user_yyyymmdd.dmp log=imp_icdmain_user_yyyymmdd.log tables=commoninformation,serviceinfo
  3. 整体备份
    1. 备份整个数据库
      exp system/manager rows=y indexes=n compress=n buffer=65536 feedback=100000 full=y inctype=complete file=exp_fulldb_yyyymmdd.dmp log=exp_fulldb_yyyymmdd.log
    2. 整个数据库的增量备份
      exp system/manager rows=y indexes=n compress=n buffer=65536 feedback=100000 full=y inctype=incremental file=exp_fulldb_zl_yyyymmdd.dmp log=exp_fulldb_zl_yyyymmdd.log
    3. 从整体备份恢复所有对象
      imp system/manager rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=y full=y file=exp_fulldb_yyyymmdd.dmp log=imp_fulldb_yyyymmdd.log
    4. 从增量备份恢复所有对象
      imp system/manager rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=y full=y inctype=restore file=exp_fulldb_zl_yyyymmdd.dmp log=imp_fulldb_zl_yyyymmdd.log

缩小 Oracle 表空间

———– maxshrink.sql ———————————-

SET verify off
COLUMN file_name format a50 word_wrapped
COLUMN smallest format 999,990 heading "Smallest|Size|Poss."
COLUMN currsize format 999,990 heading "Current|Size"
COLUMN savings  format 999,990 heading "Poss.|Savings"
break ON report
compute SUM OF savings ON report
 
COLUMN VALUE new_val blksize
SELECT VALUE FROM v$parameter WHERE name = 'db_block_size'
/
 
SELECT file_name,
       CEIL( (nvl(hwm,1)*&&blksize)/1024/1024 ) smallest,
       CEIL( blocks*&&blksize/1024/1024) currsize,
       CEIL( blocks*&&blksize/1024/1024) -
       CEIL( (nvl(hwm,1)*&&blksize)/1024/1024 ) savings
FROM dba_data_files a,
     ( SELECT file_id, MAX(block_id+blocks-1) hwm
         FROM dba_extents
        GROUP BY file_id ) b
WHERE a.file_id = b.file_id(+)
/
 
COLUMN cmd format a75 word_wrapped
 
SELECT 'alter database datafile '''||file_name||''' resize ' ||
       CEIL( (nvl(hwm,1)*&&blksize)/1024/1024 )  || 'm;' cmd
FROM dba_data_files a,
     ( SELECT file_id, MAX(block_id+blocks-1) hwm
         FROM dba_extents
        GROUP BY file_id ) b
WHERE a.file_id = b.file_id(+)
  AND CEIL( blocks*&&blksize/1024/1024) -
      CEIL( (nvl(hwm,1)*&&blksize)/1024/1024 ) > 0
/

转移 Oracle 的表空间

1.将表空间置于只读

只读状态可以使数据仍然可为用户访问.

ALTER tablespace tablespace_name READ ONLY;

2.物理拷贝文件

3.将表空间offline

ALTER tablespace tablespace_name offline;

4.rename数据文件

ALTER DATABASE RENAME file 'old_dir_file' TO 'new_dir_file';

5.将表空间联机

ALTER tablespace tablespace_name online;

6.将表空间置于read write模式

ALTER tablespace tablespace_name READ WRITE;

转移 Oracle 的TEMP表空间

CREATE tablespace TEMP2
datafile '/data1/ora9data/temp2_01.dbf' 
SIZE 100k TEMPORARY;

Tablespace created.

ALTER DATABASE DEFAULT TEMPORARY tablespace TEMP2;

Database altered.

DROP tablespace temp including contents AND datafiles;

Tablespace dropped.