Wednesday 3 June 2020

How to Use Logon Trigger to trace sessions connected to Oracle database?

To start tracing:

create or replace trigger user_logon_trg
after logon on database
begin
if USER = 'xxxx' then
execute immediate
'Alter session set events ''10046 trace name context forever, level 8''';
end if;
end;
/

/* Login a new session as User 'xxxx' and execute your selects to be traced */


NOTE: The following syntax can also be used within the if logic to also get the user name or to add more granularity by specifying a host name where the connection originated.

IF SYS_CONTEXT('USERENV','SESSION_USER') = '<USER_NM>' AND SYS_CONTEXT('USERENV','HOST') = '<HOST_NM>' THEN

To stop tracing: via LogOff Trigger (needs to be created before logging off)

create or replace trigger user_logoff_trg
before logoff on database
begin
if USER = 'xxxx' then
execute immediate
'Alter session set events ''10046 trace name context off''';
end if;
end;
/


What is the difference between Switchover and Failover in Oracle Dataguard?

A switchover means just switching roles between the primary database and standby db.
nswitchover, the primary database chnaged to a standby role, and the standby database changed to the primary role.
This is typically done for planned maintenance of the primary db server.

A failover is when the primary database fails and one of the standby databases is 
transitioned to take over the primary role. Failover is performed only in the event 
of a catastrophic failure of the primary database, and there is no possibility of 
recovering the primary database in a timely manner. Failover may or may not result 
in data loss depending on the protection mode in effect at the time of the failover.

How to enable ArchiveLog mode in Oracle Database RAC Environment?

Steps to enable Archivelog mode in RAC environment:

The following steps need to be taken to enable archive logging in a RAC database environment:

1. Shutdown immediate all database instances
$ srvctl stop database -d <db_unique_name>

2. Startup database in mount mode
$ srvctl start database -d <db_unique_name> -o mount

3. Enable archive logging
$ sqlplus / as sysdba
sql> alter database archivelog;
sql> exit;

4. Stop database
$ srvctl stop database -d <db_unique_name>

5.Start all database instances
$ srvctl start database -d <db_unique_name>

6.Verify archiving is enabled/disabled 
sql> archive log list;