ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 利用重建控制文件重命名数据库

利用重建控制文件重命名数据库

原创 Linux操作系统 作者:阿痕Jay 时间:2010-06-29 09:48:03 0 删除 编辑
Normal 0 7.8 pt 0 2 false false false EN-US ZH-CN X-NONE实验目的:学会重建控制文件

实验结果:数据库名(db_name)由原来的mydb变成yourdb。

实验参考:Chapter 5 of “Administrator’s Guide”

范例:

1. 查看原数据库名

         SQL> select name from v$database;

NAME

---------

MYDB

2. 备份当前控制文件

SQL> ALTER DATABASE BACKUP CONTROLFILE TO TRACE;

         备份后的文件在目录user_dump_dest下,用以下命令查看:

         SQL> show parameter user_dump_dest

         在该目录下有很多的trace文件,可以用以下命令确定哪个是刚刚生成的trace文件:

         $ ls –lt

         -rw-r-----  1 oracle oinstall 75991 Jun 28 16:09 alert_mydb.log

-rw-r-----  1 oracle oinstall  6421 Jun 28 16:09 mydb_ora_31550.trc

……

alert_mydb.log的下一个文件即使刚刚生成的trace文件。

查看该文件内容;

$ more mydb_ora_31550.trc

         找到以下这段话:(由于我们要重命名数据库,所以使用RESETLOGS案例)

--     Set #2. RESETLOGS case

--

-- The following commands will create a new control file and use it

-- to open the database.

-- Data used by Recovery Manager will be lost.

-- The contents of online logs will be lost and all backups will

-- be invalidated. Use this only if online logs are damaged.

-- After mounting the created controlfile, the following SQL

-- statement will place the database in the appropriate

-- protection mode:

--  ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE

STARTUP NOMOUNT

CREATE CONTROLFILE REUSE DATABASE "MYDB" RESETLOGS  NOARCHIVELOG

    MAXLOGFILES 6

    MAXLOGMEMBERS 5

    MAXDATAFILES 100

    MAXINSTANCES 3

    MAXLOGHISTORY 292

LOGFILE

  GROUP 1 '/oracle/db11g/oradata/mydb/redo01.log'  SIZE 100M BLOCKSIZE 512,

  GROUP 2 '/oracle/db11g/oradata/mydb/redo02.log'  SIZE 100M BLOCKSIZE 512,

  GROUP 3 '/oracle/db11g/oradata/mydb/redo03.log'  SIZE 100M BLOCKSIZE 512

-- STANDBY LOGFILE

DATAFILE

  '/oracle/db11g/oradata/mydb/system01.dbf',

  '/oracle/db11g/oradata/mydb/sysaux01.dbf',

  '/oracle/db11g/oradata/mydb/undotbs01.dbf',

  '/oracle/db11g/oradata/mydb/perm01.dbf',

  '/oracle/db11g/oradata/mydb/users01.dbf',

  '/oracle/db11g/oradata/mydb/indx01.dbf'

CHARACTER SET US7ASCII

;

-- Commands to re-create incarnation table

-- Below log names MUST be changed to existing filenames on

-- disk. Any one log file from each branch can be used to

-- re-create incarnation records.

-- ALTER DATABASE REGISTER LOGFILE '/oracle/db11g/11.2/dbs/arch1_1_722623275.dbf';

-- Recovery is required if any of the datafiles are restored backups,

-- or if the last shutdown was not normal or immediate.

RECOVER DATABASE USING BACKUP CONTROLFILE

-- Database can now be opened zeroing the online logs.

ALTER DATABASE OPEN RESETLOGS;

-- Commands to add tempfiles to temporary tablespaces.

-- Online tempfiles have complete space information.

-- Other tempfiles may require adjustment.

ALTER TABLESPACE TEMPTS1 ADD TEMPFILE '/oracle/db11g/oradata/mydb/temp01.dbf'

     SIZE 20971520  REUSE AUTOEXTEND ON NEXT 8192  MAXSIZE 32767M;;

2. 把原有的控制文件移走

SQL> show parameter control_files

NAME              TYPE        VALUE

------------------------------------ ----------- ------------------------------

control_files         string      /oracle/db11g/oradata/mydb/control01.ctl,

                                                                  /oracle/db11g/oradata/mydb/control02.ctl

$ cd /oracle/db11g/oradata/mydb

$ mv control01.ctl control01.ctl.bkp

$ mv control02.ctl control02.ctl.bkp

3. 修改pfile

db_name=yourdb

4. 重建控制文件

         SQL> startup nomount

         SQL>CREATE CONTROLFILE

SET DATABASE "YOURDB" RESETLOGS NOARCHIVELOG

    MAXLOGFILES 6

    MAXLOGMEMBERS 5

    MAXDATAFILES 100

    MAXINSTANCES 3

    MAXLOGHISTORY 292

LOGFILE

  GROUP 1 '/oracle/db11g/oradata/mydb/redo01.log'  SIZE 100M BLOCKSIZE 512,

  GROUP 2 '/oracle/db11g/oradata/mydb/redo02.log'  SIZE 100M BLOCKSIZE 512,

  GROUP 3 '/oracle/db11g/oradata/mydb/redo03.log'  SIZE 100M BLOCKSIZE 512

DATAFILE

  '/oracle/db11g/oradata/mydb/system01.dbf',

  '/oracle/db11g/oradata/mydb/sysaux01.dbf',

  '/oracle/db11g/oradata/mydb/undotbs01.dbf',

  '/oracle/db11g/oradata/mydb/perm01.dbf',

  '/oracle/db11g/oradata/mydb/users01.dbf',

  '/oracle/db11g/oradata/mydb/indx01.dbf'

CHARACTER SET US7ASCII;

5. 打开数据库并验证

         SQL> ALTER DATABASE OPEN RESETLOGS;

SQL>ALTER TABLESPACE TEMPTS1 ADD TEMPFILE '/oracle/db11g/oradata/mydb/temp01.dbf' SIZE 20971520  REUSE AUTOEXTEND ON NEXT 8192  MAXSIZE 32767M

         SQL> select name from v$database;

NAME

---------

YOURDB

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24068527/viewspace-666547/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Password file 认证
请登录后发表评论 登录
全部评论

注册时间:2010-06-10

  • 博文量
    19
  • 访问量
    18318