Saturday, August 7, 2010

Changing Global Database Name and Domain Name in RAC

Some definitions from the Oracle Reference guide first
"DB_DOMAIN
In a distributed database system, DB_DOMAIN specifies the logical location of the database within the network structure. You should set this parameter if this database is or ever will be part of a distributed system. The value consists of the extension components of a global database name, consisting of valid identifiers (any alphanumeric ASCII characters), separated by periods. Oracle recommends that you specify DB_DOMAIN as a unique string for all databases in a domain.
If you omit the domains from the name of a database link, Oracle expands the name by qualifying the database with the domain of your local database as it currently exists in the data dictionary, and then stores the link name in the data dictionary. The characters valid in a database domain name are: alphanumeric characters, underscore (_), and number sign (#).

DB_NAME
DB_NAME specifies a database identifier of up to 8 characters. This parameter must be specified and must correspond to the name specified in the CREATE DATABASE statement.
The following characters are valid in a database name: alphanumeric characters, underscore (_), number sign (#), and dollar sign ($). No other characters are valid. Oracle removes double quotation marks before processing the database name. Therefore you cannot use double quotation marks to embed other characters in the name. The database name is case insensitive.
"

If an invalid character is entered as the database name into DBCA, it automatically substring the database name such that it contains all the valid character before the first invalid character.


But there's nothing to prevent entering an invalid character entered as part of the domain name (except the knowledge of the db_domain's valid characters). It's possible to enter global database name as "TEST.DOMAIN-NET" and create the database and continue to use it, even on a RAC environment.

But an error is thrown when trying to create a materialized view using database link as in basic replication
SQL> create materialized view abc refresh fast with primary key start with sysdate next sysdate + 1/(24*60) as (select * from abc@std11g1);
create materialized view abc refresh fast with primary key start with sysdate next sysdate + 1/(24*60) as (select * from abc@std11g1)
*
ERROR at line 1:
ORA-02083: database name has illegal character '-'
This was tested using 11gR1 standard edtion (primary has correct alphanumeric characters in the global database name, while replica was created with test.domain-net).

This is when you have to change the domain name and the global database name along with it. From the Oracle Admin Guide "The global database name consists of the user-specified local database name and the location of the database within a network structure. The DB_NAME initialization parameter determines the local name component of the database name, and the DB_ DOMAIN parameter, which is optional, indicates the domain (logical location) within a network structure.

You can rename the GLOBAL_NAME of your database using the ALTER DATABASE RENAME GLOBAL_NAME statement. However, you must also shut down and restart the database after first changing the DB_NAME and DB_DOMAIN initialization parameters and recreating the control files.
"

Current global database name
SQL> select * from global_name;

GLOBAL_NAME
-------------------
CLUSDB.DOMAIN-NET
database name
SQL> select name,db_unique_name from v$database;

NAME DB_UNIQUE_NAME
--------- ---------------
CLUSDB clusdb
Instance name
SQL> select instance_name from v$instance;

INSTANCE_NAME
-------------
clusdb1
Since database name (DB_NAME) is not changed all that is required is to change the global database name and the DB_DOMAIN parameter. If the DB_NAME is been changed then DBNEWID utility must be used. "The DBNEWID utility does not change global database names."

Change the global name while the database online
ALTER DATABASE RENAME GLOBAL_NAME TO clusdb.domain.net;
ALTER DATABASE RENAME GLOBAL_NAME TO clusdb.domain.net
ERROR at line 1:
ORA-01109: database not open

SQL> ALTER DATABASE RENAME GLOBAL_NAME TO clusdb.domain.net;
Database altered.
Change the DB_DOMAIN parameter, in RAC this parameter must be same on all instances
SQL> alter system set db_domain='domain.net' scope=spfile;
System altered.
On a single instance database this should be enough, once the database is bounced the new domain name and global database name will take effect. On a RAC environment it requires bit more work.
srvctl config database -d clusdb
Database unique name: clusdb
Database name:
Oracle home: /opt/app/oracle/product/11.2.0/clusdb
Oracle user: oracle
Spfile: +DATA/clusdb/spfileclusdb.ora
Domain: domain-net
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools: clusdb
Database instances: clusdb1
Disk Groups: DATA,FLASH
Services:
Database is administrator managed
One way to change this to update the domain information with
srvctl modify database -d rac11g -m domain.net
Another would be to remove the database and add it again, both these method has been tested and proved fine.
srvctl stop database -d clusdb
srvctl remove database -d clusdb
Remove the database clusdb? (y/[n]) y
srvctl add database -d clusdb -o $ORACLE_HOME
srvctl add instance -d clusdb -i clusdb1 -n hpc1
srvctl start database -d clusdb
srvctl config database -d clusdb
Database unique name: clusdb
Database name:
Oracle home: /opt/app/oracle/product/11.2.0/clusdb
Oracle user: oracle
Spfile:
Domain: domain.net
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools: clusdb
Database instances: clusdb1
Disk Groups:
Services:
Database is administrator managed
Add the other configuration values to match the configuration before the removal of the database
srvctl add database -d clusdb -o $ORACLE_HOME -p +DATA/clusdb/spfileclusdb.ora -a "DATA,FLASH"

srvctl config database -d clusdb
Database unique name: clusdb
Database name:
Oracle home: /opt/app/oracle/product/11.2.0/clusdb
Oracle user: oracle
Spfile: +DATA/clusdb/spfileclusdb.ora
Domain: domain.net
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Server pools: clusdb
Database instances: clusdb1
Disk Groups: DATA,FLASH
Services:
Database is administrator managed
The default service name is automatically updated to reflect the new domain name and require no change
show parameter service

NAME TYPE VALUE
-------------- ----------- -------------
service_names string clusdb.domain.net
tnsnames.ora files in clients might need some changing to reflect the new service name.