Search This Blog

Friday, February 21, 2014

RMAN: Restore controlfiles


Sometimes, your loose all your controlfiles, your instance is down, and you think you're in a big sh**. But here's a solution.


Check your last controlfile backup to get your DBID :
ls -l *.bck
-rw-rw---- 1 oracle oracle   10092544 Apr 15 15:49 c-159519437-20110415-06.bck

The DBID is the first number block : 159519437


Then, go to RMAN and restore your controlfile from the last backup:

rman target /

set DBID=159519437

startup nomount

set controlfile autobackup format for device type disk to '/backup/file/location/%F';

restore controlfile from autobackup;


The last action, recover and start the database

recover database;

alter database open resetlogs;

Tuesday, February 4, 2014

Linux: Generate a random password

The main script, has to be saved in a separate file, or modified as a function:
#!/bin/bash

#add special characters you want to use in the password here:
charspool=('a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p'
'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y' 'z' '0' '1' '2' '3' '4' '5' '6' '7'
'8' '9' '0' 'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O'
'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z' '$' '-' '_');

len=${#charspool[*]} if [ $# -lt 1 ]; then         num=$1; else         num=$1; fi randomnumbers=$(head -c $num /dev/urandom | od -t u1 | awk '{for (i = 2; i <= NF; i++) print $i}') for c in $randomnumbers; do         echo -n ${charspool[$((c % len))]} done echo

and to call it:
lenPassword=8
# echo $(/path/to/script/gen_password.sh $lenPassword);

Wednesday, January 29, 2014

Linux: Allow a user to execute only specific root command(s)

Sometimes you want a linux user to be able to execute root command(s). To do so, you need to modify the /etc/sudoers file (with visudo).

However, almost everyone add a line like the below:
username ALL=(ALL:ALL) ALL


Which is far from being the right thing to do. You basically just gave the user username all root rights... To do it properly, you should know the synopsis of that line:
user machine=(effective user [ : effective group ] command


With:
user : the user you want to grant access to some commands. it can be a group too, just replace user by %groupname
machine : the machine you want those rights to apply (can be a hostname, IP, ALL)
effective user : the user's rights you want your user to execute the command as (root, user1, ALL, etc)
effective group : same as above, but for the group. This is not mandatory
command : the command or command list (separated by comma. Ex. /bin/chown,reboot)

An example is allays better than a long talk, if you want to give the user user1 the rights to execute the chown command:
user1 ALL=(root) /bin/chown

Monday, January 27, 2014

Oracle DB ratios explained

Here you will find two pdf (in french and english) with the explanation of the following ratios, and what to do to improve them, as well as your database performances:

  • Buffer Cache Hit Ratio 
  • Chained Row Ratio 
  • Database CPU Time Ratio
  • Database Wait Time Ratio
  • Dictionary Cache Hit Ratio 
  • Execute to Parse Ratio 
  • Get Hit Ratio 
  • Latch Hit Ratio 
  • Library Cache Hit Ratio 
  • Parse CPU to Elapsed Ratio 
  • Pin Hit Ratio 
  • Soft-Parse Ratio 
  • Library cache reload Ratio
  • Rollback Segment Wait to Get Ratio
  • In (PGA) Memory Sort Ratio
  • Buffer Nowait Ratio
  • Redo Nowait Ratio

In french

You can hit the gv$sysmetric view to most of those ratios.