Monday, 23 February 2015

How to change DBNAME and DBID in Oracle database Using Normal & RMAN Method



(i)Changing the DBID in normal method:

    If u clone the database , the new DBID same as like the source DB. If  u want to change the DBID following below methods useful.

This is my new clone database DBID. Same as source DBID, now i want to change new DBID for clone database.



Step 1:




Step 3:

This script checks user for the new NAME and DBID.

(i)DBNAME change

var old_name varchar2(20)
var old_dbid number
var new_name varchar2(20)
var new_dbid number
exec select name, dbid -
       into :old_name,:old_dbid -
       from v$database
print old_name


accept new_name prompt "Enter the new Database Name:" 



Step 4:

(ii) DBID Change
    If u run the script , it will ask DBID enter the new DBID.

      accept new_dbid prompt "Enter the new Database ID:"


Step 5:

Make the changes of new DBNAME and new DBID.

exec :new_name:='&&new_name'
exec :new_dbid:=&&new_dbid




Step 6:

  The following below script run- new DBID changes in contolfile level all database files.

set serveroutput on
exec dbms_output.put_line('Convert '||:old_name||  -
     '('||to_char(:old_dbid)||') to '||:new_name|| -
     '('||to_char(:new_dbid)||')')
declare
  v_chgdbid   binary_integer;
  v_chgdbname binary_integer;
  v_skipped   binary_integer;
begin
  dbms_backup_restore.nidbegin(:new_name,
       :old_name,:new_dbid,:old_dbid,0,0,10);
  dbms_backup_restore.nidprocesscf(
       v_chgdbid,v_chgdbname);
  dbms_output.put_line('ControlFile: ');
  dbms_output.put_line('  => Change Name:'
       ||to_char(v_chgdbname));
  dbms_output.put_line('  => Change DBID:'
       ||to_char(v_chgdbid));
  for i in (select file#,name from v$datafile)
     loop
     dbms_backup_restore.nidprocessdf(i.file#,0,
       v_skipped,v_chgdbid,v_chgdbname);
     dbms_output.put_line('DataFile: '||i.name);
     dbms_output.put_line('  => Skipped:'
       ||to_char(v_skipped));
     dbms_output.put_line('  => Change Name:'
       ||to_char(v_chgdbname));
     dbms_output.put_line('  => Change DBID:'
       ||to_char(v_chgdbid));
     end loop;
  for i in (select file#,name from v$tempfile)
     loop
     dbms_backup_restore.nidprocessdf(i.file#,1,
       v_skipped,v_chgdbid,v_chgdbname);
     dbms_output.put_line('DataFile: '||i.name);
     dbms_output.put_line('  => Skipped:'
       ||to_char(v_skipped));
     dbms_output.put_line('  => Change Name:'
       ||to_char(v_chgdbname));
     dbms_output.put_line('  => Change DBID:'
       ||to_char(v_chgdbid));
     end loop;
  dbms_backup_restore.nidend;
end;
/

O/P:-


Step 7:

Change db_name and open the database.
Bef u can open the database, you have to change db_name parameter in the spfile. Everything is done open the database in open resetlogs mode.

shutdown immediate;
startup mount;
alter database open resetlogs;

startup force;
create spfile from pfile=’e:\initcorporate.ora’

startup force; 

========================================================================

(ii) Changing the DBID in RMAN method:

Step 1. Identify the DBID of the database

SQL> select dbid from v$database;

DBID
———-
1320285073

Step 2. Shutdown the database in normal mode

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

Step 3.Start the database to mount phase

SQL> startup mount

ORACLE instance started.

Total System Global Area    250667625 bytes

Fixed Size                    2365080 bytes

Variable Size                73274908 bytes

Database Buffers             56721608 bytes

Redo Buffers                   5876423 bytes

Database mounted.

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options


Step 4. Execute the nid command

[oracle@orcl ~]$ which nid

/u01/app/oracle/product/11.2.0/dbhome_1/bin/nid

[oracle@orcl ~]$ nid target=/

DBNEWID: Release 11.2.0.3.0 – Production on Mon Jan 23 11:45:22 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to database RC (DBID=1320285073)

Connected to server version 11.2.0

Control Files in database:

/u01/app/oracle/oradata/control01.ctl

/u01/app/oracle/oradata/control02.ctl

Change database ID of database RC? (Y/[N]) => Y

Proceeding with operation

Changing database ID from 1320285073 to 1323314655

Control File /u01/app/oracle/oradata/control01.ctl – modified

Control File /u01/app/oracle/oradata/control02.ctl – modified

Datafile /u01/app/oracle/oradata/system01.dbf– dbid changed

Datafile /u01/app/oracle/oradata/sysaux01.dbf – dbid changed

Datafile /u01/app/oracle/oradata/undotbs01.dbf– dbid changed

Datafile /u01/app/oracle/oradata/temp01.dbf – dbid changed

Instance shut down

Database ID for database RC changed to 1323314655

All previous backups and archived redo logs for this database are unusable.

Database has been shutdown, open database with RESETLOGS option.

Succesfully changed database ID.

DBNEWID – Completed succesfully.


Step 5. Open the DB in mount stage

[oracle@orcl ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Jan 23 12:10:45 2015

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup mount

ORACLE instance started.

Total System Global Area     250667625 bytes

Fixed Size                    2365080 bytes

Variable Size                73274908 bytes

Database Buffers             56721608 bytes

Redo Buffers                   5876423 bytes

Database mounted.


Step 6. Open the database with resetlog option

SQL> alter database open resetlogs ;

Database altered.

SQL>

Step 7. Identify the new changed DBID

SQL> select dbid from v$database;

DBID
———-
1323314655

=============================================================================================

Friday, 6 February 2015

Temp file wise usage:


Temp file wise usage:

set lines 152
col FILE_NAME for a30
col TABLESPACE_NAME for a10
col BYTES for a12
col MAXBYTES for a12
col AUT format a8
col STATUS for a10
select file_name,tablespace_name,bytes/1024/1024,maxbytes/1024/1024,autoextensible,status from dba_temp_files;


Temp tablespace usage:


Temp tablespace usage:

set lines 152
col FreeSpaceGB format 999.999
col UsedSpaceGB format 999.999
col TotalSpaceGB format 999.999
col host_name format a30
col tablespace_name format a30
select tablespace_name,
(free_blocks*8)/1024/1024 FreeSpaceGB,
(used_blocks*8)/1024/1024 UsedSpaceGB, (total_blocks*8)/1024/1024 TotalSpaceGB,
i.instance_name,i.host_name
from gv$sort_segment ss,gv$instance i where ss.tablespace_name in (select tablespace_name from dba_tablespaces where contents='TEMPORARY') and
i.inst_id=ss.inst_id;




Tablespace Datafile wise free space:


Tablespace Datafile wise free space:


set lines 152
col TABLESPACE format a10
col FILE_NAME format a35
col BYTES format format a10
col MAXBYTES format a12
col AUT format a8
col STATUS format a12
select TABLESPACE_NAME,FILE_NAME,bytes/1024/1024,maxbytes/1024/1024,autoextensible,status from dba_data_files;




Particular Tablespace Usage Report:


Particular Tablespace Usage Report:

select tablespace_name, tbs_mb, free_mb,
round(free_mb/tbs_mb*100,2) pct_free, round(tbs_mb*15/100-free_mb,2) Est_mb from
( select a.tablespace_name ,sum(bytes)/1024/1024 tbs_mb,
nvl((select sum(bytes)/1024/1024 from dba_free_space where tablespace_name=a.tablespace_name),0) free_mb
from dba_data_files a group by tablespace_name)
where free_mb/tbs_mb*100 <=10 and tablespace_name ='&tablespace_name';




Total Tablespace space usage – Scripts


Total Tablespace space usage – Scripts

select tbs.tbs,total_mb tbs_mb, nvl(free_mb,0) free_mb, round(nvl(free_mb,0)/total_mb*100,2) pct_free,
total_mb*25/100 -nvl(free_mb,0) Est_mb    from
(select tablespace_name tbs,round(sum(bytes)/1024/1024,2) free_mb
from dba_free_space   group by tablespace_name) free_tbs,
(select tablespace_name tbs,round(sum(bytes)/1024/1024,2) total_mb
from dba_data_files   group by tablespace_name) tbs
where tbs.tbs=free_tbs.tbs(+) AND round(nvl(free_mb,0)/total_mb*100,2)<=10;


Tablespace Script:


Tablespace Script:

clear columns
column tablespace format a20
column total_mb format 999,999,999,999.99
column used_mb format 999,999,999,999.99
column free_mb format 999,999,999.99
column pct_used format 999.99
column graph format a25 heading "GRAPH (X=5%)"
column status format a10
compute sum of total_mb on report
compute sum of used_mb on report
compute sum of free_mb on report
break on report
set lines 200 pages 100
select  total.ts tablespace,
        DECODE(total.mb,null,'OFFLINE',dbat.status) status,
total.mb total_mb,
NVL(total.mb - free.mb,total.mb) used_mb,
NVL(free.mb,0) free_mb,
        DECODE(total.mb,NULL,0,NVL(ROUND((total.mb - free.mb)/(total.mb)*100,2),100)) pct_used,
CASE WHEN (total.mb IS NULL) THEN '['||RPAD(LPAD('OFFLINE',13,'-'),20,'-')||']'
ELSE '['|| DECODE(free.mb,
                             null,'XXXXXXXXXXXXXXXXXXXX',
                             NVL(RPAD(LPAD('X',trunc((100-ROUND( (free.mb)/(total.mb) * 100, 2))/5),'X'),20,'-'),
'--------------------'))||']'
         END as GRAPH
from
(select tablespace_name ts, sum(bytes)/1024/1024 mb from dba_data_files group by tablespace_name) total,
(select tablespace_name ts, sum(bytes)/1024/1024 mb from dba_free_space group by tablespace_name) free,
        dba_tablespaces dbat
where total.ts=free.ts(+) and
      total.ts=dbat.tablespace_name
UNION ALL
select  sh.tablespace_name,
        'TEMP',
SUM(sh.bytes_used+sh.bytes_free)/1024/1024 total_mb,
SUM(sh.bytes_used)/1024/1024 used_mb,
SUM(sh.bytes_free)/1024/1024 free_mb,
        ROUND(SUM(sh.bytes_used)/SUM(sh.bytes_used+sh.bytes_free)*100,2) pct_used,
        '['||DECODE(SUM(sh.bytes_free),0,'XXXXXXXXXXXXXXXXXXXX',
              NVL(RPAD(LPAD('X',(TRUNC(ROUND((SUM(sh.bytes_used)/SUM(sh.bytes_used+sh.bytes_free))*100,2)/5)),'X'),20,'-'),
                '--------------------'))||']'
FROM v$temp_space_header sh
GROUP BY tablespace_name
order by 1
/
ttitle off
rem clear columns

                                                                                    Venish VK (Sr.Oracle DBA)                   

Thursday, 5 February 2015

ORA-00119: invalid specification for system parameter LOCAL_LISTENER, ORA-00132


ORA-00119: invalid specification for system parameter LOCAL_LISTENER

ORA-00132: syntax error or unresolved network name 'LISTENER_ORCL'


Solutions:


Step 1: using spfile starting up your database, create a pfile from it.

Enter Username:sys as sysdba
Passwd:

connected to an idle instance.

SQL> create pfile from spfile;

File created.

SQL>exit

Step 2: Edit the pfile and remove the parameter LOCAL_LISTENER

*.local_listener='LISTENER_ORCL'

Step 3: Create spfile from the pfile 

SQL> create Spfile from pfile;

File created.

Step 4: Startup the database

SQL>STARTUP

ORA - 06553: PLS-801: internal error [56327]



ORA - 06553: PLS-801: internal error [56327]



ORA - 06544: PL/SQL: internal error , arguments: [56327], [ ], [ ], [ ], [ ], [ ], [ ]
ORA - 06553: PLS-801: internal error  [56327]

Solution: 

 Recompile the existing PL/SQL in the format required for new database.

SQL> shut immediate
SQL> startup upgrade;
SQL> @?/rdbms/admin/utlirp
SQL> shut immediate
SQL> startup
SQL> @?/rdbms/admin/utlrp

RMAN Active Database Cloning: 11g New feature


RMAN Active Database Cloning: 11g New feature



               Target DB                                                                 Auxiliary DB  
 192.168.1.100                                                             192.168.1.101

  PROD                                                                          TEST
 <-------------------------------- 
    <--------------------------------                                                   

Auxiliary DB Server:

$ mkdir /u01/admin/test
$ cd /u01/admin/test
$mkdir pfile bdump udump cdump create
$mkdir /u01/oradata/test

Target DB Server:
$scp –r $ORACLE_HOME/dbs/initprod.ora oracle@192.168.1.101:/u01/admin/test/pfile

Target DB Server:
$mv /u01/admin/test/pfile/initprod.ora /u01/admin/test/pfile/inittest.ora
$ vi /u01/admin/test/pfile/inittest.ora
      db_unique_name=test
      db_name=test
      control_files=’/u01/oradata/test/control01.ctl’
      background_dump_dest=/u01/admin/test/bdump
      user_dump_dest=/u01/admin/test/udump
     core_dump_dest=/u01/admin/test/cdump
     audit_dump_dest==/u01/admin/test/adump
     db_file_name_convert=(‘/opt/oradata/prod’,’/u01/oradata/test’)
     log_file_name_convert=(‘/opt/oradata/prod’,’/u01/oradata/test’)
$export ORACLE_SID=test
$orapwd file=$ORACLE_HOME/dbs/orapwtest password=sys
$ sqlplus “ / as sysdba”
SQL> startup nomount pfile=’/u01/admin/test/pfile/inittest.ora’;
SQL> create spfile from pfile=’/u01/admin/test/pfile/inittest.ora’;
SQL> shutdown immediate;
SQL> startup nomount;

$cat>> $ORACLE_HOME/network/admin/tnsnames.ora
 test=
      (DESCRIPTION=
          (ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.101)(PORT=1521))
            (CONNECT_DATA=
               (SERVICE_NAME=test)
            )
       )


Target DB SERVER:

$cat>> $ORACLE_HOME/network/admin/tnsnames.ora
 test123=
      (DESCRIPTION=
          (ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.101)(PORT=1521))
            (CONNECT_DATA=
               (SERVICE_NAME=test)
            )
       )

$ export ORACLE_SID=PROD
$ rman target /
RMAN> connect catalog rman/rman123@apps123
RMAN> connect auxiliary sys/sys@test123;
RMAN> duplicate target database to test from active database;

 èDUPLICATE TARGET DATABASE TO test FROM ACTIVE DATABASE PASSWORD FILE SPFILE    NOFILENAMECHECK;(Don’t check directory structure – what u mention in dbfilenameconvert that can be take)

èDUPLICATE DATABASE TO test UNTIL TIME “TO_DATE (‘11/01/2013 14:00:00’,’MM/DD/YYYY HH24:MI:SS’) SPFILE BACKUP LOCATION ‘/prod_backups’ NOFILENAMECHECK; (In target DB presented spfile to be cloned , and then testDB spfile backup)


RMAN>exit;