手工修改Oracle資料庫DBNAME-轉載
手工修改資料庫DBNAME
對於沒有NID的情況,如何修改資料庫的DBNAME呢,可以按照以下的做法,不過做之前請備份資料庫,以防不測
對於沒有NID的情況,如何修改資料庫的DBNAME呢,可以按照以下的做法,不過做之前請備份資料庫,以防不測
PURPOSE
This entry describes how to find and change the "db_name" for a database, or
the ORACLE_SID for an instance, without recreating the database.
SCOPE & APPLICATION
For DBAs requiring to either find or change the db_name or ORACLE_SID.
RELATED DOCUMENTS
Note 1018634.102 AFTER RENAMING THE DATABASE SELECT FROM DUAL RETURNS
OLD DATABASE NAME
Note 9560.1 ALTER TABLESPACE/DATABASE TO RENAME FILES
Note 61590.1 Renaming an existing Windows NT database(For Windows)
To find the current DB_NAME and ORACLE_SID:
===========================================
Query the views v$database and v$thread.
V$DATABASE gives DB_NAME
V$THREAD gives ORACLE_SID
If ORACLE_SID = DB_SID and db_name = DBNAME:
To find the current value of ORACLE_SID:
(For Oracle9i/Oracle10g, must use SQL*Plus)
SVRMGR> select instance from v$thread;
INSTANCE
----------------
DB_SID
To find the current value of DB_NAME:
SVRMGR> select name from v$database;
NAME
---------
DBNAME
Modifying a database to run under a new ORACLE_SID:
===================================================
1. Shutdown the instance
The database must be shutdown with SHUTDOWN NORMAL or SHUTDOWN IMMEDIATE.
It must not be shutdown abnormally using SHUTDOWN ABORT.
2. Backup all control, redo, and data files.
3. Go through the .profile, .cshrc, .login, oratab, tnsnames.ora,
(for SQL*Net version 2), and redefine the ORACLE_SID environment
variable to a new value.
For example, search through disks and do a grep ORACLE_SID *
4. Change locations to the "dbs" directory
% cd $ORACLE_HOME/dbs
and rename the following files:
o init.ora (or use pfile to point to the init file)
o control file(s). This is optional if you do not rename any
of the controlfiles, and the control_files parameter is used.
The "control_files" parameter is set in the "init.ora" file
or in a file it references with the ifile parameter. Make
sure that the control_file parameter does not point to old
file names, if they have been renamed.
o "crdb.sql" &
"crdb2.sql", This is optional, these are
only used at database creation.
NOTE: for Oracle9i/Oracle10g if using an SPFILE: You must rename it (i.e. spfile.ora)
along with changing parameter values in the SPFILE. Please review the following
for more information on SPFILE.
Note 162491.1 Spfile
and Init.ora Parameter File Startup of an Oracle9i Instance
Note 137483.1 How to Modify the Content of an SPFILE Parameter File
5. To rename the database files and redo log files, follow the
instructions in Note 9560.1.
6. Change the ORACLE_SID environment variable to the new value.
7. Check in the "$ORACLE_HOME/dbs" directory to see if the password
file has been enabled. If enabled, the file "orapw" will
exist and a new password file for the new SID must be created
(renaming the old file will not work). If "orapw" does not
exist, skip to step 8. To create a new password file, issue
the following command as oracle owner:
orapwd file=orapw password=?? entries= granted permission to start the database instance>
8. Start up the database and verify that it works. Once this is done,
shutdown the database and take a final backup of all control, redo,
and data files.
The database must be shutdown with SHUTDOWN NORMAL or SHUTDOWN IMMEDIATE.
It must not be shutdown abnormally using SHUTDOWN ABORT.
9. When the instance is started, the control file is updated with the
current ORACLE_SID.
Changing the "db_name" for a Database:
======================================
1. Login to Server Manager (Oracle7 through Oracle8i)/ SQL*Plus for Oracle9i/Oracle10g
% svrmgrl
SVRMGR> connect internal
NOTE: For Oracle9i/Oracle10g, must use SQL*Plus (svrmgrl is obsolete after Oracle8i)
% sqlplus "/ as sysdba"
2. Type
SVRMGR> alter system switch logfile;
to force a checkpoint.
3. Type
SVRMGR> alter database backup controlfile to trace resetlogs;
This will create a trace file containing the "CREATE CONTROLFILE"
command to recreate the controlfile in its current form.
4. Shutdown the database and exit SVRMGR
SVRMGR> shutdown
SVRMGR> exit
The database must be shutdown with SHUTDOWN NORMAL or SHUTDOWN IMMEDIATE.
It must not be shutdown abnormally using SHUTDOWN ABORT.
5. Change locations to the directory where the trace files are located.
They are usually in the "$ORACLE_HOME/rdbms/log" directory. If
"user_dump_dest" is set in the "init.ora" file, then go to the
directory listed in the "user_dump_dest" variable. The trace file will
have the form. "ora_NNNN.trc with NNNN being a number.
NOTE: for Oracle9i/Oracle10g if using an SPFILE: Please review the following for
changing parameter values in the SPFILE.
Note 137483.1 How to
Modify the Content of an SPFILE Parameter File
6. Copy the contents of the trace file starting from the line with
STARTUP NOMOUNT down to the end of the trace file and put it in
a new file called something like "ccf.sql".
7. Edit the "ccf.sql" file
FROM: CREATE CONTROLFILE REUSE DATABASE "olddbname" RESETLOGS ...
TO: CREATE CONTROLFILE set DATABASE "newdbname" RESETLOGS ...
Change the word 'REUSE' to 'set' and the 'olddbname' to 'newdbname'.
It is possible to recreate the controlfile using the syntax:
CREATE CONTROLFILE REUSE set DATABASE "newdbname" RESETLOGS ...
But this syntax will allow the existing controlfiles to be overwritten
without giving an error.
FROM:
# 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
TO:
# 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
The last command in ccf.sql should be:
alter database open resetlogs
NOTE : In cases of Oracle 9i, the script. must to be modified and
#(as comments) changed to -- as "#" is not recognized as a comment
in SQL*Plus
8. Save and exit the "ccf.sql" file
9. Rename the old control files for backup purposes and so that they do
not exist when creating the new ones.
10. Edit the "init.ora" file so that db_name="newdb_name" .
NOTE: for Oracle9i/Oracle10g if using an SPFILE: Please review the following for
changing parameter values in the SPFILE.
Note 137483.1 How to
Modify the Content of an SPFILE Parameter File
11. Login to Server Manager
% svrmgrl
SVRMGR> connect internal
NOTE: For Oracle9i/Oracle10g, must use SQL*Plus (svrmgrl is obsolete after Oracle8i)
% sqlplus "/ as sysdba"
12. Run the "ccf.sql" script.
SVRMGR> @ccf
This will issue a startup nomount, and then recreate the controlfile.
If, at this point, an error stating that a file needs media recovery
is reported, then the database was not shutdown normally as specified
in step 4. Try recovering the database using the redo in the current
logfile, by issuing:
SVRMGRL> recover database using backup controlfile until cancel;
This will prompt for an archived redologfile. It may be possible to
open the database after applying the current logfile. BUT this is not
guaranteed.
To apply the necessary redo, check the online logfiles and apply the
one with the same sequence number as reported in the message. This
usually is the logfile with status=CURRENT. If not apply, the logfiles
in turn until the logfile with status=CURRENT has been applied. If,
after applying the current logfile, the database will not open then it
is highly likely that the operation must be restarted having shutdown
the database normally.
To find a list of the online logfiles:
SVRMGR> select group#, seq#, status from v$log;
GROUP# SEQUENCE# STATUS
---------- --------- ----------------
1 123 CURRENT <== this redo needs to be applied
2 124 INACTIVE
3 125 INACTIVE
4 126 INACTIVE
5 127 INACTIVE
6 128 INACTIVE
7 129 INACTIVE
7 rows selected.
SVRMGR> select member
from v$logfile
where GROUP# = 1;
Member
------------------------------------
/u02/oradata/V815/redoV81501.log
After applying the current online log file the following prompt should
be displayed:
Log Applied
Media Recovery Complete
At this point the database can be opened with:
SVRMGR> alter database open resetlogs;
13. The global database name may also need to be changed:
alter database rename global_name to.
See Note 1018634.102 for
further detail.
14. Make sure the database is working.
15. Shutdown and backup the database.
The database must be shutdown with SHUTDOWN NORMAL or SHUTDOWN IMMEDIATE.
It must not be shutdown abnormally using SHUTDOWN ABORT.
This entry describes how to find and change the "db_name" for a database, or
the ORACLE_SID for an instance, without recreating the database.
SCOPE & APPLICATION
For DBAs requiring to either find or change the db_name or ORACLE_SID.
RELATED DOCUMENTS
Note 1018634.102 AFTER RENAMING THE DATABASE SELECT FROM DUAL RETURNS
OLD DATABASE NAME
Note 9560.1 ALTER TABLESPACE/DATABASE TO RENAME FILES
Note 61590.1 Renaming an existing Windows NT database(For Windows)
To find the current DB_NAME and ORACLE_SID:
===========================================
Query the views v$database and v$thread.
V$DATABASE gives DB_NAME
V$THREAD gives ORACLE_SID
If ORACLE_SID = DB_SID and db_name = DBNAME:
To find the current value of ORACLE_SID:
(For Oracle9i/Oracle10g, must use SQL*Plus)
SVRMGR> select instance from v$thread;
INSTANCE
----------------
DB_SID
To find the current value of DB_NAME:
SVRMGR> select name from v$database;
NAME
---------
DBNAME
Modifying a database to run under a new ORACLE_SID:
===================================================
1. Shutdown the instance
The database must be shutdown with SHUTDOWN NORMAL or SHUTDOWN IMMEDIATE.
It must not be shutdown abnormally using SHUTDOWN ABORT.
2. Backup all control, redo, and data files.
3. Go through the .profile, .cshrc, .login, oratab, tnsnames.ora,
(for SQL*Net version 2), and redefine the ORACLE_SID environment
variable to a new value.
For example, search through disks and do a grep ORACLE_SID *
4. Change locations to the "dbs" directory
% cd $ORACLE_HOME/dbs
and rename the following files:
o init
o control file(s). This is optional if you do not rename any
of the controlfiles, and the control_files parameter is used.
The "control_files" parameter is set in the "init
or in a file it references with the ifile parameter. Make
sure that the control_file parameter does not point to old
file names, if they have been renamed.
o "crdb
only used at database creation.
NOTE: for Oracle9i/Oracle10g if using an SPFILE: You must rename it (i.e. spfile
along with changing parameter values in the SPFILE. Please review the following
for more information on SPFILE.
Note 137483.1 How to Modify the Content of an SPFILE Parameter File
5. To rename the database files and redo log files, follow the
instructions in Note 9560.1.
6. Change the ORACLE_SID environment variable to the new value.
7. Check in the "$ORACLE_HOME/dbs" directory to see if the password
file has been enabled. If enabled, the file "orapw
exist and a new password file for the new SID must be created
(renaming the old file will not work). If "orapw
exist, skip to step 8. To create a new password file, issue
the following command as oracle owner:
orapwd file=orapw
8. Start up the database and verify that it works. Once this is done,
shutdown the database and take a final backup of all control, redo,
and data files.
The database must be shutdown with SHUTDOWN NORMAL or SHUTDOWN IMMEDIATE.
It must not be shutdown abnormally using SHUTDOWN ABORT.
9. When the instance is started, the control file is updated with the
current ORACLE_SID.
Changing the "db_name" for a Database:
======================================
1. Login to Server Manager (Oracle7 through Oracle8i)/ SQL*Plus for Oracle9i/Oracle10g
% svrmgrl
SVRMGR> connect internal
NOTE: For Oracle9i/Oracle10g, must use SQL*Plus (svrmgrl is obsolete after Oracle8i)
% sqlplus "/ as sysdba"
2. Type
SVRMGR> alter system switch logfile;
to force a checkpoint.
3. Type
SVRMGR> alter database backup controlfile to trace resetlogs;
This will create a trace file containing the "CREATE CONTROLFILE"
command to recreate the controlfile in its current form.
4. Shutdown the database and exit SVRMGR
SVRMGR> shutdown
SVRMGR> exit
The database must be shutdown with SHUTDOWN NORMAL or SHUTDOWN IMMEDIATE.
It must not be shutdown abnormally using SHUTDOWN ABORT.
5. Change locations to the directory where the trace files are located.
They are usually in the "$ORACLE_HOME/rdbms/log" directory. If
"user_dump_dest" is set in the "init
directory listed in the "user_dump_dest" variable. The trace file will
have the form. "ora_NNNN.trc with NNNN being a number.
NOTE: for Oracle9i/Oracle10g if using an SPFILE: Please review the following for
changing parameter values in the SPFILE.
6. Copy the contents of the trace file starting from the line with
STARTUP NOMOUNT down to the end of the trace file and put it in
a new file called something like "ccf.sql".
7. Edit the "ccf.sql" file
FROM: CREATE CONTROLFILE REUSE DATABASE "olddbname" RESETLOGS ...
TO: CREATE CONTROLFILE set DATABASE "newdbname" RESETLOGS ...
Change the word 'REUSE' to 'set' and the 'olddbname' to 'newdbname'.
It is possible to recreate the controlfile using the syntax:
CREATE CONTROLFILE REUSE set DATABASE "newdbname" RESETLOGS ...
But this syntax will allow the existing controlfiles to be overwritten
without giving an error.
FROM:
# 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
TO:
# 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
The last command in ccf.sql should be:
alter database open resetlogs
NOTE : In cases of Oracle 9i, the script. must to be modified and
#(as comments) changed to -- as "#" is not recognized as a comment
in SQL*Plus
8. Save and exit the "ccf.sql" file
9. Rename the old control files for backup purposes and so that they do
not exist when creating the new ones.
10. Edit the "init
NOTE: for Oracle9i/Oracle10g if using an SPFILE: Please review the following for
changing parameter values in the SPFILE.
11. Login to Server Manager
% svrmgrl
SVRMGR> connect internal
NOTE: For Oracle9i/Oracle10g, must use SQL*Plus (svrmgrl is obsolete after Oracle8i)
% sqlplus "/ as sysdba"
12. Run the "ccf.sql" script.
SVRMGR> @ccf
This will issue a startup nomount, and then recreate the controlfile.
If, at this point, an error stating that a file needs media recovery
is reported, then the database was not shutdown normally as specified
in step 4. Try recovering the database using the redo in the current
logfile, by issuing:
SVRMGRL> recover database using backup controlfile until cancel;
This will prompt for an archived redologfile. It may be possible to
open the database after applying the current logfile. BUT this is not
guaranteed.
To apply the necessary redo, check the online logfiles and apply the
one with the same sequence number as reported in the message. This
usually is the logfile with status=CURRENT. If not apply, the logfiles
in turn until the logfile with status=CURRENT has been applied. If,
after applying the current logfile, the database will not open then it
is highly likely that the operation must be restarted having shutdown
the database normally.
To find a list of the online logfiles:
SVRMGR> select group#, seq#, status from v$log;
GROUP# SEQUENCE# STATUS
---------- --------- ----------------
1 123 CURRENT <== this redo needs to be applied
2 124 INACTIVE
3 125 INACTIVE
4 126 INACTIVE
5 127 INACTIVE
6 128 INACTIVE
7 129 INACTIVE
7 rows selected.
SVRMGR> select member
from v$logfile
where GROUP# = 1;
Member
------------------------------------
/u02/oradata/V815/redoV81501.log
After applying the current online log file the following prompt should
be displayed:
Log Applied
Media Recovery Complete
At this point the database can be opened with:
SVRMGR> alter database open resetlogs;
13. The global database name may also need to be changed:
alter database rename global_name to
See
14. Make sure the database is working.
15. Shutdown and backup the database.
The database must be shutdown with SHUTDOWN NORMAL or SHUTDOWN IMMEDIATE.
It must not be shutdown abnormally using SHUTDOWN ABORT.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17252115/viewspace-749086/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 手工建立oracle資料庫(轉)Oracle資料庫
- Oracle 手工建立資料庫Oracle資料庫
- 手工建立oracle資料庫Oracle資料庫
- 手工刪除oracle資料庫Oracle資料庫
- 【手工建庫】手工方式建立 ORACLE資料庫全程記錄Oracle資料庫
- 轉載oracle資料庫鎖Oracle資料庫
- 【原創】手工建立Oracle資料庫Oracle資料庫
- Oracle 9 手工建庫(轉)Oracle
- Oracle11g 手工建立資料庫Oracle資料庫
- 手工建立ORACLE 11g 資料庫Oracle資料庫
- oracle10g手工建立資料庫Oracle資料庫
- Oracle 10g手工建立資料庫Oracle 10g資料庫
- 手工建立oracle資料庫的過程Oracle資料庫
- 單例項資料庫手工轉化多例項資料庫單例資料庫
- Oracle 中手工建立資料庫的語法Oracle資料庫
- 手工建立資料庫資料庫
- 概述Oracle中的資料庫名---轉載Oracle資料庫
- 【轉載】[效能分析]Oracle資料庫效能模型Oracle資料庫模型
- 如何手工刪除oracle資料庫和軟體Oracle資料庫
- ORACLE資料庫修改資料庫名db_nameOracle資料庫
- Oracle手工修改JOB屬性Oracle
- 手工命令建立資料庫資料庫
- 轉載如何修改oracle資料庫字符集_及如何繞過超集報錯Oracle資料庫
- 修改Oracle資料庫字符集Oracle資料庫
- oracle資料庫修改連線數Oracle資料庫
- 修改Oracle資料庫表的大小Oracle資料庫
- 手工建立(Create)一個Oracle 10g資料庫Oracle 10g資料庫
- 手工建立oracle示例資料庫schema (Database Examples 安裝)Oracle資料庫Database
- oracle xe 10g 手工建立資料庫 for windows XPOracle資料庫Windows
- 【oracle手工建庫】Oracle
- oracle手工建庫Oracle
- 修改資料庫字符集(轉)資料庫
- (轉)手工升級資料庫10.1到10.2資料庫
- [Oracle]Oracle資料庫資料被修改或者刪除恢復資料Oracle資料庫
- [轉] 使用NID 修改資料庫名(Oracle9或以上)資料庫Oracle
- 修改oracle9i資料庫字符集的方法(轉)Oracle資料庫
- (轉載)Oracle資料庫字符集問題解析Oracle資料庫
- 手動建立 Oracle9i 資料庫(轉載)Oracle資料庫