пятница, 22 ноября 2013 г.

Recover datafile if corrupted during database open

Recover datafile if corrupted during database open
============
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u02/oradata/TEST/system01.dbf'

Try to recover it via database
=============================
SQL> recover datafile '/u02/oradata/TEST/system01.dbf';
ORA-00283: recovery session canceled due to errors
ORA-01110: data file 1: '/u02/oradata/TEST/system01.dbf'
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/u02/oradata/TEST/system01.dbf'

recover via RMAN
=======================
Of cause we taken backup several hours before the corryption happened.
======================

Take datafile offline
======================
SQL> ALTER DATABASE DATAFILE 1 OFFLINE;

Recover corrupted datafile:
===============
RMAN> RESTORE DATAFILE 5;
RMAN> RECOVER DATAFILE 5;

Make datafile online
==============
SQL> ALTER DATABASE DATAFILE 1 ONLINE;
SQL> ALTER DATABASE OPEN;

вторник, 19 ноября 2013 г.

Restore table changes back in time (as of timestamp)

restore table changes back in time
====================================
<><><><><><><><><><><><><><><><><><><><><><><><>
Let me introduce the table called PHONE_BOOK:
<><><><><><><><><><><><><><><><><><><><><><><><>
DESC PHONE_BOOK
Name       Null Type        
---------- ---- -------------
NUM             NUMBER      
NAME            VARCHAR2(100)
PROFESSION      VARCHAR2(100)
PHONE           VARCHAR2(100)
OTHER           VARCHAR2(100)

<><><><><><><><><><><><><><><><><><><><><><><><>
There are following values living
<><><><><><><><><><><><><><><><><><><><><><><><>
select name,other from PHONE_BOOK where  NAME like '%Evge%';
NAME   OTHER
================ ===========
Bashmak Evgeny  222-61-34
Botman Evgeny
Zelipuk Evgeny  299-46-14

<><><><><><><><><><><><><><><><><><><><><><><><>
Let's corrupt selected values
<><><><><><><><><><><><><><><><><><><><><><><><>
update phone_book
set    other = '77777777'
where  NAME like '%Evge%'
/

commit;
<><><><><><><><><><><><><><><><><><><><><><><><>
Haha, values become wrong:
<><><><><><><><><><><><><><><><><><><><><><><><>
select name,other from PHONE_BOOK where  NAME like '%Evge%';

NAME   OTHER
================ ===========
Bashmak Evgeny  77777777
Botman Evgeny  77777777
Zelipuk Evgeny  77777777

<><><><><><><><><><><><><><><><><><><><><><><><>
No worries, there is backup oportunity in the 11g
<><><><><><><><><><><><><><><><><><><><><><><><>
update phone_book
set    (other) =
          (select other
              from   phone_book as of timestamp systimestamp - 1/24 history
              where  history.NAME = phone_book.NAME
             )
/

commit;

<><><><><><><><><><><><><><><><><><><><><><><><>
Values back to the right values
<><><><><><><><><><><><><><><><><><><><><><><><>
select name,other from PHONE_BOOK where  NAME like '%Evge%';
NAME   OTHER
================ ===========
Bashmak Evgeny  222-61-34
Botman Evgeny
Zelipuk Evgeny  299-46-14

понедельник, 18 ноября 2013 г.

Script to start/stop oracle services

#!/bin/bash
echo "startall"
echo "start_db_ln"
echo "stopall"
echo "start_db"
echo "start_dbconsole"
echo "start_ln"
echo -n "Order please : "
read order
case $order in

startall)
echo starting all services           
. /home/oracle/test.env
lsnrctl start TEST
sqlplus "/as sysdba" <startup;
exit;
EOF
emctl start dbconsole
;;
   
stopall)
echo stop all services
. /home/oracle/test.env
sqlplus "/as sysdba" <shutdown immediate;
exit;
EOF
lsnrctl stop TEST
emctl stop dbconsole
;;

   
start_db)
echo startup database only 
. /home/oracle/test.env
sqlplus "/as sysdba" <startup;
exit;
EOF
;;


start_ln)
echo starting listener           
. /home/oracle/test.env
lsnrctl start TEST
;;

start_db_ln)
echo starting listener and database          
. /home/oracle/test.env
lsnrctl start TEST
sqlplus "/as sysdba" <startup;
exit;
EOF
;;

start_dbconsole)
echo starting dbconsole        
. /home/oracle/test.env
emctl start dbconsole
;;
   
*) echo  nothing ordered                   ;;

    esac

пятница, 15 ноября 2013 г.

Create simple table


To create simple table:
=====================
CREATE TABLE phone_book
(
    num                 number,
    Name             varchar2(100),
    Profession           varchar2(100),
    Phone        varchar2(100),
    Other                varchar2(100)
    )
    TABLESPACE USERS
    ;

Where varchar2(100) to keep 100 bytes for the each
and number to avoid any characters except numbers

понедельник, 11 ноября 2013 г.

Template RMAN backup script:
===================
CONFIGURE DEFAULT DEVICE TYPE TO disk;
CONFIGURE DEVICE TYPE disk PARALLELISM 2;
CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT '/u02/RMAN/full_%U';
CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT '/u02/RMAN/full_%U';
run {
backup device type disk tag 'TEST_full' database;
backup device type disk tag 'TEST_full' archivelog all not backed up delete all input;
backup tag 'TEST_full' current controlfile;
}
allocate channel for maintenance type disk;
delete noprompt obsolete device type disk;
release channel;
Enable Archive log for oracle database:
====================
SQL> startup mount
ORACLE instance started.

Total System Global Area  184549376 bytes
Fixed Size                  1300928 bytes
Variable Size             157820480 bytes
Database Buffers           25165824 bytes
Redo Buffers                 262144 bytes
Database mounted.

SQL> alter database archivelog;
Database altered.

SQL> alter database open;
Database altered.
Issie with oracle EM 11g, it refused to start right after installation. Performed following steps to resolve an issue:
1) Dropped repository setup configured during the installation
=============
  • cd $ORACLE_HOME/bin
  • ./emca -deconfig dbcontrol db -repos drop
2) set TZ for the console to avoid issue wit wrong time zone. TZ was set to Moscow time. Changed it via linux GUI to GMT+5 (US/Eastern), as well set local alias for the console as following:
==============
export TZ=US/Eastern

as well added value to the env file. so the environment currently looking like following
>>>>>>>
ORACLE_HOME=/u01/db/11.2.0/dbhome_1
ORACLE_SID=TEST
ORACLE_UNQNAME=TEST
TZ=US/Eastern
export ORACLE_HOME ORACLE_SID ORACLE_UNQNAME TZ
PATH=$PATH:/usr/local/bin:$ORACLE_HOME/bin
export PATH
<<<<<<<<
3) Recreated EM repository
==============
emca -config dbcontrol db -repos create

Repository recreated with no errors. EM started automatically. Login to the Web interface successful.