Thursday, July 24, 2008

How to: Linux/UNIX Delete or Remove Files With Inode Number

Sometime accidently, we create file with special character and its hard to remove file using rm command.

  • Find out the inode number coressponding to file name (:q)

    $ ls -il :q

    52155 -rw-rw-r-- 1 oracle dba 2310 Jul 24 14:52 :q
  • Use find command to remove file:
    find . -inum 52155 -exec rm -i {} \;

Wednesday, July 23, 2008

Blog Tips

Blog Tips

If you have noticed by now, the codes are wrapped in the lesser than (<) and greater than (>) signs. The moment these are posted, they will be interpreted as codes and will trigger an action by the browser. Should you want to display these as part of the text, use their character entities instead.

"&quot;
&&amp;
<&lt;
>&gt;


Monday, July 21, 2008

Hiding Passwords From UNIX ps Command

Hiding Passwords From UNIX ps Command

When running an sql script from unix OS, the unix ps (process status) command will show the Oracle userid and password of the sqlplus session.

To get around this problem, you should consider using pipe in script to pass the the password into sqlplus Below are examples of piping in the password (userid system, password systempw) for sqlplus, import, and export.

$ echo system_password sqlplus -s system @MYSCRIPT
$ echo system_password imp system file=myfile.dmp tables=mytable
$ echo system_password exp system file=myfile.dmp tables=mytable

Alternatively, run the following commands:

$ sqlplus <<EOF
SYSTEM/system_password
SELECT ...
EXIT
EOF

alert file location in 11g

alert file location in 11g

Starting from 11g all the diagnostic data (traces, dumps, the alert log) will go under Automatic Diagnostic Repository.

ADR home would be in the following location:

ADR_BASE/diag/product_type/product_id/instance_id

where

product_type --> rdbms
product_id --> database name (my database name t801)
instance_id --> SID (my instance name t801)

ADR Home Subdirectories:











So Alert file location will be under following directory:

ADR_BASE/diag/rdbms/t801/t801/alert

If the ORACLE_BASE=/u01/app/oracle then alert file location would be:

/u01/app/oracle/diag/rdbms/t801/t801/alert

DIAGNOSTIC_DEST initialization parameter location would be:

DIAGNOSTIC_DEST=/u01/app/oracle/

For more detail, read Oracle Documentation:

Friday, July 18, 2008

Find processor information from different UNIX flavor

Find processor information from different UNIX flavor

  • On HP-UX
  • You can use the info from the 'model' command to get the processor type (PA-RISC or Itanium) like so:

    Unix1$ grep -i $(model cut -d"/" -f3) /usr/sam/lib/mo/sched.models

    which tells us that the box has a PA8700 processor type (PA-RISC)

    To get the speed, you can do:
    Unix1$ echo 'itick_per_usec/D' adb /stand/vmunix /dev/kmem grep itick_per_usectail -1

    which tells us it's a 750MHz processor

    To get whether the kernel is running in 32 or 64bit mode you can do:
    (Unix1:oracle)# getconf KERNEL_BITS
    64
    which says 64bit mod

Find physical memory on Unix/Linux systems

HP-UX:Find physical memory
For your really real physical ram try this:
#echo "selclass qualifier memory;info;wait;infolog"|cstm

The above command will show you how many memory slot and physical memory that plug in that slots in MB format.

#dmesg|grep Phy, this ouput will show yor memory in KB format

But I trust the first command that come from cstm is more valid.

Thursday, July 17, 2008

AWR manual snapshot

AWR manual snapshot

To do stress testing or troubleshooting performace related issue, you can use manual AWR snapshot.

AWR manual snapshot:

EXEC DBMS_WORKLOAD_REPOSITORY.create_snapshot;

Friday, July 11, 2008

Using Putty PSCP and PSFTP on Windows

Using Putty PSCP and PSFTP on Windows
  • Using PSCP on Windows


  • C:\> cd "C:\Program Files\PuTTY"

    C:\Program Files\PuTTY> pscp -h # -h gives a short help listing
    ...short help listing displays here...

    C:\Program Files\PuTTY> pscp -P 2003 -l alleni99 \
    net2003.idallen.ca:.bashrc foo.txt
    ...you may be asked to accept the host key here (say yes)...
    alleni99@net2003.idallen.ca's password:
    ...file transfers ".bashrc" to "foo.txt" in the current directory...

    Remember to use the -P option and use -l to set your own userid.

  • Using PSFTP on Windows


C:\> cd "C:\Program Files\PuTTY"

C:\Program Files\PuTTY> psftp -h # -h gives a short help listing
...short help listing displays here...

C:\Program Files\PuTTY> psftp -P 2003 -l alleni99 net2003.idallen.ca
...you may be asked to accept the host key here (say yes)...
alleni99@net2003.idallen.ca's password:
Remote working directory is /home/alleni99
psftp> help
...short help listing displays here...
psftp> ls
...listing of directory displays here...
psftp> get .bashrc foo.txt
remote:/home/alleni99.bashrc => local:foo.txt
psftp> quit
...file "foo.txt" is now in the current directory...

Remember to use the -P option and use -l to set your own userid when
using the PuTTY version of PSFTP.

Note that the options to the PuTTY Windows version of SFTP (named
PSFTP) are not the same as the options to the Unix/Linux version
of SFTP. In particular, the option "-P" has different meanings!



################################### My examples ##########################################################



************* windows:-**********************
From desktop to TESTNET database server:
pscp -P 2222 -l oracle swingbench230376.zip localhost:swingbench230376.zip

pscp -P 2222 -l oracle jre-6u7-solaris-sparc.sh localhost:jre-6u7-solaris-sparc.sh

pscp -P 2222 -l oracle jre-6u7-solaris-sparcv9.sh localhost:jre-6u7-solaris-sparcv9.sh

From TESTNET database server to desktop:
pscp -P 2222 -l oracle localhost:trap_test.ksh trap_test.ksh


C:\Program Files\Putty>pscp -P 2222 -l oracle swingbench230376.zip localhost:swingbench230376.zip
Using keyboard-interactive authentication.
Password:
swingbench230376.zip | 9005 kB | 1500.9 kB/s | ETA: 00:00:00 | 100%



If tunnel not setup correctly then we will get following message:

C:\Program Files\PuTTY>pscp -P 2222 -l oracle swingbench230376.zip localhost:swingbench230376.zip
Fatal: Network error: Connection refused


Thursday, July 10, 2008

Understanding Unix AWK

Understanding Unix AWK

awk is field-oriented and ideal for manipulating database or comma-delimited files
  1. awk '{ print $1 }' address_book
  2. awk -F, '{ print $1 }' address_book
  3. awk -F, '{ print $1 " " $2 " " $8 }' address_book > address_book.bck
  4. awk -F, '/KARAM/{ print $1 " " $2 " " $8 }' address_book > address_book.bck

Understanding Unix ENVIRONMENT

Understanding Unix ENVIRONMENT while logging.

When you login to UNIX environment, keep in mind that following configuratin files are generally run in a specified order.

  • Systemwide configuration files (such as /etc/profile) run first upon login if they exist.
  • Configuration files specific to your unix account run next if they are available (such as ~/.profile and ~/.kshrc)
  • It means that personal configuration files override the system one

Wednesday, July 9, 2008

Duplicate Database on a different server using RMAN dulplicate

Duplicate Database on a different server using RMAN dulplicate.


  1. copy the backup of RMAN back to standby server(new server). Backup Directory structure should same as on Primary side.

  2. Lets assume, password file already created on primary database. So Make sure that we can make connetion as sys user from new server.
  3. Make sure that db_file_name_convert and log_file_name_convert parameter are set correctly on new AUXILIARY database.
  4. Start the new AUXILIARY database in NOMOUNT state.
    unix$ sqlplus / as sysdba
    SQLPLUS> startup nomount

  5. Start RMAN from AUX side and Connect to rman catalog
    unix$ rman
    RMAN> rman/rman1@primcatalog

  6. Connect target(primary) database using sys user
    RMAN> sys/password@primary_db


    1. RMAN> duplicate target database to AUX.
    2. RMAN> duplicate target database to AUX.

Friday, July 4, 2008

Recovery from Complete Loss (No Controlfile)

Recovery from complete loss (no control file and no pfile or spfile)


  1. find out DBID of lost database. This can done by checking control file autobackup location.

  2. $ export ORACLE_SID=TEST

  3. $ sqlplus / as sysdba
  4. SQL> startup force nomount
  5. Restore spfile
    $rman
    rman> set dbid=4885937635
    rman> connect catalog
    rman/rman@dbcatalog
    rman> restore spfile from autobackup;
    rman> shutdown immediate;
    rman> startup nomount

  6. Restore the control file and mount database from restored control file.
    rman> restore controlfile from autobackup;
    rman> alter database mount;
  7. Restore the datafile and perform media recovery.
    rman> restore database;
    rman> recover database;
    rman> alter database open resetlogs;

Tuesday, July 1, 2008

Making SQLPLUS connection to remote database

Making SQLPLUS connection to remote database:

  1. sqlplus system/manager@test.gdbsi.com using connect string
  2. sqlplus system/manager@//hostname:portname/dbname
  3. sqlplus system/manager@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SID=TEST)))

Drop Oracle Database Manually

Drop Oracle Database Manually:

  1. $export ORACLE_SID=TEST
  2. Connect to SQL*Plus as "/ as SYSDBA" privilege
  3. SQL> startup force mount
  4. SQL> alter system enable RESTRICTED session;
  5. SQL> drop database;

Import Multiple dump files using Data Pump

To import multiple dump files using Data Pump, use substitution variable (%u).

For example:

impdp / DIRECTORY=pump_dir LOGFILE=parallel_import.log DUMPFILE=par_exp%u.dmp PARALLEL=2 TABLE_EXISTS_ACTION=REPLACE

TABLE_EXISTS_ACTION={SKIP APPEND TRUNCATE REPLACE}
The possible values have the following effects:
  • SKIP leaves the table as is and moves on to the next object. This is not a valid option if the CONTENT parameter is set to DATA_ONLY.
  • APPEND loads rows from the source and leaves existing rows unchanged.
  • TRUNCATE deletes existing rows and then loads rows from the source.
  • REPLACE drops the existing table and then creates and loads it from the source. This is not a valid option if the CONTENT parameter is set to DATA_ONLY.
Create Update trigger on stream heatbeat table to test HEAVY insert/update activiry.

CREATE OR REPLACE TRIGGER KARAM.UPDATE_AFTER_EACH_ROW
AFTER UPDATE
OF STM_UDT_TS
ON KARAM.TDM_STRMHB FOR EACH ROW
DECLARE
v_out_file UTL_FILE.FILE_TYPE;
begin
v_out_file := UTL_FILE.FOPEN('STRMADMIN_DIR','heart_beat.log', 'A');
UTL_FILE.PUT_LINE (v_out_file, 'Updated on ' to_char(sysdate,'mm-dd-YYYY HH24:MI:SS'));
UTL_FILE.FCLOSE(v_out_file);
EXCEPTION
WHEN OTHERS THEN NULL;
end update_after_each_row;
/
ALTER TRIGGER KARAM.UPDATE_AFTER_EACH_ROW ENABLE;

Also trigger will get fire only if following executed:

SQLPLUS> beginDBMS_DDL.SET_TRIGGER_FIRING_PROPERTY('TEST_SCHEMA','UPDATE_AFTER_EACH_ROW',FALSE);end;/