Friday, June 15, 2018

ORA Error : 

ORA-01012: not logged on startup failed



Problem:
Now while starting the DB instance.
$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Tue Sep 25 07:23:45 2015
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected.
SQL> startup
ORA-01012: not logged on
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORA-01012: not logged on
So whenever we forcefully shut down the DB this issue may occurs
“SYSRESV”  shows a shared memory segment for a non-existing instance

Solution:
At OS level remove the orphaned shared memory segment using this utility
$ sysresv
IPC Resources for ORACLE_SID "<SID>" :
Shared Memory:
ID             KEY
15              0x00000000
16              0x00000000
17              0x0edc1410
Semaphores:
ID              KEY
19              0xb6aad8c8
Oracle Instance alive for sid "<SID>"
$ ipcrm -m 15
$ ipcrm -m 16
$ ipcrm -m 17



Sunday, June 11, 2017

How to resolve archive gap between primary and standby database

How to resolve archive gap between primary and standby database :

1) Check the current SCN on both primary and standby database :

On the primary:
SQL> select to_char(current_scn) from v$database;

CURRENT_SCN
-----------
1447102

On the standby:

SQL> select to_char(current_scn) from v$database;

CURRENT_SCN
-----------
1301571



2) Check the time difference also :

On the primary:
SQL> select scn_to_timestamp(1447102) from dual;

SCN_TO_TIMESTAMP(1447102)
-------------------------------
18-DEC-09 08.54.28.000000000 AM


On the standby:
SQL> select scn_to_timestamp(1301571) from dual;

SCN_TO_TIMESTAMP(1301571)
-------------------------------
15-DEC-09 07.19.27.000000000 PM



 3) Chech the archive lags using below query: 

On the primary:

SQL> select p.prim_max,
       f.fall_max_archived,
       d.dr_max_archived,
       af.fall_max_applied,
       ad.dr_max_applied,
       p.prim_max-f.fall_max_archived archive_lag_fall,
       p.prim_max-d.dr_max_archived archive_lag_dr,
       p.prim_max-af.fall_max_applied applied_lag_fall,
       p.prim_max-ad.dr_max_applied applied_lag_dr
from
(select max(sequence#) prim_max from v$archived_log where dest_id=1 and archived='YES') p,
(select max(sequence#) fall_max_archived from v$archived_log where standby_dest='YES' and archived='YES' and dest_id=2) f,
(select max(sequence#) dr_max_archived from v$archived_log where standby_dest='YES' and archived='YES' and dest_id=3) d,
(select max(sequence#) fall_max_applied from v$archived_log where standby_dest='YES' and archived='YES' and applied='YES' and dest_id=2) af,
(select max(sequence#) dr_max_applied from v$archived_log where standby_dest='YES' and archived='YES' and applied='YES' and dest_id=3) ad;

OR

SQL> select  a.live-b.dest_id_2 as dest_id_2,a.live-c.dest_id_3 as dest_id_3,a.live-d.dest_id_4 as       dest_id_4,a.live-e.dest_id_5 as dest_id_5
from (select max(sequence#) as live from v$archived_log) a,
(select max(sequence#) as dest_id_2 from v$archived_log where applied='YES' and dest_id=2) b,
(select max(sequence#) as dest_id_3 from v$archived_log where applied='YES' and dest_id=3) c,
(select max(sequence#) as dest_id_4 from v$archived_log where applied='YES' and dest_id=4) d,
(select max(sequence#) as dest_id_5 from v$archived_log where applied='YES' and dest_id=5) e;


4) Take the incremental backup on primary:

RMAN> run {
2> allocate channel c1 type disk format '/u01/backup/%U.bkp';
3> backup incremental from scn 1301571 database;
4> }


 5) Take the standby controlfile backup on primary:

SQL> alter database create standby controlfile as '/u01/backup/standby_controlfile_bkp.ctl';

Database altered.



6) Copy incremental backup and standby controlfile backup to standby server 

scp *.bkp *.ctl oracle@oracle123:/u02/orabkp


7) Stop the managed standby apply process:
On the standby:

SQL> alter database recover managed standby database cancel;

Database altered.



8) Shutdown the standby database and start in nomount mode :

SQL> shut immediate;
SQL> startup nomount; 
  

9) Connect to RMAN and catalog the backup files to RMAN and follow below steps:
On the standby:

$ rman target /

RMAN> catalog start with '/u02/orabkp' 
RMAN> restore standby controlfile from '/u02/orabkp/standby_controlfile_bkp.ctl'

RMAN> sql'alter database mount standby database';


10) Performe recovery :
On the standby:

RMAN> recover database;


11) Start managed recovery process :
 On the standby:

SQL> alter database recover managed standby database disconnect from session;

Database altered.


12) Check the SCN in primary and standby, it should be close to each other :

On the primary:
SQL> select to_char(current_scn) from v$database;

CURRENT_SCN
-----------
1447478

On the standby:

SQL> select to_char(current_scn) from v$database;

CURRENT_SCN
-----------
1447474


 

Tuesday, April 25, 2017

Database shutdown immediate hang situation

Database shutdown immediate hang situation :        

Many times Oracle DBA's are faced with a situation where shutting down the instance with shutdown immediate seems to take infinite time and gives a impression that the session is hung. In most of the cases this is not a hang. Hang can be defined as a scenario when few sessions/processes are waiting on some action and in turn blocking other session/processes to complete their tasks. Now the original sessions could be waiting because of resource issues or Oracle Bugs.

Shutdown immediate can take long time to complete (appear to be hung) because of three reasons:
1. Uncommitted transactions are being rolled back.
2. SMON is cleaning temp segments or performing delayed block cleanouts.
3. Processes still continue to be connected to the database and do not terminate.

1. Uncommitted transactions are being rolled back:
This is the case when the message 'Waiting for smon to disable tx recovery' is posted in the alert log after we issue shutdown immediate.
There are two reasons for this:
- A large query was running at the time of shutdown immediate.
-A large transaction was running at the time of shutdown immediate.
For large queries:
SQL > select count(*) from v$session_longops where time_remaining>0;
If it returns a value > 0 then we can do a shutdown abort and then startup restrict and then again shutdown immediate.
For large transactions:
SQL > select sum(used_ublk) from v$transaction;
If it returns a large value then we have to wait for a long time for shutdowm to get completed.
If the large transaction is aborted and then shutdown is issued then we have to query v$fast_start_transactions and v$fast_start_server, we will not see anything in v$transaction at this time.
At this particular moment transaction recovery is going on and the count(*) will keep on decreasing:
SQL > select count(*) from v$fast_start_transaction;
Decreasing count will show that recovery is going on and when the recovery is completed the database will be shutdown.
But it is not desirable under some circumstances such as, when we have very short maintance window and we need to perform a shutdown immediate to do some work, in those cases we can use the following event and set in the init.ora file TEMPERORARLY To disable transaction recovery:
event="10513 trace name context forever, level 2"
and bounce the instance and issue shutdown immediate to get complete without transaction recovery.SMON will not do a transaction recovery untill this event is set in the init.ora file so it is necessary to remove this event whenever you get a chance to shutdown the database again, this time shutdown immediate can even take 3-5 hours(Just remove this event from pfile).

2. SMON is cleaning temp segments or performing delayed block cleanouts:
During a SHUTDOWN IMMEDIATE and SHUTDOWN NORMAL, SMON cleans up extents which are no longer needed and marking them as freed. It means that count from uet$ will decrease and count in fet$ will increase.
To verify that the temporary segments are decreasing have an active session available in SQL during the SHUTDOWN IMMEDIATE. Run query to ensure the database is not hanging, but is actually perform extent cleanup:
SQL> select count(block#) from fet$;
COUNT(BLOCK)
----------
115

SQL> select count(block#) from uet$;
COUNT(BLOCK)
----------
713
After some time, issue the query again and check the results:
SQL> select count(block#) from fet$;
COUNT(BLOCK)
----------
210

SQL > select count(block#) from uet$;
COUNT(BLOCK)
----------
512
If you do not have sufficient time to wait for this cleanup then you can set the following event and bounce the database and reissue shutdown immediate to skip this cleanup:
event="10061 trace name context forever, level 10"
It allows you to prevent SMON from cleaning up temporary segments. Again it is not recommended to set this event event forever. Whenever you have large downtime remove this event and allow SMON to do its work.

3. Processes still continue to be connected to the database and do not terminate:
After issuing shutdown immediate, If we see entries in alert log file as:
Tue Jan  8 12:00:27 2008
Active call for process 10071 user 'oracle' program 'oracle@server.domain.abc (J001)'
SHUTDOWN: waiting for active calls to complete.
Tue Jan  8 12:00:57 2008

SHUTDOWN: Active sessions prevent database close operation
It shows that there are some active calls at program 'oracle@server.domain.abc (J001)' which pmon is not able to clear up.This message is due to the fact that database is waiting for pmon to clean up processes, but pmon is unable to clean them. The client connections to the server are causing the shutdown immediate or normal to hang. Do the following in this case:
1. Before shutdown immediate, shutdown the listener:
$ lsnrctl stop
2. Now check if there are any connection present at the database as:
$ ps -eaf | grep LOCAL
It will give you the OSPIDs of the client connected to database.
3 Manually kill them as:
# Kill -9 <OSPID>
4. Issue shutdown immediate now.
Do not forget to bring up the listener after startup
In addition to this you can set 10046 event in the session used to shutdown the instance. This will help to tell the event on which session is waiting
SQL>alter session set events '10046 trace name context forever, level 12'

SQL>Shutdown immediate;
Look for the trace file in user_dump_dest location. Also look at the alert.log for any other messages. They might be helpful in case the shutdown is experiencing hang situation.

Saturday, April 1, 2017

How to check RMAN backup status and completion time

Que : How to check RMAN backup status and completion time.

Ans :

SQL> select SESSION_KEY, INPUT_TYPE, STATUS,
     to_char(START_TIME,'mm/dd/yy hh24:mi') start_time,
     to_char(END_TIME,'mm/dd/yy hh24:mi') end_time,elapsed_seconds/3600 hrs
     from V$RMAN_BACKUP_JOB_DETAILS
     order by session_key;
 
Output : 
 
SESSION_KEY INPUT_TYPE    STATUS                  START_TIME     END_TIME              HRS
----------- ------------- ----------------------- -------------- -------------- ----------
       2505 ARCHIVELOG    COMPLETED WITH WARNINGS 03/07/17 22:03 03/07/17 22:20 .285277778
       2509 DB INCR       COMPLETED               03/07/17 23:01 03/08/17 00:17 1.26972222
       2514 ARCHIVELOG    COMPLETED WITH WARNINGS 03/08/17 22:03 03/08/17 22:21 .291944444 

Saturday, February 25, 2017

Find inactive sessions script to kill it

Script for finding inactive session and generate script for kill :

Script :

select 'Alter system kill session '||''''||sid||','||serial#||''''||' immediate ;' from v$session where sid in (select sid from v$session where status='INACTIVE' and username = 'USER_NAME');

Output :

SQL > select 'Alter system kill session '||''''||sid||','||serial#||''''||' immediate ;'
           from v$session where sid in (select sid from v$session where status='INACTIVE'
           and username = 'USER_NAME');

'ALTERSYSTEMKILLSESSION'||''''||SID||','||SERIAL#||''''||'IMMEDIATE;'
--------------------------------------------------------------------------------
Alter system kill session '111,7963' immediate ;
Alter system kill session '112,44431' immediate ;
Alter system kill session '123,38269' immediate ;
Alter system kill session '138,12327' immediate ;









Sunday, February 19, 2017

How to drop all objects from single schema :

Script :



> select 'DROP '||OBJECT_TYPE||' '||OBJECT_NAME||';' from user_objects; 



For LOB objects need to purge recyclebin.

> purge  recyclebin;

ORA-27101: shared memory realm does not exist

Oracle Error : 

ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist

Solution :  

Make sure ORACLE_HOME and ORACLE_SID is correct.

And then try to connct DB.


Sometimes in case of window ,  if event log is full , then we get this error . So delete the event logs and try to connect again .

Sometimes , in case of window , we resolve this issue by simply restart the oracle services . so restart the window services as
start --- cmd  --- net stop oracleservice
then start again,
--- net start oracleservice