ITPub博客

首页 > 数据库 > Oracle > [20201112]nid改变数据库名字.txt

[20201112]nid改变数据库名字.txt

原创 Oracle 作者:lfree 时间:2020-11-12 09:00:33 1 删除 编辑

[20201112]nid改变数据库名字.txt

$ nid
DBNEWID: Release 11.2.0.4.0 - Production on Thu Nov 12 08:40:15 2020
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Keyword     Description                    (Default)
----------------------------------------------------
TARGET      Username/Password              (NONE)
DBNAME      New database name              (NONE)
LOGFILE     Output Log                     (NONE)
REVERT      Revert failed change           NO
SETNAME     Set a new database name only   NO
APPEND      Append to output log           NO
HELP        Displays these messages        NO

--//很明显nid支持仅仅修改数据库名字,测试看看。

SYS@book> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SYS@book> startup mount
ORACLE instance started.
Total System Global Area  643084288 bytes
Fixed Size                  2255872 bytes
Variable Size             205521920 bytes
Database Buffers          427819008 bytes
Redo Buffers                7487488 bytes
Database mounted.

$ nid TARGET=sys/oracle DBNAME=bookx SETNAME=YES
DBNEWID: Release 11.2.0.4.0 - Production on Thu Nov 12 08:43:24 2020
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
Connected to database BOOK (DBID=1337401710)
Connected to server version 11.2.0

Control Files in database:
    /mnt/ramdisk/book/control01.ctl
    /mnt/ramdisk/book/control02.ctl

Change database name of database BOOK to BOOKX? (Y/[N]) => Y

Proceeding with operation
Changing database name from BOOK to BOOKX
    Control File /mnt/ramdisk/book/control01.ctl - modified
    Control File /mnt/ramdisk/book/control02.ctl - modified
    Datafile /mnt/ramdisk/book/system01.db - wrote new name
    Datafile /mnt/ramdisk/book/sysaux01.db - wrote new name
    Datafile /mnt/ramdisk/book/undotbs01.db - wrote new name
    Datafile /mnt/ramdisk/book/users01.db - wrote new name
    Datafile /mnt/ramdisk/book/example01.db - wrote new name
    Datafile /mnt/ramdisk/book/tea01.db - wrote new name
    Datafile /mnt/ramdisk/book/temp01.db - wrote new name
    Control File /mnt/ramdisk/book/control01.ctl - wrote new name
    Control File /mnt/ramdisk/book/control02.ctl - wrote new name
    Instance shut down

Database name changed to BOOKX.
Modify parameter file and generate a new password file before restarting.
Succesfully changed database name.
DBNEWID - Completed succesfully.

$ cp initbook.ora initbookx.ora
--//修改initbookx.ora如下:
--//注建立initbook.ora过程有点遗漏,后面补充。
 $ grep bookx initbookx.ora
bookx.__db_cache_size=377487360
bookx.__java_pool_size=12582912
bookx.__large_pool_size=12582912
bookx.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
bookx.__pga_aggregate_target=4294967296
bookx.__sga_target=645922816
bookx.__shared_io_pool_size=0
bookx.__shared_pool_size=209715200
bookx.__streams_pool_size=0
*.db_name='bookx'

$ export ORACLE_SID=bookx

SYS@bookx> startup mount
ORACLE instance started.

Total System Global Area  643084288 bytes
Fixed Size                  2255872 bytes
Variable Size             205521920 bytes
Database Buffers          427819008 bytes
Redo Buffers                7487488 bytes
Database mounted.

--//注意启动有点慢是正常的,因为要建立许多目录以及相关信息。

SYS@bookx> alter database open read only ;
Database altered.

--//说明改名不需要resetlogs。

SYS@bookx> select * from scott.dept;
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON

--//再修改回来.

SYS@bookx> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SYS@bookx> startup mount
ORACLE instance started.
Total System Global Area  643084288 bytes
Fixed Size                  2255872 bytes
Variable Size             205521920 bytes
Database Buffers          427819008 bytes
Redo Buffers                7487488 bytes
Database mounted.

$ export ORACLE_SID=book

$ nid TARGET=sys/oracle DBNAME=book SETNAME=YES
DBNEWID: Release 11.2.0.4.0 - Production on Thu Nov 12 08:52:28 2020
Connected to database BOOKX (DBID=1337401710)
Connected to server version 11.2.0

Control Files in database:
    /mnt/ramdisk/book/control01.ctl
    /mnt/ramdisk/book/control02.ctl

Change database name of database BOOKX to BOOK? (Y/[N]) => Y

Proceeding with operation
Changing database name from BOOKX to BOOK
    Control File /mnt/ramdisk/book/control01.ctl - modified
    Control File /mnt/ramdisk/book/control02.ctl - modified
    Datafile /mnt/ramdisk/book/system01.db - wrote new name
    Datafile /mnt/ramdisk/book/sysaux01.db - wrote new name
    Datafile /mnt/ramdisk/book/undotbs01.db - wrote new name
    Datafile /mnt/ramdisk/book/users01.db - wrote new name
    Datafile /mnt/ramdisk/book/example01.db - wrote new name
    Datafile /mnt/ramdisk/book/tea01.db - wrote new name
    Datafile /mnt/ramdisk/book/temp01.db - wrote new name
    Control File /mnt/ramdisk/book/control01.ctl - wrote new name
    Control File /mnt/ramdisk/book/control02.ctl - wrote new name
    Instance shut down

Database name changed to BOOK.
Modify parameter file and generate a new password file before restarting.
Succesfully changed database name.
DBNEWID - Completed succesfully.


SYS@book> startup
ORACLE instance started.

Total System Global Area  643084288 bytes
Fixed Size                  2255872 bytes
Variable Size             205521920 bytes
Database Buffers          427819008 bytes
Redo Buffers                7487488 bytes
Database mounted.
Database opened.

--//补充建立initbook.ora的步骤。
SYS@book> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

$ rlsql
SQL*Plus: Release 11.2.0.4.0 Production on Thu Nov 12 08:55:34 2020
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to an idle instance.

SYS@book> create pfile='/tmp/@.ora' from spfile ;
File created.
--//执行该命令不需要nomount或者mount数据库。

SYS@book> host ls -l /tmp/book.ora
-rw-r--r-- 1 oracle oinstall 1966 Nov 12 08:55 /tmp/book.ora


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

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7969378