Friday, March 9, 2012

login as sysoper

I want get to know about the role of oper group that has always been created during installation of oracle10g on linux box.  3 groups are always created as a prequisite for oracle 10g installation on linux box.  They are oper,dba and oinstall.
I was knowing the purpose of all these groups.  For ex, dba group is used so that an os user can logged in as / as sysdba. oinstall is the owner for oracle inventory. And in my case, there is an os user named oracle which is the member of both these groups, oinstall as well as dba.  A user which is the member  of dba group can logged in as / as sysdba as well as / as sysoper, and that is what oracle user can does.
Now I wanted to understand the purpose of oper group then. It was clear to me that oper group is created so that an os user can logged in as / as sysoper to work as system operator and to perform day-to -day basic administrative tasks such as startup, shutdown, backup ,recovery,etc. And  the user who can logged in as sysdba has more powerful privilege that sysoper. That means there must be a second os user who can perform the role of system operator by logging as / as sysoper and not as / as sysdba.

Then I started with creating a second user, besides oracle, who can acess oracle database to perform basic administrative operations. After various tries and errors , I succeded. It is how I did.

$useradd geet
$ chmod -R 777 /u01
$usermod -G oper geet
$ls -l /u01
total 20
drwxrwxrwx 8 oracle oinstall 4096 Mar 1 15:40 app
--------rest truncated-------------

ls -ld /u01
drwxrwxrwx 8 oracle oinstall 4096 Feb 10 10:16 /u01

ls -l /u01/app
total 24
drwxrwxrwx 8 oracle dba 4096 Mar 1 10:32 admin
drwxrwxrwx 6 oracle dba 4096 Mar 1 10:36 flash_recovery_area
drwxrwxrwx 2 oracle dba 4096 Mar 1 16:20 logminer_dir
drwxrwxrwx 6 oracle dba 4096 Mar 1 10:35 oradata
drwxrwxrwx 7 oracle dba 4096 Mar 1 10:21 oraInventory
drwxrwxrwx 3 oracle oinstall 4096 Feb 8 12:37 product

Check the permission for $ORACLE_HOME/bin/oracle. It should be

$ls -l oracle
-rwsrwsrwx 1 oracle dba 93362259 Mar  7 11:26 oracle
Here is two s.

$id geet
uid=503(geet) gid=506(geet) groups=506(geet),501(oper),503(oinstall)
 
$su - geet
[geet@new-host-15 ~]$ export ORACLE_HOME=/u01/app/product/10.2.0/db_1
[geet@new-host-15 ~]$ export ORACLE_SID=orcl
[geet@new-host-15 ~]$ cd $ORACLE_HOME
[geet@new-host-15 db_1]$ cd bin
[geet@new-host-15 bin]$ ./sqlplus / as sysoper


SQL*Plus: Release 10.2.0.1.0 - Production on Wed Mar 7 14:12:19 2012

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

Connected.

If  this fails:

$ ./sqlplus / as sysoper

SQL*Plus: Release 10.2.0.1.0 - Production on Tue Mar 6 14:17:26 2012

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

ERROR:
ORA-01031: insufficient privileges

Then check $ORACLE_HOME/rdbms/lib config.c which looks something like this:

/* SS_DBA_GRP defines the UNIX group ID for sqldba adminstrative access. */
/* Refer to the Installation and User's Guide for further information. */
#define SS_DBA_GRP "dba"
#define SS_OPER_GRP "oper"
char *ss_dba_grp[] = {SS_DBA_GRP, SS_OPER_GRP};

if  second #define do not contain oper, but  dba, then u have to modify this file as above. After modification you have to relink this executable. To relink I used:
$relink all

But after relinking, I am able to issue

conn / as sysoper

successfully.

but when issuing
SQL> conn scott/tiger
ERROR:
ORA-00600: internal error code, arguments: [17069], [0x30AD70A4], [], [], [],
[], [], []
ERROR:
ORA-00600: internal error code, arguments: [17069], [0x30AD70A4], [], [], [],
[], [], []

Error accessing package DBMS_APPLICATION_INFO
Connected.

This error is solved by running utlirp.sql script by logging as sysdba.


Tuesday, December 6, 2011

loss of all controlfiles using user managed backup and recovery

SETUP : All scenarios are in archivelog mode.
              Database version is  10.2.0.1.0

1. Loss of all controlfiles when all redos are available.

SQL> startup
SQL> alter database begin backup;
SQL> select * from v$backup;

$cp /u01/app/oradata/orcl1/*.* /u01/app/backup/orcl1/.

 FILE# STATUS CHANGE# TIME
---------- ------------------ ---------- ---------
1 ACTIVE  482215 05-DEC-11
2 ACTIVE  482215 05-DEC-11
3 ACTIVE  482215 05-DEC-11
4 ACTIVE  482215 05-DEC-11
5 ACTIVE  482215 05-DEC-11

SQL> alter database end backup;
SQL>  select * from v$backup;

     FILE# STATUS CHANGE# TIME
---------- ------------------ ---------- ---------
1 NOT ACTIVE  482215 05-DEC-11
2 NOT ACTIVE  482215 05-DEC-11
3 NOT ACTIVE  482215 05-DEC-11
4 NOT ACTIVE  482215 05-DEC-11
5 NOT ACTIVE  482215 05-DEC-11


SQL> select NAME,SEQUENCE#,RESETLOGS_CHANGE#,FIRST_CHANGE#,NEXT_CHANGE# from v$archived_log;


/u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_05/o1_mf_1_1_7frrnnyw_.arc   1 482026      482026   482412
/u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_05/o1_mf_1_2_7frrnp2f_.arc   2 482026      482412   482414
/u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_05/o1_mf_1_3_7frrnvjn_.arc   3 482026      482414   482416


SQL> select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS    FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
1    1       4   52428800     1 NO  CURRENT   482416 05-DEC-11
2    1       2   52428800     1 YES INACTIVE   482412 05-DEC-11
3    1       3   52428800     1 YES INACTIVE   482414 05-DEC-11

Now, delete all the control files.
SQL> shutdown abort
SQL> startup 
ORACLE instance started.

Total System Global Area  167772160 bytes
Fixed Size    1218292 bytes
Variable Size   71305484 bytes
Database Buffers   88080384 bytes
Redo Buffers    7168000 bytes
ORA-00205: error in identifying control file, check alert log for more info

-> Restore controlfile from backup to all the locations mentioned in initialization parameter file.
$cp /u01/app/backup/contro1.ctl /u01/app/oradata/orcl1/control01.ctl
$cp /u01/app/backup/contro1.ctl /u01/app/oradata/orcl1/control02.ctl
$cp /u01/app/backup/contro1.ctl /u01/app/oradata/orcl1/control03.ctl


SQL> alter database mount;

Database altered.

SQL> recover database using backup controlfile [until cancel];  
ORA-00279: change 482216 generated at 12/05/2011 11:42:39 needed for thread 1
ORA-00289: suggestion : /u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_05/o1_mf_1_1_%u_.arc
ORA-00280: change 482216 for thread 1 is in sequence #1


Specify log: {=suggested | filename | AUTO | CANCEL}

-> It requires archived log related to seq1. Suggestion is pointing to current location, and press enter to accept the suggestion

ORA-00279: change 482412 generated at 12/05/2011 11:50:04 needed for thread 1
ORA-00289: suggestion : /u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_05/o1_mf_1_2_%u_.arc
ORA-00280: change 482412 for thread 1 is in sequence #2
ORA-00278: log file '/u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_05/o1_mf_1_1_7frrnnyw_.arc' no longer needed for this recovery


Specify log: {=suggested | filename | AUTO | CANCEL}

-> It requires archived log related to seq2. Suggestion is pointing to current location, and press enter to accept the suggestion


ORA-00279: change 482414 generated at 12/05/2011 11:50:05 needed for thread 1
ORA-00289: suggestion : /u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_05/o1_mf_1_3_%u_.arc
ORA-00280: change 482414 for thread 1 is in sequence #3
ORA-00278: log file '/u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_05/o1_mf_1_2_7frrnp2f_.arc' no longer needed for this recovery


Specify log: {=suggested | filename | AUTO | CANCEL}
-> It requires archived log related to seq3. Suggestion is pointing to current location, and press enter to accept the suggestion

ORA-00279: change 482416 generated at 12/05/2011 11:50:11 needed for thread 1
ORA-00289: suggestion : /u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_05/o1_mf_1_4_%u_.arc
ORA-00280: change 482416 for thread 1 is in sequence #4
ORA-00278: log file '/u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_05/o1_mf_1_3_7frrnvjn_.arc' no longer needed for this recovery


Specify log: {=suggested | filename | AUTO | CANCEL}
  
-> It requires archived log related to seq4. Suggestion is pointing to an archived location, but required redo is available in redo01.log(it is clear from the output of redo log) so,specify the file name and location and press enter.

/u01/app/oradata/orcl1/redo01.log
Log applied.
Media recovery complete.
SQL> alter database open resetlogs;

Database altered.

-> And, you will get all the data back.
**********************************************************************************

2. Loss of all controlfiles and one of the redo is missing

SQL> startup
SQL> alter database begin backup;
$cp /u01/app/oradata/orcl1/*.* /u01/app/backup/orcl1/
SQL> alter database end backup;

*****Perform some changes*************

SQL> Alter system switch logfile;
/
/
/

SQL> select name,sequence# from v$archived_log; 
/u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_05/o1_mf_1_1_7fs1hyz7_.arc   1
/u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_05/o1_mf_1_2_7fs1hzyk_.arc   2
/u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_05/o1_mf_1_3_7fs1j3o5_.arc   3
/u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_05/o1_mf_1_4_7fs1j40o_.arc   4

SQL>  select * from v$log;

    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS    FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ---------
1    1       5   52428800     1 NO  CURRENT   485153 05-DEC-11
2    1       3   52428800     1 YES ACTIVE   485148 05-DEC-11
3    1       4   52428800     1 YES ACTIVE   485151 05-DEC-11

->Remove archived log sequence#2
$ rm /u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_05/o1_mf_1_2_7fs1hzyk_.arc 

-> remove all controlfiles
$ rm /u01/app/oradata/orcl1/control*.ctl

SQL> shutdown abort
SQL> startup 
Error-> error in identifying controlfile

Database is in nomount state.

-> copy all the controlfile and datafiles from backup location to target location

$ cp /u01/app/backup/orcl1/*.* /u01/app/oradata/orcl1/*.*

SQL> alter database mount
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 484998 generated at 12/05/2011 14:15:41 needed for thread 1
ORA-00289: suggestion : /u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_05/o1_mf_1_1_%u_.arc
ORA-00280: change 484998 for thread 1 is in sequence #1


Specify log: {=suggested | filename | AUTO | CANCEL}

ORA-00279: change 485146 generated at 12/05/2011 14:21:10 needed for thread 1
ORA-00289: suggestion : /u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_05/o1_mf_1_2_%u_.arc
ORA-00280: change 485146 for thread 1 is in sequence #2
ORA-00278: log file '/u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_05/o1_mf_1_1_7fs1hyz7_.arc' no longer needed for this recovery


Specify log: {=suggested | filename | AUTO | CANCEL}
--> Since redo sequenc#2 does not exists.Issue cancel. 
CANCEL
Media recovery cancelled.
SQL> ALTER DATABASE OPEN RESETLOGS;

Database altered.

**********************************************************************************

3. Recovery from loss of all controlfiles  by creating controlfile.

-> Same procedure will work whether all the archivelogs is available or not.

SQL> SQL> startup
SQL> alter database begin backup;
$cp /u01/app/oradata/orcl1/*.* /u01/app/backup/orcl1/
SQL> alter database end backup;
SQL> alter database backup controlfile to trace as '/u01/app/control.bak' noresetlogs;

*****Perform some changes*************

SQL> Alter system switch logfile;
/
/
/
SQL> select name,sequence# from v$archived_log; 

1
/u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_06/o1_mf_1_1_7fv6mo17_.arc


 SEQUENCE#
----------
NAME
--------------------------------------------------------------------------------
2
/u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_06/o1_mf_1_2_7fv6zzz6_.arc

3
/u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_06/o1_mf_1_3_7fv700xt_.arc

4
/u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_06/o1_mf_1_4_7fv70466_.arc


 SEQUENCE#
----------
NAME
--------------------------------------------------------------------------------
5
/u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_06/o1_mf_1_5_7fv70532_.arc

6
/u01/app/flash_recovery_area/ORCL1/archivelog/2011_12_06/o1_mf_1_6_7fv70b3f_.arc

SQL> select * from v$log;

delete archive log related to seq 2 and delete all the controlfiles

SQL> shutdown abort
SQL> startup 
error in identifying contorlfile.
SQL> CREATE CONTROLFILE REUSE DATABASE "ORCL1" NORESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/u01/app/oradata/orcl1/redo01.log'  SIZE 50M,
  GROUP 2 '/u01/app/oradata/orcl1/redo02.log'  SIZE 50M,
  GROUP 3 '/u01/app/oradata/orcl1/redo03.log'  SIZE 50M
DATAFILE
  '/u01/app/oradata/orcl1/system01.dbf',
  '/u01/app/oradata/orcl1/undotbs01.dbf',
  '/u01/app/oradata/orcl1/sysaux01.dbf',
  '/u01/app/oradata/orcl1/users01.dbf',
  '/u01/app/oradata/orcl1/example01.dbf'
CHARACTER SET WE8ISO8859P1
;

Controlfuile  created

SQL> recover database;
SQL> alter database open;
**********************************************************************************