[20201112]nid改變資料庫名字.txt

lfree發表於2020-11-12

[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部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2733656/,如需轉載,請註明出處,否則將追究法律責任。

相關文章