Wednesday, January 22, 2014

How to copy/replicate/sync the sequences between two oracle databases


A combination of UltraCommits statements and a database link, in addition to a stored procedure that you can schedule to automatically run, would serve you well. and its a easiest way to keep this in sync.
--drop create db_link
DROP DATABASE LINK SOURCE_DB;

CREATE DATABASE LINK "SOURCE_DB"
  CONNECT TO USER IDENTIFIED BY password USING 'SOURCE_DB';

 --drop create sequences 
  DROP sequence target_seq;
CREATE sequence target_seq start with 6;

  --the next two lines run in source db
  DROP sequence source_seq;
CREATE sequence source_seq start with 6000;

--take a look at the sequences to get an idea of what to expect
SELECT source_schema.source_seq.nextval@SOURCE_DB source_seq,
  target_seq.nextval target_seq
FROM dual; 

--create procedure to reset target sequence that you can schedule to automatically run
CREATE OR REPLACE
PROCEDURE reset_sequence
AS
  l_source_sequence pls_integer;
  l_target_sequence pls_integer;
  l_sql VARCHAR2(100);
BEGIN
  SELECT source_schema.source_seq.nextval@SOURCE_DB,
    target_seq.nextval
  INTO l_source_sequence,
    l_target_sequence
  FROM dual;
  l_sql := 'alter sequence target_seq increment by '||to_number(l_source_sequence-l_target_sequence);
  EXECUTE immediate l_sql;
  SELECT target_seq.nextval INTO l_target_sequence FROM dual;
  l_sql := 'alter sequence target_seq increment by 1';
  EXECUTE immediate l_sql;
  COMMIT;
END reset_sequence;
/

--execute procedure to test it out
EXECUTE reset_sequence;

--review results; should be the same
SELECT source_schema.source_seq.nextval@SOURCE_DB, target_seq.nextval FROM dual;

Friday, January 17, 2014

How to find a Schema size in Oracle

SELECT sum(bytes) / (1024 * 1024 * 1024) size_in_gb
  FROM dba_segments
 WHERE owner = 'SCHEMA_NAME';

Wednesday, December 18, 2013

How to find an Index size


select segment_name,segment_type,bytes/1024/1024 MB
 from dba_segments
 where segment_type='INDEX' and segment_name='your_index_name';

How to find a table size

select segment_name,segment_type,bytes/1024/1024 MB
 from dba_segments
 where segment_type='TABLE' and segment_name='your_table_name';


Tuesday, February 12, 2013

Script to see Database Size

COLUMN "Total Mb" FORMAT 999,999,999.0
COLUMN "Redo Mb" FORMAT 999,999,999.0
COLUMN "Temp Mb" FORMAT 999,999,999.0
COLUMN "Data Mb" FORMAT 999,999,999.0


SELECT (SELECT Sum(bytes / 1048576)
        FROM   dba_data_files) "Data Mb",
       (SELECT Nvl(Sum(bytes / 1048576), 0)
        FROM   dba_temp_files) "Temp Mb",
       (SELECT Sum(bytes / 1048576) * Max(members)
        FROM   v$log)          "Redo Mb",
       (SELECT Sum(bytes / 1048576)
        FROM   dba_data_files)
       + (SELECT Nvl(Sum(bytes / 1048576), 0)
          FROM   dba_temp_files)
       + (SELECT Sum(bytes / 1048576) * Max(members)
          FROM   v$log)        "Total Mb"
FROM   dual; 

Sunday, February 10, 2013

Active session information

    SELECT SID, Serial#, UserName, Status, SchemaName, Logon_Time
    FROM V$Session
    WHERE
    Status='ACTIVE' AND
    UserName IS NOT NULL;

Thursday, December 6, 2012

Multiplexing Controlfile through RMAN in RAC

Login to the first node

column is_recovery_dest_file format a25
column name format a60
set linesize 160
select status, name, is_recovery_dest_file from v$controlfile;


check the control file status and names using the above quey,


i my case i had


STATUS  NAME                                                         IS_RECOVERY_DEST_FILE
------- ------------------------------------------------------------ -------------------------
        +DATA_RAJ/rajesh/controlfile/current.986.790135655           NO

hence ,

login in to sqlplus , and alter the system as below with your new place pointed to

alter system set control_files = '+DATA_RAJ/rajesh/controlfile/current.986.790135655','+RECO_RAJ' scope=spfile sid='*';


in my case i have the data and reco groups created on the asm, hence trying to place the controlfiles in to two different disk groups.


once alterd the system , shutdown the instance using srvctl


srvctl stop database -d xxx

after then , login to sql prmpt and startup the instance in no mount stage , once the db came up on nomount stage exit from the sql prompt and login in rman prompt

example

rman

connect  target

restore controlfile from '+DATA_RAJ/rajesh/controlfile/current.986.790135655';


it will restore/multiplex our control file to the existing and our new path. once the restore complete, shutdown the instances and startup normal

it should come up with the two controlfiles,

issues i was facing here were, one of the instance spfile was not on the shared drive hence i was failing on the below command

alter system set control_files = '+DATA_RAJ/rajesh/controlfile/current.986.790135655','+RECO_RAJ' scope=spfile sid='*';


as spfile could not be modifiable etc ... after which i have mounted the spfile on the shared drive and followed the same

Good Luck !!


Thanks

How to Trouble shoot Logfile_sync wait event

   First  Identify and break down LGWR wait events. Query wait events for LGWR. In this instance LGWR sid is 3 (and usually it is). select s...