Thursday, March 19, 2009

Window Backup Deletion script will delete when Database is open only

test.sql=
spool test.txt
set head off
set term off
set feed off
select status from v$instance;
spool off
exit
=
test.bat=
sqlplus /********@DBNAME @test.sql
TIMEOUT 4
IF EXIST test.txt (
FOR /F " skip=1 delims== " %%i in (test.txt) do (set t1=%%i)
del test.txt
SET DIRPATH=I:\TEST_BACKUP
) ELSE (exit)
IF %t1% EQU OPEN (
I:
cd %DIRPATH%
del DB_NAME_export_old.dmp
del DB_NAME_export_old.log
rename DB_NAME_export.dmp DB_NAME_export_old.dmp
rename DB_NAME_export.log DB_NAME_export_old.log
exp /********@DBNAME file=%DIRPATH%\DB_NAME_export.dmp log=%DIRPATH%\DB_NAME_export.log owner=ABC
)
=

Monday, February 9, 2009

Spfile & pfile lost : How to recreate this

1) show spfile will give if you started with a spfile or a init.ora file. You can't know which init.ora was used.

2) Here's a script:

Set linesize 1000
Set feedback off
Set pagesize 0
Col instance_name noprint new_value inst_
Set termout off
Select instance_name from v$instance;
Set termout on
Spool init&inst_..ora
select '
'||'######################################################################
'||'#
'||'# file : init&inst_..ora
'||'# date : '||to_char(sysdate,'DD/MM/YYYY HH24:MI:SS')||'
'||'#
'||'######################################################################
'||'
' from dual
/
Select '# '||name||': '||description||'
'||decode(update_comment,NULL,'','# '||update_comment||'
')||name||' = '||decode(sign(instr(value,' ')),
1,'("'||replace(value,', ','", "')||'")',
value)||'
'||'
'
from v$system_parameter
where isdefault = 'FALSE'
order by name
/
Spool off

Wednesday, February 4, 2009

Audit Trail

Auidt trail details from drop any table .
and
Audit table;
http://www.dbasupport.com/forums/showthread.php?t=20054

Tuesday, January 27, 2009

Oracle Instalation On Linux

Configure the kernel.
Edit /etc/sysctl.conf.
Add the following to the file:
# Kernel parameters required by Oracle 11gR1 / 10g

fs.file-max = 6553600
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 262144
************************************************************************
sysctl -p
************************************************************************
Edit /etc/security/limits.conf
Add these lines:

oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536

************************************************************************
Edit /etc/pam.d/login

Add these lines:

session required /lib/security/pam_limits.so
session required pam_limits.so
************************************************************************
Edit /etc/profile

Add these lines:

if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
************************************************************************
groupadd oinstall
groupadd dba
groupadd oper
useradd oracle
usermod -g oinstall -G dba,oper,oracle oracle
passwd oracle
*************************************************************************

Edit /home/oracle/.bash_profile

Add these lines:

umask 022
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.1.0/db_1
ORACLE_SID=orcl
PATH=$ORACLE_HOME/bin:$PATH
export PATH
export ORACLE_BASE ORACLE_HOME ORACLE_SID
************************************************************************
mkdir -p /u01/app
chown root:oinstall /u01/app
chmod 775 /u01/app
************************************************************************

Tuesday, January 13, 2009

Sample Control file + sqlldr

SQLLDR USERID=account_data/account_data@test CONTROL=D:\share\vivek\test.CTL ERRORS=5000 log=d:\abc.log

test.CTL=
load data
infile 'data_daily1.csv'
infile 'data_daily2.csv'
infile 'data_daily3.csv'
append
into table daily_upload
fields terminated by ","
optionally enclosed by '"'
trailing nullcols
(
col1,
col2,
col3,
col4,
col5
)

Tuesday, October 14, 2008

How Much time recovery after Killing the Long Running Session will take

select state,undoblocksdone,undoblockstotal,undoblocksdone / undoblockstotal * 100
from v$fast_start_transactions;
************************
The FAST_START_PARALLEL_ROLLBACK parameter controls how much juice SMON will take. The three possible parameters are: FALSE, LOW, and HIGH. A setting of FALSE will tell SMON to do the recovery on its own without parallel assistance. This could work to allow your app to remain online while SMON does its job, but could still cause contention issues. In the end, it is better to let SMON finish the work while other processes try to lay off UNDO as much as possible. A setting of LOW will tell SMON to use 2 * CPU_COUNT parallel processes to do the work, and a setting of high will use 4 * CPU_COUNT. In order to allow SMON to finish its work as quickly as possible, we turned off their app and set the FAST_START_PARALLEL_ROLLBACK parameter to HIGH, allowing SMON all the resources it needed to finish. To determine how long it would take to finish, we consulted the V$FAST_START_TRANSACTIONS view

Tuesday, October 7, 2008

Delete duplicate row from table

delete from TABLE_NAME where rowid in (select min(rowid) from TABLE_NAME group by (empid, LOCATION) having count(empid)>1 );