Saturday, November 28, 2009

SQL Tuning Advisor - The commands

Using Enterprise Manager or dbconsole is the convenient way for using SQL Advisor, the problem is that these options not always exists, and there are some scenarios that you are not authorized to activate dbconsole.
So we are left with the PL/SQL option which appears to be not so complicated.
In order to access the SQL tuning advisor API, a user must be granted the ADVISOR privilege:

CONN sys/password AS SYSDBA
GRANT ADVISOR TO my_user;
CONN my_user/my_password


Creating tuning task
DECLARE
l_sql VARCHAR2(3200);
l_sql_tune_task_id VARCHAR2(100);
BEGIN
l_sql := 'SELECT COUNT (*) FROM MY_TABLE';

l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
sql_text => l_sql,
scope => DBMS_SQLTUNE.scope_comprehensive,
time_limit => 360,
task_name => 'Yossi_Nixon_tuning_task1',
description => 'Tuning task for sql');
DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
END;
/

Running the tuning task
EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => 'Yossi_Nixon_tuning_task1');

Tracking after the tuning task
SELECT * FROM dba_advisor_log
WHERE task_name ='Yossi_Nixon_tuning_task1';

Checking the recommendations of the advisor after the task is completed;
SET LONG 10000;
SET PAGESIZE 1000
SET LINESIZE 200
SELECT DBMS_SQLTUNE.report_tuning_task('Yossi_Nixon_tuning_task1') AS recommendations FROM dual;

When You done, you can delete the task
BEGIN
DBMS_SQLTUNE.drop_tuning_task (task_name => 'Yossi_Nixon_tuning_task1');
END;
/

Other ways to add new tuning task
1. Tuning task created for specific a statement from the AWR.
SET SERVEROUTPUT ON
DECLARE
l_sql_tune_task_id VARCHAR2(100);
BEGIN
l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
begin_snap => 764,
end_snap => 938,
sql_id => '19v5guvsgcd1v',
scope => DBMS_SQLTUNE.scope_comprehensive,
time_limit => 60,
task_name => '19v5guvsgcd1v_AWR_tuning_task',
description => 'Tuning task for statement 19v5guvsgcd1v in AWR.');
DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
END;
/

2. Tuning task created for specific a statement from the cursor cache.
DECLARE
l_sql_tune_task_id VARCHAR2(100);
BEGIN
l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
sql_id => '19v5guvsgcd1v',
scope => DBMS_SQLTUNE.scope_comprehensive,
time_limit => 60,
task_name => '19v5guvsgcd1v_tuning_task',
description => 'Tuning task for statement 19v5guvsgcd1v.');
DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
END;
/

3. Tuning task created from an SQL tuning set.
DECLARE
l_sql_tune_task_id VARCHAR2(100);
BEGIN
l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
sqlset_name => 'test_sql_tuning_set',
scope => DBMS_SQLTUNE.scope_comprehensive,
time_limit => 60,
task_name => 'sqlset_tuning_task',
description => 'Tuning task for an SQL tuning set.');
DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
END;
/

If the TASK_NAME parameter is specified, its value is returned as the SQL tune task identifier. If omitted, a system generated name such as "TASK_1478" is returned. If the SCOPE parameter is set to scope_limited the SQL profiling analysis is omitted. The TIME_LIMIT parameter simply restricts the time the optimizer can spend compiling the recommendations.
During the execution phase, you may wish to pause and restart the task, cancel it or reset the task to allow it to be re-executed:

Interrupt and resume a tuning task.
EXEC DBMS_SQLTUNE.interrupt_tuning_task (task_name => 'emp_dept_tuning_task');
EXEC DBMS_SQLTUNE.resume_tuning_task (task_name => 'emp_dept_tuning_task');

Cancel a tuning task.
EXEC DBMS_SQLTUNE.cancel_tuning_task (task_name => 'emp_dept_tuning_task');

Reset a tuning task allowing it to be re-executed.
EXEC DBMS_SQLTUNE.reset_tuning_task (task_name => 'emp_dept_tuning_task');

The status of the tuning task can be monitored using the DBA_ADVISOR_LOG view:

SELECT task_name, status FROM dba_advisor_log WHERE owner = 'SCOTT';

TASK_NAME STATUS
------------------------------ -----------
emp_dept_tuning_task COMPLETED

1 row selected.

Thursday, November 05, 2009

Silent Installation

Some times there are problems using installation with GUI, the reason can be:
1. Firewall
2. Unix security
3. Client software (missing or not working(
and maybe some more reasons
If your environment is cooperative helping you solve this - it is simple - go for it.
But if you are on your own and can't reach "the right guys" - do it yourself "Silently"
Look for the proper response file fits for your needs in /database/response/

Edit it and run the following command:

$ ./runInstaller -force -invPtrLoc /oraInst.loc -silent -noconfig -ignoreSysPrereqs -responseFile /database/response/enterprise.rsp

You can also run the installer without a response file as mentioned in Metalink Note 782918.1

$ ./runInstaller -silent -force -debug \
FROM_LOCATION="/mount/dvd/database/stage/products.xml" \
ORACLE_HOME="/u01/app/oracle/product/11.1.0/db_1" \
ORACLE_HOME_NAME="Ora11gDb1" ORACLE_BASE="/u01/app/oracle" \
TOPLEVEL_COMPONENT='{"oracle.server","11.1.0.6.0"}' \
INSTALL_TYPE="EE" n_configurationOption=3

Good luck

RDA - Health Check (HCVE)

I noticed that many DBAs are not aware of the need to run a prerequisite system check before installation of an oracle product.
This special check should be done in addition to the installation document and the check inside the installer.
The utility called RDA with a module for Health Check called HCVE.
It is well documented for RAC but can be used for simple installation.
RDA is maintained frequently and adjusted to the OS version against the oracle software.
You can read about it in Metalink Doc ID: 250262.1
"RDA - Health Check / Validation Engine Guide"

Sample

./rda.sh -T hcve

Processing HCVE tests ...
Available Pre-Installation Rule Sets:
1. Oracle Database 10g R1 (10.1.0) PreInstall (AIX)
2. Oracle Database 10g R2 (10.2.0) PreInstall (AIX)
3. Oracle Database 11g R1 (11.1.0) PreInstall (AIX)
4. Oracle Application Server 10g (9.0.4) PreInstall (AIX)
5. Oracle Fusion Middleware 11g R1 (11.1.1) PreInstall (AIX)
6. Oracle Portal PreInstall (Generic)
Available Post-Installation Rule Sets:
7. Oracle Portal PostInstall (generic)
8. Data Guard PostInstall (Generic)
.
.
.

Test Results
~~~~~~~~~~~~

ID NAME RESULT VALUE
====== ==================== ======= ==========================================
A00010 OS Certified? PASSED Certified with Oracle Database 11g R1
A00020 User in /etc/passwd? PASSED userOK
A00040 Group in /etc/group? PASSED GroupOK
A00050 Input ORACLE_HOME RECORD /products/oracle/version/ora11g1
A00060 ORACLE_HOME Valid? PASSED OHexists
A00070 O_H Permissions OK? PASSED CorrectPerms
A00080 oraInventory Permiss PASSED oraInventoryOK
A00090 Got ld,nm,ar,make? FAILED MakeFoundInPath
A00100 Umask Set to 022? FAILED UmaskNotOK
A00110 ulimits OK? FAILED DataTooSmall StackTooSmall
A00140 LDLIBRARYPATH Unset? FAILED IsSet
A00160 LIBPATH Unset? FAILED IsSet
A00190 JDK Home RECORD /products/oracle/version/ora11g1/jdk
A00200 JDK Version FAILED JDK home is missing
A00210 Other O_Hs in PATH? FAILED OratabEntryInPath
A00220 Other OUI Up? PASSED NoOtherOUI
A00230 /tmp Adequate? PASSED TempSpaceOK
A00240 Disk Space OK? PASSED DiskSpaceOK
A00250 Swap (in MB) RECORD 24448
A00260 RAM (in MB) PASSED 32768
A00270 SwapToRAM OK? FAILED SwapLessThanRAM
A00290 IP Address RECORD ***.**.*.**
A00300 Domain Name RECORD *****.*****.co.il
A00310 DNS Lookup PASSED Host correctly registered in DNS
A00320 /etc/hosts Format FAILED Missing host.domain
A00340 AIXTHREAD_SCOPE=S? FAILED AIXTHREADNotSet
A00350 LINK_CNTRL is Unset? PASSED LINK_CNTRLunset
A00410 Got OS Patches? PASSED PatchesFound
A00430 Got OS Packages? PASSED All required OS packages are installed
Result file: /products/oracle/version/INSTALL11/rda/output/RDA_HCVE_A200DB11R1_aix_res.htm

Monday, August 24, 2009

Importing just 1 view via impdp

Hi,
Struggling the right syntax in Unix environment for importing a lost view, here is the proper way:

impdp user/password@database directory=dir_dump dumpfile=dump.dmp logfile=imp_MY_VIEW.log INCLUDE=VIEW:\"= \'MY_VIEW\'\" job_name=imp_MY_VIEW

Tuesday, May 12, 2009

RMAN-06059: expected archived log not found

while running archivelog backup and the file is missing:

RMAN-06059: expected archived log not found, lost of archived log compromises recoverability


trying to fix it by crosscheck:
run {
allocate channel c1 type disk ;
crosscheck archivelog all ;
release channel c1 ;
}

validation succeeded for archived log
archive log filename=D:REDOARCHARCH_1038.DBF recid=1017 stamp=611103638


still need to run:
allocate channel for maintenance type disk;
crosscheck archivelog all;
release channel;

Sunday, April 05, 2009

ASM instance: ORA-15032 and ORA-15063 errors occur after restart of the Host

We already had the same symptom of ORA-15032 & ORA-15063 mentioned in my last post. Trying to follow these instructions didn't help this time.

ls -l /dev/oracleasm/disks/*
rpm -qa | grep oracleasm
kfod asm_diskstring='ORCL:*' disks=all
/etc/sysconfig/oracleasm conatin ORACLEASM_SCANORDER=dm
spfile has: asm_diskstring = /dev/dm*

All of these command worked fine. Beacause of the dm* parameter I checked the filesystem:

$ ls -l /dev/dm-*
/bin/ls: /dev/dm-*: No such file or directory

It seems that the dm* devices are missing and must be there for ASM by Note 602952.1 :
NOTE: When scanning, only the device names known by the kernel are scanned. With device-mapper, the kernel sees the devices as /dev/dm-XX. The /dev/mapper/XXX names are created by udev for human readability. Any configuration of ORACLEASM_SCANORDER or ORACLEASM_SCANEXCLUDE must use the dm prefix.

Since this Host is RedHat 5, we found the source of the problem by Note 558596.1:
Cause: The oracleasm scans /proc/partitions and expects devices to be available in /dev. If the device doesn't exist in /dev it will fail to open the device. RHEL/OEL5 does not create dm-xx devices in /dev by default.
Solution: Please comment out the following line in file /etc/udev/rules.d/50-udev.rules
#KERNEL=="dm-[0-9]*", ACTION=="add", OPTIONS+="ignore_device"
reboot and the problem should be gone.
Note: Newer versions of EL/RH 5 the udev rule has been moved to "/etc/udev/rules.d/90-dm.rules".

Monday, March 23, 2009

Recovering cloned database while datafile was added

We are cloning our primary production database to a test system periodically. Sometimes it happens that we are adding a datafile to the primary database while the copy is in progress. After the copy we are creating a new control file based on the production ( with the new datafile ), trying to recover the cloned database we are getting the following error (from the alert.log):

SQL> alter database recover automatic until time '2009-03-15 16:00:00' using backup controlfile;
File #114 added to control file as 'UNNAMED00114'. Originally created as:
'/bzq1/oracalls_2009_indx1/q109_icalls_ts_05.dbf'
Errors with log /bilpre/oraarch/bzq1_1_0000048990_561428818.arc
Some recovered datafiles maybe left media fuzzy
Media recovery may continue but open resetlogs may fail
Media Recovery failed with error 1244
ORA-283 signalled during: alter database recover automatic until time '2009-03-15 16:00:00' using backup controlfile...

It seems that in the archive log there is data regarding to the new datafile, so we need to create it also in the cloned database. To find out what is the current full location that is written in the cloned database:
SQL> select name from v$datafile where name like '%UNNAMED00114%';
NAME
-------------------------------
/software/oracle/BILPRE10gR2/dbs/UNNAMED00114

Now we have the information for the following command :
SQL> alter database create datafile '/software/oracle/BILPRE10gR2/dbs/UNNAMED00114' as '/bilpre/oracalls_2009_indx1/q109_icalls_ts_05.dbf'
Database altered.
SQL> alter database recover automatic until time '2009-03-15 16:00:00' using backup controlfile;
Media Recovery Complete (bilpre)
SQL> alter database open resetlogs;

The Database is working, and there is no need to copy it again

Tuesday, January 20, 2009

glogin.sql,in 10g

In Oracle 10g, the glogin.sql and login.sql are run whenever you connect to a new user.

This is the glogin.sql additions that I am using in 10g:

set verify off termout off head off feed off

col login_prompt new_value welcome

SELECT upper(SYS_CONTEXT('USERENV','SERVER_HOST')
||' '
|| SYS_CONTEXT('USERENV','CURRENT_USER')
||'@'
|| SYS_CONTEXT('USERENV','DB_NAME')) login_prompt
FROM DUAL
;


set sqlprompt "_user'@'_connect_identifier> "

set verify on termout on head on feed on
prompt ************************************
prompt WELCOME TO &&welcome
prompt ************************************
prompt
set echo off serveroutput on size 100000 line 100 trims on