ORA-01031: insufficient privileges

Issue:

On a windows Server 2008 R2 machine hosting a 11.2.0.3 database when I try to connect to the database as sys with sysdba privs I get the error ‘ORA-01031: insufficient privileges’. Whereas when I provide the sys user password it connects successfully as shown below.

 

ORACLE_SID has been set to ‘DEVC’
ORACLE_HOME has been set to ‘d:\app\oracle\product\11.2.0\dbhome_2’

C:\Users\Deepa.Raja>sqlplus /  as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Thu Jun 18 01:38:08 2015

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

ERROR:
ORA-01031: insufficient privileges

 

C:\Users\Deepa.Raja>sqlplus  "sys/test as sysdba"

SQL*Plus: Release 11.2.0.3.0 Production on Thu Jun 18 01:38:45 2015

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

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>

 

Reason:

When we do sqlplus / as sysdba from the database server, we are making a local connection to the database instance.

To make local connections to an Oracle instance a user must either:

a) Supply a password
b) Be a user belonging to a special ‘dba’ group.

The ‘DBA’ group is chosen at installation time and is usually the group ‘dba’ by default. In our case it was ora_dba

Fix:

Open control panel and change the group for your user as shown below in the screen shots.

image

 

image

 

image

 

image

 

image

 

 

C:\Users\Deepa.Raja>sqlplus /  as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Thu Jun 18 01:38:45 2015

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

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>

Viewing alert log for oracle database on windows

Oracle DBAs used to working in linux environment often hate to manage oracle databases running on windows. As a novice to oracle on windows, I find the following difficult in Windows compared to linux

  • listing directories and sub directories along with their size (du – sh in linux)
  • killing sessions (kill –9 in linux)
  • viewing alert log and waiting for latest updates (linux less command with shift f)

There are lot more to add to this list…But let me stop here and I would like to share a  solution for the last issue. I always had trouble reading alert log on windows environment. In cases where there was no log rotation, the files were too big and took a long time to load in notepad. Also when we are looking for latest updates we need to close the notepad and open it again to view the latest alert log entries. This makes it even worse. I found a better solution  with oracle 11g.

Oracle introduced Automatic diagnostic repository (ADR) in 11g, the file based repository for diagnostic data. We can use the command line interface available for ADR called adrci to view the alert logs.

 

Connect to adrci and set the homepath

 

F:\BIAS\scripts>adrci

ADRCI: Release 11.2.0.3.0 – Production on Wed Jun 10 00:56:06 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

ADR base = "C:\APP\ORACLE"
adrci> show homes
ADR Homes:
diag\clients\user_amabesadmin\host_343795160_76
diag\clients\user_anshal.nath\host_343795160_76
diag\clients\user_arun.kumar\host_343795160_76
diag\clients\user_mansoor.naeem\host_343795160_76
diag\clients\user_SYSTEM\host_343795160_76
diag\clients\user_UNKNOWN\host_343795160_76

show alert

This opens the alert log file in a notepad

adrci> show  alert

ADR Home = C:\APP\ORACLE\diag\rdbms\gmcfpr01\prod:
*************************************************************************
Output the results to file: C:\Users\DEEPA~1.RAJ\AppData\Local\Temp\5\alert_7428_6896_prod_1.ado

 

show alert –tail

This shows the last 10 entries from the alert log file.

adrci> show alert -tail
2015-06-09 23:56:50.687000 -04:00
LNS: Standby redo logfile selected for thread 1 sequence 35262 for destination LOG_ARCHIVE_DEST_2
2015-06-09 23:57:03.794000 -04:00
Archived Log entry 88814 added for thread 1 sequence 35261 ID 0xd8ac4e2b dest 1:
Archived Log entry 88815 added for thread 1 sequence 35261 ID 0xd8ac4e2b dest 4:
2015-06-10 00:11:24.650000 -04:00
Thread 1 cannot allocate new log, sequence 35263
Private strand flush not complete
  Current log# 3 seq# 35262 mem# 0: F:\APP\ORACLE\ORADATA\PROD\REDO03.LOG
2015-06-10 00:11:27.742000 -04:00
Thread 1 advanced to log sequence 35263 (LGWR switch)
  Current log# 4 seq# 35263 mem# 0: F:\APP\ORACLE\ORADATA\PROD\REDO04.LOG
LNS: Standby redo logfile selected for thread 1 sequence 35263 for destination LOG_ARCHIVE_DEST_2
2015-06-10 00:11:45.752000 -04:00
Archived Log entry 88817 added for thread 1 sequence 35262 ID 0xd8ac4e2b dest 1:
Archived Log entry 88818 added for thread 1 sequence 35262 ID 0xd8ac4e2b dest 4:
2015-06-10 00:20:00.222000 -04:00
Errors in file C:\APP\ORACLE\diag\rdbms\gmcfpr01\prod\trace\prod_j001_17644.trc:
ORA-12012: error on auto execute of job "SYS"."LIGHTWEIGHT_APP"
ORA-06576: not a valid function or procedure name

 

show alert –tail 15

Shows the last 15 entries from the alert log

adrci> show alert -tail  15
2015-06-09 22:01:08.798000 -04:00
Archived Log entry 88811 added for thread 1 sequence 35260 ID 0xd8ac4e2b dest 1:
Archived Log entry 88812 added for thread 1 sequence 35260 ID 0xd8ac4e2b dest 4:
2015-06-09 22:20:00.097000 -04:00
Errors in file C:\APP\ORACLE\diag\rdbms\gmcfpr01\prod\trace\prod_j001_15832.trc:
ORA-12012: error on auto execute of job "SYS"."LIGHTWEIGHT_APP"
ORA-06576: not a valid function or procedure name
2015-06-09 22:59:07.000000 -04:00
Warning: VKTM detected a time drift.
Time drifts can result in an unexpected behavior such as time-outs. Please check trace file for more details.
2015-06-09 23:00:13.805000 -04:00
End automatic SQL Tuning Advisor run for special tuning task  "SYS_AUTO_SQL_TUNING_TASK"
2015-06-09 23:20:00.220000 -04:00
Errors in file C:\APP\ORACLE\diag\rdbms\gmcfpr01\prod\trace\prod_j001_13464.trc:
ORA-12012: error on auto execute of job "SYS"."LIGHTWEIGHT_APP"
ORA-06576: not a valid function or procedure name
2015-06-09 23:56:47.402000 -04:00
Thread 1 cannot allocate new log, sequence 35262
Private strand flush not complete
  Current log# 7 seq# 35261 mem# 0: F:\APP\ORACLE\ORADATA\PROD\REDO07.LOG
2015-06-09 23:56:50.484000 -04:00
Thread 1 advanced to log sequence 35262 (LGWR switch)
  Current log# 3 seq# 35262 mem# 0: F:\APP\ORACLE\ORADATA\PROD\REDO03.LOG
LNS: Standby redo logfile selected for thread 1 sequence 35262 for destination LOG_ARCHIVE_DEST_2
2015-06-09 23:57:03.794000 -04:00
Archived Log entry 88814 added for thread 1 sequence 35261 ID 0xd8ac4e2b dest 1:
Archived Log entry 88815 added for thread 1 sequence 35261 ID 0xd8ac4e2b dest 4:
2015-06-10 00:11:24.650000 -04:00
Thread 1 cannot allocate new log, sequence 35263
Private strand flush not complete
  Current log# 3 seq# 35262 mem# 0: F:\APP\ORACLE\ORADATA\PROD\REDO03.LOG
2015-06-10 00:11:27.742000 -04:00
Thread 1 advanced to log sequence 35263 (LGWR switch)
  Current log# 4 seq# 35263 mem# 0: F:\APP\ORACLE\ORADATA\PROD\REDO04.LOG
LNS: Standby redo logfile selected for thread 1 sequence 35263 for destination LOG_ARCHIVE_DEST_2
2015-06-10 00:11:45.752000 -04:00
Archived Log entry 88817 added for thread 1 sequence 35262 ID 0xd8ac4e2b dest 1:
Archived Log entry 88818 added for thread 1 sequence 35262 ID 0xd8ac4e2b dest 4:
2015-06-10 00:20:00.222000 -04:00
Errors in file C:\APP\ORACLE\diag\rdbms\gmcfpr01\prod\trace\prod_j001_17644.trc:
ORA-12012: error on auto execute of job "SYS"."LIGHTWEIGHT_APP"
ORA-06576: not a valid function or procedure name

show alert –tail –f

This is unix equivalent of less with a shift f. This basically shows the last 10 entries and waits for the latest updates

adrci> show alert -tail -f
2015-06-09 23:56:50.687000 -04:00
LNS: Standby redo logfile selected for thread 1 sequence 35262 for destination LOG_ARCHIVE_DEST_2
2015-06-09 23:57:03.794000 -04:00
Archived Log entry 88814 added for thread 1 sequence 35261 ID 0xd8ac4e2b dest 1:
Archived Log entry 88815 added for thread 1 sequence 35261 ID 0xd8ac4e2b dest 4:
2015-06-10 00:11:24.650000 -04:00
Thread 1 cannot allocate new log, sequence 35263
Private strand flush not complete
  Current log# 3 seq# 35262 mem# 0: F:\APP\ORACLE\ORADATA\PROD\REDO03.LOG
2015-06-10 00:11:27.742000 -04:00
Thread 1 advanced to log sequence 35263 (LGWR switch)
  Current log# 4 seq# 35263 mem# 0: F:\APP\ORACLE\ORADATA\PROD\REDO04.LOG
LNS: Standby redo logfile selected for thread 1 sequence 35263 for destination LOG_ARCHIVE_DEST_2
2015-06-10 00:11:45.752000 -04:00
Archived Log entry 88817 added for thread 1 sequence 35262 ID 0xd8ac4e2b dest 1:
Archived Log entry 88818 added for thread 1 sequence 35262 ID 0xd8ac4e2b dest 4:
2015-06-10 00:20:00.222000 -04:00
Errors in file C:\APP\ORACLE\diag\rdbms\gmcfpr01\prod\trace\prod_j001_17644.trc:
ORA-12012: error on auto execute of job "SYS"."LIGHTWEIGHT_APP"
ORA-06576: not a valid function or procedure name
2015-06-10 01:20:00.214000 -04:00
Errors in file C:\APP\ORACLE\diag\rdbms\gmcfpr01\prod\trace\prod_j001_15528.trc:
ORA-12012: error on auto execute of job "SYS"."LIGHTWEIGHT_APP"
ORA-06576: not a valid function or procedure name

 

SHOW ALERT -P "MESSAGE_TEXT LIKE ‘%ORA-%’”

view_alert_log

 

SHOW ALERT -P "MESSAGE_TEXT LIKE ‘%ORA-%’ AND originating_timestamp > systimestamp-1"

view_alert_log3

 

SHOW ALERT -P "ORIGINATING_TIMESTAMP >= ‘2015-06-08 00:00:00.000000 -04:00’ AND originating_timestamp < ‘2015-06-09 02:00:00.000000 -04:00’"

view_alert_log1

 

Also ADR data can be viewed from support work bench in OEM. So we can view alert from OEM as well.

view_alert_log2

 

To view the xml log contents click on the go button as shown in the pic.

view_alert_log4

And the output looks like this.

view_alert_log5

 

To view the text base alert log file click on ‘Switch to text alert log contents’ hyperlink.

 

view_alert_log8

 

Choose the time period for viewing the alert log.

view_alert_log6

 

Click on go to fetch results as shown below.

view_alert_log7

ORACLE DBA interview questions

Core DATABASE

compatible parameter

Size of log buffer related to redo log size

Explain logfile switch and logfile sync wait

What happens when you issue an update statement in an oracle database

Difference between an mview and view

How to find the number of cpus in a server to decide on parallelism

Is there an option to by pass inventory and apply patch

 

Export/Import

Can you use expdp against and Read Only database

What happens if you change the name of the master table in the database for expdp

Why is expdp faster than exp?

Expdp is carried out on server side and uses direct path api(streams)/external tables api.

How to speed up exp

how to import without affecting already existing data in a table

What are the precautions to take before refreshing a schema

How to investigate a stuck expdp job

 

Tuning

What SQL tuning have you done

What is a profile?

 

Indexes

How to prevent an SQL from using an index

What is the criteria for rebuilding index

Increasing processes what shared memory do u need to check

how to fix an index corruption

what is index skip scan

What is multi block read count

What are the considerations to be taken before adding a new database to a oracle server that has an ASM instance serving multiple databases.

 

Recovery

What do we need to do if  there is a corruption in an online redo log of a database running in no archive log mode

What are the steps involved in creating an RMAN clone

 

RAC

Rac scan ip how it decides which node

Ctsctl stop CRS stops db in what mode

How to load balance in RAC both on client side and service side

What are the common causes of node eviction?

What is the difference between a 11.1 and 11.2 RAC

 

OEM

OEM Sysman user password change

How do you add targets to OEM

 

Dataguard

Primary adding a tablespace of 60G. But at the standby we get the error that there is not enough space. How to resolve the issue.

how to improve the performance of an redo apply

What are the different protection levels in oracle dataguard.

A standby is behind the primary by about 4 days. What is the quickest way to recover the physical standby database and bring it up to date.

What are the parameters relevant to dataguard

 

Troubleshooting

Unable to connect to a database instance. How to investigate it

Instance crashed and no information in the alert log. How to investigate this.

 

12C New features

Increase SGA for an oracle database in windows with a dataguard physical standby

Environment:

Oracle: 11.2.0.3 enterprise edition

OS: Windows 2008 R2 Standard

OEM: 12C

 

Task: To increase SGA on a production single instance database with a single instance physical standby database.

Research: Ensure there is enough room for the increase in SGA. In our case the

Total RAM on server: 12GB RAM.
Current SGA: 4GB
Current PGA : 5GB

Required SGA: 6GB

For running a windows 64 bit version, Microsoft recommends a RAM of 2GB for OS. We wanted to increase the SGA to 6GB. But this would take the total RAM requirement to 2GB (OS)+ 6GB (SGA)+5GB (PGA) = 13GB which is more than available 12GB. As there was a shortage, after analyzing the PGA requirement during the peak period for the database (memory advisors), we decided to decrease the PGA to 3GB and increase SGA to 6GB so that there would be enough RAM for OS.

1)Create Blackout in OEM 12C
Blackout both the primary and standby db instance (just primary would do, but didn’t want to get alerted by lag and hence included standby too)

2)Defer Sync: Connect to primary database and defer sync to standby

show parameter archive_dest
alter system set log_archive_dest_state_2=defer scope=both;

3)Check and amend memory parameters on primary

show parameter sga
show parameter pga
alter system set sga_target=6G scope=spfile
alter system set sga_max_size=6G scope=spfile
alter system set pga_aggregate_target=3G scope=spfile
shutdown immediate
start up

4)verify changes on primary

show parameter target
show parameter sga
show parameter pga

5)validate primary database after bounce
check listener listening to the db service
connect via tns entry and verify successful connection
check alert log

6)Re-enable sync to standby

alter system set log_archive_dest_state_2=enable scope=both;
show parameter archive_dest

 

7)verify sync
on primary
archive log list

On standby
archive log list

On Primary
alter system switch logfile
alter system switch logfile
archive log list

On standby
archive log list
Ensure the current log sequence is upto date

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            G:\oracle\Archive\
Oldest online log sequence     34540
Next log sequence to archive   0
Current log sequence           34547

7)verify alert log on standby

In windows environment viewing alert log for latest updates is a pain as we have to close and reopen the alert log for the latest updates. If the alert log is huge then this is frustrating. ADRCI comes in handy in windows.

adrci> set homepath diag\rdbms\gmcfad01\gmcfad01
adrci> show alert –tail

 

7)Remove blackout in OEM

oraenv for windows

With oracle databases on linux platform it is really easy to set environment variables to connect to a database using oracle provided utility called oraenv. Unfortunately it oracle has not provided similar utility for windows environment.

 

So in order to set ORACLE_HOME and ORACLE_SID we need to check the services and find the oracle home and SID from them and we have to manually run

set ORACLE_HOME=D:\app\oracle\product\11.1.0\db
set ORACLE_SID=cc92dev1
set PATH=%PATH%;%ORACLE_HOME%\bin

 

To avoid the above we can create a simple bat script as below

 

Create a file called oraenv.bat and add the following to that file

 

@echo off
REM Set the environment Variables
REM You will need to set the path to your oraenv directory

SET ORAENV_DIR=F:\BIAS\scripts\
SET ORAENV_CURRENT_SID=%ORAENV_DIR%\cur_sid.ora
SET ORAENV_ORATAB=%ORAENV_DIR%\oratab.ora

REM Print out the Current ORACLE_SID and prompt for a new one

echo Please enter Oracle SID:
echo Current SID:
for /f "tokens=1 delims=|" %%a in (%ORAENV_ORATAB%) do (
echo %%a
)
for /f  %%a in (%ORAENV_CURRENT_SID%) do (
SET ORA_SID=%%a
)

SET /P ORA_SID="New SID [%ORA_SID%?]: "

REM If the user Enters nothing then keep the Current SID, like UNIX oraenv does 🙂

IF NOT %ORA_SID%=="" echo %ORA_SID% > %ORAENV_CURRENT_SID%

REM Check the ORATAB file to see if this ORACLE_SID is listed
REM If it’s not the jump back to the command prompt

FIND /I "%ORA_SID%|" %ORAENV_ORATAB% > nul
IF NOT %ERRORLEVEL%==0 (
echo Oracle SID not found
exit /b
)

REM Set the ORACLE_SID
set ORACLE_SID=%ORA_SID%

REM Now get the Oracle Home from the oratab file
FOR /F "tokens=2 delims=|" %%A IN (‘FIND /I "%ORA_SID%|"
%ORAENV_ORATAB%’) DO SET ORACLE_HOME=%%A

REM Last thing to do is set the Path
SET PATH=%ORACLE_HOME%\bin;%PATH%

REM And as a nice little touch we will Print out some details for the user
ECHO ORACLE_SID has been set to ‘%ORACLE_SID%’
ECHO ORACLE_HOME has been set to ‘%ORACLE_HOME%’

@echo on

 

Then create another file called oratab.ora with contents as shown below

image

 

And finally create another file called cur_sid.ora with one entry as shown below.

image

 

image

ORA-12516, TNS: listener could not find available handler with matching protocol stack

Problem

Users complaining issues connecting to the database intermittently. Following error recorded by the applications

ORA-12516, TNS:listener could not find available handler with matching protocol stack

Investigation

Check alert log for errors

Errors in file /u01/app/oracle/diag/rdbms/qweb2/QWEB21/trace/QWEB21_j003_23298.trc:
ORA-12012: error on auto execute of job "STOCK_BROADCAST"."REFRESH_MV_ADVERT_MEDIA"
ORA-12520: TNS:listener could not find available handler for requested type of server
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2563
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2776
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 2745
ORA-06512: at line 1

Connect to SQLplus and find the number of sessions connecting to the database

SQL*Plus: Release 11.2.0.3.0 Production on Thu Mar 20 14:12:56 2014

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

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options

SQL> select count(*) from v$Session;

  COUNT(*)
———-
       993

 

This indicates the number of sessions is almost equal to the number of processes. So listener will block connections if there are not enough processes. To see who has the most number of connections against the database do the following

SQL> show parameter process

NAME                                 TYPE        VALUE
———————————— ———– ——————————
aq_tm_processes                      integer     1
cell_offload_processing              boolean     TRUE
db_writer_processes                  integer     4
gcs_server_processes                 integer     2
global_txn_processes                 integer     1
job_queue_processes                  integer     50
log_archive_max_processes            integer     4
processes                            integer     1000
processor_group_name                 string

Shows that the maximum number of processes allowed is only 1000 and we are very close to the limit. So where are the connections coming from? We could identify that using the following query

SQL> select username, count(*) from v$session group by username;

USERNAME                         COUNT(*)
—————————— ———-
                                       52
ATD_UK_PSPRELEASE                       1
ATD_IE_MMV                              1
ATD_UK_DSC                             10
ATD_UK_SECURITY                        10
ATD_UK_POLA_INTEGRATION                10
ATD_URS                                 2
ATD_UK_DWS                             31
ATD_UK_DF                               6
ATD_APP_AUTH                            1
ATD_UK_ETL_SUPPORT                    636

There are unusually high number of connections from the following schema causing the database issue
ATD_UK_ETL_SUPPORT

HOW TO- Setup your own VM instance to use instead of Cygwin for installing Oracle software on Linux

To setup your very own VM instance you will need to do the following (you will need 20Gb disk space free before starting and it’s recommended to defrag your hard drive before starting too to optimise performance):

1. Download and install Oracle VM VirtualBox:

http://download.virtualbox.org/virtualbox/4.1.18/VirtualBox-4.1.18-78361-Win.exe

Run the installer with all default settings.

2. Download the pre-built Oracle VM instance (Oracle Developer Day), it’s 4 Gb

http://download.oracle.com/otn/other/virtualbox/dd/Oracle_Developer_Day.ova

3. Import the VM instance on VirtualBox:

File > Import Appliance to launch Appliance Import Wizard.

Click Choose… to browse to the directory where the VM instance is and select the Oracle Developer Day.ova then click Next> to begin importing the virtual machine.

This will import the VM instance with its 2 disks (2x 11Gb, 11Gb used on pre-built leaving 11Gb free which will grow on your local disk as when you use within your VM instance)

Once finished, you will see ‘Oracle Developer Days (Powered Off)’

4. Before starting you need to enable networking (otherwise your VM instance will only be local and not able to access anything on the network):

Click on Oracle Developer days. Once select setting gets highlighted. Click on setting. Then click Network in Virtual Box.

Then on Adapter 1, click Enable Network Adapter and change Attached to: NAT as shown below:
image

You should Adaptor 1: PCnet-FAST III (NAT) as shown below:
image

5. Start your VM instance, double-click the OTN Developer Days VM.

Click OK to close the Virtualbox Information dialogs.

When you get to the Enterprise Linux 5 screen you can now login (Username and password is oracle).

Allow the process to complete; it is ready when you see a terminal window, which you can close.

Once you are finished working in the guest VM you can shut it down via System > Shut Down; this will return the guest VM to the Powered Off state.

6. To run Oracle Universal Installer on any server:

Double Click Terminal

Then Type ssh -X oracle@server

Then when you run runInstaller it will appear within the VM instance J

More info here:

https://www.virtualbox.org/

http://www.oracle.com/technetwork/community/developer-vm/index.html

http://www.oracle.com/technetwork/database/enterprise-edition/databaseappdev-vm-161299.html

Creating TEST2 clone database

Remember the following when creating clone volumes for a clone database
=======================================================================
Take a snap of all the data and redo volumes involved with the dbs to be cloned.
Also make sure data volumes are snapped before the redo volumes and dont leave too much gap between the two or you need to clone the arch as well.
Clone archive volume only if we need to go back to a point in time for which the redo logs are only in the archive
If we are cloning live databases that are up and running take a hot backup and base clones on those snaps.
Make sure you dont interfere with the 30 mins regular backups.
Base the clone on the correct datacentre snaps depending on the server you are mounting it on
Notify networks to create the clones on the correct data centre based on the snaps ending with name CLONE_<ddmmyyyy>
For example to clone TEST2 voume to create TEST2 clone DB

ssh oracle@tcygg01
export ORACLE_SID=TEST21
sqlplus / as sysdba
alter database begin backup;
exit;
sudo su
/usr/bin/rsh ga_test2_data.data.dc1.oracle.net -n snap create TCYGA_TEST2_DATA TCYGA_TEST2_CLONE_25062012
/usr/bin/rsh test2_redo_a.data.dc1.oracle.net -n snap create TEST2_REDO_A TEST2_REDO_A_TEST2_CLONE_25062012
/usr/bin/rsh test2_redo_b.data.dc1.oracle.net -n snap create TEST2_REDO_B TEST2_REDO_B_TEST2_CLONE_25062012
exit
sqlplus / as sysdba
alter database end backup;
exit;

Mounting the Clone volumes on the target server
==============================================
Once the clone volumes are created by storage administrators mount the volumes on the target server as below

sudo su
vi /etc/fstab
test2_data.data.dc1.oracle.net:/DC1_WEB2_DATA       /oradata/TEST2   nfs     rw,bg,hard,rsize=65536,wsize=65536,vers=3,actimeo=0,nointr,suid,timeo=600,tcp   0       0
test2_redo_a.data.dc1.oracle.net:/DC1_WEB2_REDO_A   /oraredo/TEST2_A nfs     rw,bg,hard,rsize=65536,wsize=65536,vers=3,actimeo=0,nointr,suid,timeo=600,tcp   0       0
test2_redo_b.data.dc1.oracle.net:/DC1_WEB2_REDO_B   /oraredo/TEST2_B nfs     rw,bg,hard,rsize=65536,wsize=65536,vers=3,actimeo=0,nointr,suid,timeo=600,tcp   0       0
exit

mkdir /oradata/TEST2
chown oracle:dba /oradata/TEST2
mkdir /oraredo/TEST2_A
chown oracle:dba /oraredo/TEST2_A
mkdir /oraredo/TEST2_B
chown oracle:dba /oraredo/TEST2_A

mount /oradata/TEST2
mount /oraredo/TEST2_A
mount /oraredo/TEST2_B

 

Create the pfile to point the spfile that is on the mounted volume, check pwd file
==================================================================================

cd $ORACLE_HOME/dbs
vi initTEST21.ora
spfile=’/oradata/TEST2/TEST2/spfileTEST2.ora’

check the target file exists as below
ls /oradata/TEST2/TEST2/spfileTEST2.ora

–create symbolic link to the password file
cd $ORACLE_HOME/dbs
ln -s /oradata/TEST2/TEST2/orapwTEST2 orapwTEST21

Tidy up the tns entries
=======================
Ensure that the db could not  connect to any live database by removing all tns entries to production database

 

Tidy up memory parameters
=========================
create pfile from spfile to edit memory parameters
==================================================
export ORACLE_SID=TEST21
sqlplus / as sysdba
create pfile=’/u01/app/oracle/product/11.1/db/dbs/deepa_test2.ora’ from spfile=’/oradata/TEST2/TEST2/spfileTEST2.ora’;
exit

df -h
tmpfs                 9.0G  1.3G  7.8G  14% /dev/shm

note down memory available

vi deepa_test2.ora

delete all parameters <inst>.__ as they are dynamically managed parameters

leave the cluster database = true
*.memory_max_target=6442450944
TEST21.memory_max_target=6442450944
*.shared_pool_size=512M

remove
*.memory_target=23622320128
TEST21.memory_target=23622320128
WEB12.memory_target=21474836480
*.pga_aggregate_target=4294967296
TEST21.pga_aggregate_target=4294967296
WEB12.pga_aggregate_target=4294967296
*.sga_target=10737418240
TEST21.sga_target=10737418240
WEB12.sga_target=10737418240
*.streams_pool_size=268435456
*.large_pool_size=268435456
*.java_pool_size=268435456
*.db_cache_size=4294967296

LISTENER
========
Ensure *.remote_listener=’LISTENERS_TEST2′ entry exists in tns files

sqlplus / as sysdba
create spfile=’/oradata/TEST2/TEST2/spfileTEST2.ora’ from pfile=’/u01/app/oracle/product/11.1/db/dbs/deepa_test2.ora’;
exit

Open in mount mode and disable all scheduler and dbms_jobs
==========================================================
export ORACLE_SID=TEST21
sqlplus / as sysdba
startup mount;

show parameter job_queue
alter system set job_queue_processes=0;

recover database (using backup controlfile)
alter database noarchivelog
alter database open (resetlogs);

BEGIN
    DBMS_OUTPUT.ENABLE(9000000);
    FOR cur IN
        (SELECT ‘BEGIN SYS.DBMS_SCHEDULER.STOP_JOB(JOB_NAME => ‘ || chr(39) || OWNER || ‘.’ || JOB_NAME || chr(39) || ‘, FORCE => TRUE); END;’ stmt,
        OWNER || ‘.’ || JOB_NAME job_name
        FROM DBA_SCHEDULER_JOBS
        WHERE OWNER <> ‘SYS’)
    LOOP
        –DBMS_OUTPUT.PUT_LINE(cur.stmt);
        BEGIN
            EXECUTE IMMEDIATE(cur.stmt);
        EXCEPTION
        WHEN others THEN
            DBMS_OUTPUT.PUT_LINE(‘JOB NOT RUNNING ‘ || cur.job_name);
            –DBMS_OUTPUT.PUT_LINE(SQLERRM || ‘ CAUSE:’ || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
        END;
    END LOOP;
    FOR cur IN
        (SELECT ‘BEGIN SYS.DBMS_SCHEDULER.DISABLE(NAME => ‘ || ”” || OWNER || ‘.’ || JOB_NAME || ”” || ‘, FORCE => TRUE); END;’ stmt,
        OWNER || ‘.’ || JOB_NAME job_name
        FROM DBA_SCHEDULER_JOBS
        WHERE OWNER <> ‘SYS’)
    LOOP
        –DBMS_OUTPUT.PUT_LINE(cur.stmt);
        BEGIN
            EXECUTE IMMEDIATE(cur.stmt);
        EXCEPTION
        WHEN others THEN
            DBMS_OUTPUT.PUT_LINE(‘JOB NOT DISABLED ‘ || cur.job_name);
            –DBMS_OUTPUT.PUT_LINE(SQLERRM || ‘ CAUSE:’ || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
        END;
    END LOOP;
END;
/

HOW TO – find out what is using the the temp tablespace in a oracle database

 

In a 11g database we could identify the amount of temp tablespace used by running the following

SELECT *

  FROM dba_temp_free_space

 

To identify which Session and SQL that is consuming the temp, use the following SQL (for RAC)

SELECT s.sid,
       s.username,
       s.osuser,
       s.machine,
       s.program,
       u.tablespace,
       s.sql_hash_value || '/' || u.sqlhash hash_value,
       u.segtype,
       u.contents,
       u.blocks*8/1024 used_mb
  FROM gv$session s, gv$tempseg_usage u
WHERE s.saddr = u.session_addr
   AND u.inst_id = s.inst_id
DER BY used_mb DESC;

 

 


SELECT S.sid || ',' || S.serial# sid_serial, 
       S.username, 
       S.osuser, 
       P.spid, 
       S.module, 
       S.program, 
       SUM (T.blocks) * TBS.block_size / 1024 / 1024 mb_used, 
       T.tablespace, 
       COUNT (*) sort_ops 
  FROM v$sort_usage T, 
       v$session S, 
       dba_tablespaces TBS, 
       v$process P 
WHERE     T.session_addr = S.saddr 
       AND S.paddr = P.addr 
       AND T.tablespace = TBS.tablespace_name 
GROUP BY S.sid, 
       S.serial#, 
       S.username, 
       S.osuser, 
       P.spid, 
       S.module, 
       S.program, 
       TBS.block_size, 
       T.tablespace 
ORDER BY mb_used;

HOW TO- Setup your own VM instance to use instead of Cygwin for installing Oracle software on Linux

1. Download and install Oracle VM VirtualBox:

\\wa12-file1\shareddata2\Operations\DBA1 – DBA Software1 – Oracle\Oracle VM\VirtualBox-4.1.18-78361-Win.exe

OR

http://download.virtualbox.org/virtualbox/4.1.18/VirtualBox-4.1.18-78361-Win.exe

Run the installer with all default settings.

2. Download the pre-built Oracle VM instance (Oracle Developer Day), it’s 4 Gb

\\wa12-file1\shareddata2\Operations\DBA1 – DBA Software1 – Oracle\Oracle VM\Oracle_Developer_Day.ova

OR

http://download.oracle.com/otn/other/virtualbox/dd/Oracle_Developer_Day.ova

3. Import the VM instance on VirtualBox:

File > Import Appliance to launch Appliance Import Wizard.

Click Choose… to browse to the directory where the VM instance is and select the Oracle Developer Day.ova then click Next> to begin importing the virtual machine.

This will import the VM instance with its 2 disks (2x 11Gb, 11Gb used on pre-built leaving 11Gb free which will grow on your local disk as when you use within your VM instance)

Once finished, you will see ‘Oracle Developer Days (Powered Off)’

4. Before starting you need to enable networking (otherwise your VM instance will only be local and not able to access anything on the network):

Click on Oracle Developer days. Once select settting gets highlighted. Click on setting. Then click Network in VirtualBox.

Then on Adapter 1, click Enable Network Adapter and change Attached to: NAT as shown below:

image001

 

You should Adaptor 1: PCnet-FAST III (NAT) as shown below:

image002

 

5. Start your VM instance, double-click the OTN Developer Days VM.

Click OK to close the Virtualbox Information dialogs.

When you get to the Enterprise Linux 5 screen you can now login (Username and password is oracle).

Allow the process to complete; it is ready when you see a terminal window, which you can close.

Once you are finished working in the guest VM you can shut it down via System > Shut Down; this will return the guest VM to the Powered Off state.

6. To run Oracle Universal Installer on any server:

Double Click Terminal

Then Type ssh -X oracle@server

Then when you run runInstaller it will appear within the VM instance J

More info here:

https://www.virtualbox.org/

http://www.oracle.com/technetwork/community/developer-vm/index.html

http://www.oracle.com/technetwork/database/enterprise-edition/databaseappdev-vm-161299.html