Blog

How Long a Session Has been Idle or Inactive In Oracle Database ?

SQL to find how long a session has been ACTIVE or IDLE, very handy.

SYMPTOMS

There are up to one thousand sessions connected to Oracle Database from a Weblogic connection pool. User wanted to know how long those sessions have been idle ( INACTIVE), so the Weblogic connection pool can be reviewed and reconfigured properly.

SOLUTION

The below query can be run to meet this requirement:

SQL>select USERNAME,
           MACHINE,
           STATUS,
           LOGON_TIME,
           LAST_CALL_ET INACTIVE_SECONDS 
    from  gv$session 
    order by LAST_CALL_ET desc; 

USERNAME   MACHINE    STATUS    LOGON_TIME         INACTIVE_SECONDS
---------- ---------- -------   -----------------  ----------------
USERAPP    machine1  INACTIVE   20170917-17:04:17             3523
USERAPP    machine2  INACTIVE   20170918-02:57:03             2068
USERAPP    machine3  INACTIVE   20170917-17:52:09             1141
...
..
.
USERAPP    machine1 INACTIVE   20170917-17:17:01               176
USERAPP    machine1 I NACTIVE   20170917-17:17:01              176

REFERENCES

According to Oracle doc :

LAST_CALL_ETNUMBERIf the session STATUS is currently ACTIVE, then the value represents the elapsed time in seconds since the session has become active.If the session STATUS is currently INACTIVE, then the value represents the elapsed time in seconds since the session has become inactive.

The below query can also get the results as per Oracle Doc ID 365693.1.

SQL>select sid, seconds_in_wait 
      from v$session_wait
     where state='WAITING' 
       and event='SQL*Net message from client'
 order by seconds_in_wait desc;

Data Guard Not Applying Logs After RAC Standby Database Restarted

It looks like a bug. Property “PreferredApplyInstance” specifies the standby instance to apply logs

11.2.0.4 RAC standby database is not applying archivelogs after instances are all restarted.  It is configured in Data Guard management.

After investigation, there is nothing special, but only “PreferredApplyInstance” is configured for RAC node1 ‘STBTEST1’.

Original :

PreferredApplyInstance ='STBTEST1'

Modify “PreferredApplyInstance” to empty:

PreferredApplyInstance=''

Restarted RAC standby database instances , all archivelogs are applied to database from the node which is chosen randomly by Data Guard.

ORA-03135: connection lost contact to Standby Database

Newly built 12.1.0.2 DataGuard got errors.

Primary Database alert.log:

Mon Sep 11 11:35:59 2017
TT01: Attempting destination LOG_ARCHIVE_DEST_2 network reconnect (3135)
TT01: Destination LOG_ARCHIVE_DEST_2 network reconnect abandoned
Mon Sep 11 11:35:59 2017
Errors in file /u01/app/oracle/diag/rdbms/ractest/RACTEST1/trace/RACTEST1_tt01_30967.trc:
ORA-03135: connection lost contact
Error 3135 for archive log file 42 to 'STBTEST'
Mon Sep 11 11:35:59 2017
Errors in file /u01/app/oracle/diag/rdbms/ractest/RACTEST1/trace/RACTEST1_tt01_30967.trc:
ORA-03135: connection lost contact
LNS: Failed to archive log 42 thread 1 sequence 852 (3135)

Standby Database Alert.log

Fatal NI connect error 12170.

VERSION INFORMATION:
 TNS for Linux: Version 12.1.0.2.0 - Production
 Oracle Bequeath NT Protocol Adapter for Linux: Version 12.1.0.2.0 - Production
 TCP/IP NT Protocol Adapter for Linux: Version 12.1.0.2.0 - Production
 Time: 06-SEP-2017 16:50:33
 Tracing not turned on.
 Tns error struct:
 ns main err code: 12535

TNS-12535: TNS:operation timed out
 ns secondary err code: 12608
 nt main err code: 0
 nt secondary err code: 0
 nt OS err code: 0
 Client address: (ADDRESS=(PROTOCOL=tcp)(HOST=xx.xx.xx.xx)(PORT=63637))
Wed Sep 06 16:50:34 2017
RFS[37]: Possible network disconnect with primary database

Subscribe to get access

Read more of this content when you subscribe today.

ORA-16698: LOG_ARCHIVE_DEST_n parameter set for object to be added

The ORA-16698 occurred when creating a new Data Guard Broker configuration on 12.1.0.2 RAC database.

DGMGRL>CREATE CONFIGURATION 'RACTEST_DG' as PRIMARY DATABASE IS 'RACTEST' CONNECT IDENTIFIER IS RACTEST;
Error: ORA-16698: LOG_ARCHIVE_DEST_n parameter set for object to be added

Subscribe to get access

Read more of this content when you subscribe today.

Also Make sure do the same before you configure Data Guard Broker by using Oracle OEM. Otherwise it will fail without any errors provided, for which it might take you some time to investigate.

ORA-15001: diskgroup does not exist or is not mounted. ORA-15040: diskgroup is incomplete

Hit a bug when run RMAN command “restore controlfile to from “

SYMPTOM

              GI: 12.2.0.1.170814 (26609817)
        RAC HOME: 12.1.0.2.160419 (22291127)

Just starting to build a standby database, and trying to put standby database controlfile into ASM diskgroup by using RMAN , got the following errors:

RMAN> restore controlfile to '+DATA' from '/tmp/standby.ctl';

Starting restore at 2017-09-05 09:44:30
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1694 instance=STYTEST1 device type=DISK

channel ORA_DISK_1: restoring control file
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 09/05/2017 09:44:32
ORA-19870: error while restoring backup piece /tmp/standby.ctl
ORA-19504: failed to create file "+DATA"
ORA-17502: ksfdcre:4 Failed to create file +DATA
ORA-15001: diskgroup "DATA" does not exist or is not mounted
ORA-15040: diskgroup is incomplete

CAUSE

This hits the bug “21626377 – 12.2_150812: DBCA FAILS TO CREATE 12102 DB OVER 12.2 GI/ASM”

SOLUTION

1) Apply the latest PSU patch against RAC home( 12.1.0.2). For now , the latest RU for 12.1.0.2 is 12.1.0.2.170814 (26609783).

2) Retry again from RMAN successfully.

RMAN> restore controlfile to '+DATA' from '/tmp/standby.ctl';

Starting restore at 2017-09-05 10:30:39
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=989 instance=STYTEST1 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 2017-09-05 10:30:40

3) Review alert.log. The diskgroup “+DATA” was mounted successfully.

Tue Sep 05 10:30:40 2017
NOTE: ASMB mounting group 2 (DATA)
...
..
.
SUCCESS: mounted group 2 (DATA)
...
..
.