Flush Linux Buffer Cache

Cache is used to keep data to use frequently by operating system,  But sometimes memory is getting low linux provide some memory Command line to monitor Memory status Check the below link :-

1- Linux Check Memory Usage Here.
2- 18 Command Line Tools to Monitor Linux Performance here.

There are options available to flush cache of linux memeory :-

Flush everything ( Pagecache, dentries and inodes )  :-

 sync; echo 3 > /proc/sys/vm/drop_caches.

Flash dentries and inodes :-

 sync; echo 2 > /proc/sys/vm/drop_caches

Flash PageCache only

sync; echo 1 > /proc/sys/vm/drop_caches

All the command should be Run As root.

Schudle the above command as job using crontab , choose from the above command what you need :-

0  *  *  *  *  /root/memory.sh

Memorysh –> should be contain one the above script run as root.

Thank you
Osama mustafa

 

Useful Linux Commands For DBA

Show Routing Table :
 
netstat -r

Check ORA errors in the Logs:

grep ^ORA- *log |cut -f2 -d"-"|cut -f1 -d:|awk '{print "ORA-" $1}'|sort -u
Inzip CPIO Files :
 
cpio -idmv < 

 Sort Files By Size :

ls -l |sort -k 5

Find Command archive and move to another Folder :

find ./ -name "*.arch" -mtime +1 -exec mv {} /u01/;

Find Command archive and Remove it:

find ./ -name "*.ARC" -mtime +1 -exec rm {} \;

Find Command with Zip :

find ./ -name "*.ARC" -mtime +1 -exec gzip {} \;

 Find Command With List :


 find ./ -name “*.ARC” -mtime +1 -ls 

Thank you
Osama Mustafa

Check memory On Linux

Sometime you as DBA you need to check your memory On Operating System Level, i will give you some command will useful to you :

1-free -m / free -g

m : megabytes
g : gigabytes

              total    used     free   shared  buffers   cached 
Mem: 503 451 52 0 14 293
-/+ buffers/cache: 143 360
Swap: 1027 0 1027

 another example :

free -t -m
       total       used       free     shared    buffers     cached
Mem: 750 625 125 0 35 335
-/+ buffers/cache: 253 496
Swap: 956 0 956
Total: 1707 625 1082
2-vmstat

procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
1 0 0 131620 35432 341496 0 0 42 82 737 1364 15 3 81 1
 
 
 
 
3-top 
 
 
 

4-gnome-system-monitor
 
 
 
The below Command for clear cache memory in linux 

sync; 
echo 3 > /proc/sys/vm/drop_caches
 you can make it as job in linux save in it crontab 
0 * * * * /root/clearcache.sh
 
Create a file in '/root' called 'clearcache.sh' with the following content:

#!/bin/sh  
sync; echo 3 > /proc/sys/vm/drop_caches
 
  
Thank you 
osama mustafa 

Backup an entire hard disk using dd command

The ‘ dd ‘ command is one of the original Unix utilities and should be in everyone’s tool box. It can strip headers, extract parts of binary files and write into the middle of floppy disks; it is used by the Linux kernel Makefiles to make boot images. It can be used to copy and convert magnetic tape formats, convert between ASCII and EBCDIC, swap bytes, and force to upper and lowercase. 

# dd –help

full hard disk copy

dd if=/dev/hdx of=/dev/hdy
dd if=/dev/hdx of=/path/to/image
dd if=/dev/hdx | gzip > /path/to/image.gz

Hdx could be hda, hdb etc. In the second example gzip is used to compress the image if it is really just a backup.  



Restore Backup of hard disk copy

dd if=/path/to/image of=/dev/hdx

gzip -dc /path/to/image.gz | dd of=/dev/hdx  




MBR backup

In order to backup only the first few bytes containing the MBR and the partition table you can use dd as well.

dd if=/dev/hdx of=/path/to/image count=1 bs=512 



MBR restore

dd if=/path/to/image of=/dev/hdx

Add “count=1 bs=446” to exclude the partition table from being written to disk. You can manually restore the table.

 “All This Information was taken from the other site , just for information to take hard-disk backup , it will be useful to use it with Oracle ”

thank you 
Osama mustafa