Home » RDBMS Server » Server Administration » rename a database??????
rename a database?????? [message #59482] Tue, 25 November 2003 19:14 Go to next message
fengq
Messages: 38
Registered: October 2002
Member
Does anyone know how to rename a database rather than recreate one???

Thank you so much!
Re: rename a database?????? [message #59485 is a reply to message #59482] Wed, 26 November 2003 03:59 Go to previous messageGo to next message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
This should do the trick:
ALTER DATABASE RENAME GLOBAL_NAME to _your_new_name_
Do not enclose the new name in single quotes. The use of double quotes is accepted.

MHE
Re: rename a database?????? [message #59486 is a reply to message #59485] Wed, 26 November 2003 06:17 Go to previous messageGo to next message
Thiru
Messages: 1089
Registered: May 2002
Senior Member
Maheer
that does not rename the database, just the global_name.

For eg)
-- Get the database name
thiru@9.2.0:SQL>select name from v$Database;

NAME
------------------------------
THIRU

-- GEt the Global_name

thiru@9.2.0:SQL>select global_name from global_name;

GLOBAL_NAME
--------------------------------------------------------------------------
THIRU.US.ORACLE.COM

-- Change the global_name to TEST

thiru@9.2.0:SQL>alter database rename global_name to TEST;

Database altered.

thiru@9.2.0:SQL>select global_name from global_name;

GLOBAL_NAME
--------------------------------------------------------------------------
TEST.US.ORACLE.COM

-- The database name remains the same

thiru@9.2.0:SQL>select name from v$Database;

NAME
------------------------------
THIRU

-- Now I can change the global_name back to default

thiru@9.2.0:SQL>alter database rename global_name to THIRU;

Database altered.

thiru@9.2.0:SQL>select global_name from global_name;

GLOBAL_NAME
--------------------------------------------------------------------------
THIRU.US.ORACLE.COM

Changing the database name in 8i and prior involved a number of steps.
Feng, see Mahesh Rajendran's earlier post about those steps. Basically you recreate the controlfile with SET DATABASE clause to update the controlfile and the datafiles , to perform the rename.

If you are in 9i, you can use the NID utility to change the database name easily.

Here's an extract from the documentation of how to do this :

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

The following steps describe how to change the database name without changing the DBID.

Ensure that you have a recoverable whole database backup.
Ensure that the target database is mounted but not open, and that it was shut down consistently prior to mounting. For example:
SHUTDOWN IMMEDIATE
STARTUP MOUNT

Invoke the utility on the command line, specifying a valid user with the SYSDBA privilege. You must specify both the DBNAME and SETNAME parameters. This example changes the name to test_db2:
% nid TARGET=SYS/oracle@test_db DBNAME=test_db2 SETNAME=YES

DBNEWID performs validations in the headers of the control files (not the datafiles) before attempting I/O to the files. If validation is successful, then DBNEWID prompts for confirmation, changes the database name in the control files, and exits. After DBNEWID completes successfully, the database is left mounted but is not yet usable.

DBNEWID: Release 9.2.0.1.0

(c) Copyright 2002 Oracle Corporation. All rights reserved.

Connected to database TEST_DB (DBID=3942196782)

Control Files in database:
/oracle/dbs/cf1.f
/oracle/dbs/cf2.f

Change database name of database TEST_DB to TEST_DB2? (Y/[[N]]) => Y

Proceeding with operation

Database name changed from TEST_DB to TEST_DB2 - database needs to be
shutdown.
Modify parameter file and generate a new password file before restarting.

DBNEWID - Successfully changed database name

If validation is not successful, then DBNEWID terminates and leaves the target database intact. You can open the database, fix the error, and then either resume the DBNEWID operation or continue using the database without changing the database name.

Shut down the database. For example:
SHUTDOWN IMMEDIATE

Set the DB_NAME initialization parameter in the initialization parameter file to the new database name.
Create a new password file.
Start up the database and resume normal use. For example:
STARTUP

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

-Thiru
Oops ..misspelt Maaher [message #59494 is a reply to message #59486] Wed, 26 November 2003 14:43 Go to previous messageGo to next message
Thiru
Messages: 1089
Registered: May 2002
Senior Member
sorry about the spelling mistake!
Re: rename a database?????? [message #59495 is a reply to message #59486] Wed, 26 November 2003 15:22 Go to previous message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
Well, I'm only a humble developer after all. I leave most DBA stuff to those who know best ;-)

MHE
Previous Topic: Session Parameters
Next Topic: bcv copy -> duplicate rows prim key
Goto Forum:
  


Current Time: Fri Sep 20 15:39:55 CDT 2024