Top daily usefull linux commands for DBA's
TFA command:
(a) To check whether it is installed: grep TFA_HOME = /etc/init.d/init.tfa
(b) To check the current version: tfactl version -all
(c) To check the status of TFA: tfactl print status
As the Grid Infrastructure (GI) homeowner, run the TFA collection using the following single command:
$TFA_HOME/bin/.tfactl diagcollect -from "MON/DD/2022 hh:mm:ss" -to "MON/DD/2022 hh:mm:ss"
$TFA_HOME/bin/.tfactl diagcollect -from "06/19/2023 01:00:00" -to "06/19/2023 04:00:00"
crontab format:
# * * * * * command to be executed
# - - - - -
# | | | | |
# | | | | +----- day of week (0 - 6) (sunday=0,monday-1,tue-2,wed-3,thur-4,frid-5,sat-6)
# | | | +------- month (1 - 12)
# | | +--------- day of month (1 - 31)
# | +----------- hour (0 - 23)
# +------------- min (0 - 59)
r - read
w - write
x - execute
7 = all rights
6 = read and write
5 = read and execute
4 = read only
3 = execute and write
2 = write only
1 = execute only
0 = no rights
i think this will help you to understand the permission and by adding + you give the permission and - you remove the permission
Dead process:
ps aux | egrep "Z|defunct"
To kill a PID:
kill -9 <Parent PID>
How to check OS Parameter's:
cat /proc/sys/net/ipv4/ip_local_port_range
cat /proc/sys/vm/max_map_count
cat /proc/sys/vm/min_free_kbytes
cat /proc/sys/vm/nr_hugepages
grep fs.aio-max-nr /etc/sysctl.conf
grep fs.file-max /etc/sysctl.conf
grep kernel.shmall /etc/sysctl.conf
grep kernel.shmmax /etc/sysctl.conf
grep kernel.shmmni /etc/sysctl.conf
grep kernel.sem /etc/sysctl.conf
grep net.ipv4.ip_local_port_range /etc/sysctl.conf
grep net.core.rmem_default /etc/sysctl.conf
grep net.core.rmem_max /etc/sysctl.conf
grep net.core.wmem_default /etc/sysctl.conf
grep net.core.wmem_max /etc/sysctl.conf
/sbin/sysctl vm.max_map_count
/sbin/sysctl vm.min_free_kbytes
/sbin/sysctl vm.nr_hugepages
To check the no of CPU's available:
cat /proc/cpuinfo |egrep -i "processor|cores"
lscpu
To check total memory and free memory in linux server:
# grep -i huge /proc/meminfo
cat /proc/swaps
grep Swap /proc/meminfo
# free -h
# free -g
# free -m
emptying the file : cat /dev/null > Filename
To check mount point details on the server mount with root user:
cat /proc/mounts or cat /etc/mtab or fdisk -l
To check the disk device status in Linux, you can use the lsblk command:
lsblk -f
lsblk -i
check /var/log/message for any issues at OS level
Basic vmstat Output
The basic output of the vmstat command displays system information in six sections.
1. procs – Process Statistics
r – Active process count.
b – Sleeping process count.
2. memory – Memory statistics
swpd – Total virtual memory. The swap space is initially unoccupied. However, the kernel starts using swap space as the system’s physical memory reaches its limit.
free – Total free memory.
buff – Total memory temporarily used as a data buffer.
cache – Total cache memory.
3. swap – Swap space Statistics
si – The rate of swapping-in memory from disk.
so – The rate of swapping-out memory to disk.
4. io – Input/Output Statistics
bi – Blocks received from a block device per second.
bo – Blocks sent to a block device per second.
5. system – Scheduling statistics
in – The number of system interrupts.
cs – The number of context switches per second.
6. cpu – CPU Statistics
us – The percentage of CPU time spent on non-kernel processes.
sy – The percentage of CPU time spent on kernel processes.
id – The percentage of idle CPU.
wa – The percentage of CPU time spent waiting for Input/Output.
st – The percentage of CPU time stolen by a virtual machine.
Generating CPU Report on the Fly 5 times every 2 seconds.
[root@localhost ~]# sar 2 5
Linux 3.10.0-123.el7.x86_64 (localhost.localdomain) Monday 26 October 2015 _x86_64_ (2 CPU)
01:43:55 EDT CPU %user %nice %system %iowait %steal %idle
01:43:57 EDT all 0.00 0.00 0.25 0.00 0.00 99.75
01:43:59 EDT all 0.00 0.00 0.00 0.00 0.00 100.00
01:44:01 EDT all 0.00 0.00 0.25 0.00 0.00 99.75
Note:
If the %I/O wait is more than zero for a longer period of time then we can consider there is some bottleneck in I/O system ( Hard disk or Network )
Generating Memory Usage report using -r
[root@localhost ~]# sar -r 2 5
kbcommit & %commit is the overall memory used including RAM & Swap
Generating Paging Statistics Report using -B
[root@localhost ~]# sar -B 2 5
In the report majflts/s shows the major faults per second means number of pages loaded into the memory from disk (swap), if its value is higher then we can say that system is running of RAM.
%vmeff indicates the number of pages scanned per second, if it’s vaule is 100 % its is consider OK and when it is below 30 % then there is some issue with virtual memory. Zero value indicates that there is no page scanned during that time
Command to check packets drop or packet loss
netstat --statistics --tcp.
netstat --statistics --udp
$ netstat -anus
Mailx command:
cat /tmp/awrrpt_3_91244_91246.html |mailx -s "AWR_report" shaik@TCS.com
SCP Command syntax:
scp source_file_name username@destination_host:destination_folder
To find the biggest files:
du -a /u01/app/oracle/diag/rdbms/dborcl/dborcl/trace/ | sort -n -r | head -n 20
To find and delete the files for a particular number of days:
find . -name "*.trm.gz" -mtime +15 -exec rm -rf {} \;
find . -mtime +2 -type d -exec rm -rf {} \;
find /u01/app/oracle/diag/rdbms/dborcl/dborcl/dborcl_full_*.dmp.gz -mtime +14 -type f -exec rm -f {} \;
find /u01/app/oracle/diag/rdbms/dborcl/dborcl/adump -name ".aud" -mtime +60 -exec rm {} \;
find /u01/app/base/diag/tnslsnr/hostdb/listener/alert -name \*.xml -mtime +5 -exec rm {} \;
find /u01/app/oracle/diag/rdbms/dborcl/dborcl/trace -type f -name \*.trc -mtime +7 -exec rm {} \;
find /u01/app/oracle/diag/rdbms/dborcl/dborcl/adump -type f -name \*.aud -mtime +365 -type f -exec rm -f {} \;
find /u01/app/oracle/diag/rdbms/dborcl/dborcl/*.dmp -mtime +30 -exec rm {} \;
find /u01/app/oracle/diag/rdbms/dborcl/dborcl/alert -name "*.xml" -mtime +4 -exec rm {} \;
find /u01/app/oracle/diag/rdbms/dborcl/dborcl/trace -name "*.gz" -mtime +5 -exec rm {} \;
find /opt/oracle/diag/tnslsnr/hostname/listener_dbname/alert -name "log*xml" -mtime +3 -exec rm {} \;
(or)
find . -name "*.trc" -mtime +30 -exec rm -f {} \;
cd /backup_new/oracle/dpump
find . -name "${ORACLE_SID}_schemas_backup_*.dmp" -mtime +20 -follow -exec rm {} \;
find . -name "${ORACLE_SID}_schemas_backup_*.dmp.gz" -mtime +14 -follow -exec rm {} \;
find *.trm -mtime +30 -exec rm {} \;
To search top big files under / root file system:
du -xh / |grep ‘^\S*[0-9\.]\+G’|sort -rn
du -xh /u01/app/oracle/diag/rdbms/dborcl/dborcl/trace |grep ‘^\S*[0-9\.]\+G’|sort -rn
du -a /u01/app/oracle/diag/rdbms/dborcl/dborcl/trace | sort -n -r | head -n 10
To identify the used file size (in blocks), use the command below:
lsof -Fn -Fs |grep -B1 -i deleted | grep ^s | cut -c 2- | awk '{s+=$1} END {print s}'
To sort the top 10 process utilizes more cpu excluding HEADER
ps aux |grep -v “%CPU”|sort +2nr|head -10
To check CPU utilization for processes using ps command:
ps aux |head -3
To check which process utilizes more swap space:
svmon -P|head -10
To count a particular word in a file:
grep "exported" cosi.sql | wc
systeminfo | find "Boot Time"
Paging space command:
To list the percentage usage of the paging space:
cb20qcdb1prd# lsps -s
Total Paging Space Percent Used
4096MB 29%
Compressing the file : gzip
gzip alert_ADCBPRD.log
uncompressing the file : gunzip
gunzip alert_ADCBPRD.log.gz
Date and errors in alert.log:
cat alert*log |awk 'BEGIN{buf=""}/[0-9]:[0-9][0-9]:[0-9]/{buf=$0}/ORA-/{print buf,$0}'
cat alert_envtest.log|grep ORA-00600
How to find the Date of startups in the alert.log:
cat alert_alert_dborcl.log |awk 'BEGIN{buf=""}/[0-9]:[0-9][0-9]:[0-9]/{buf=$0}/Network ORACLE/{print buf,$0}'
How to find errors from an alert log file and error details with time stamp:
grep 'ORA-' /u01/app/oracle/diag/rdbms/dborcl/dborcl/alert_dborcl.log
awk '/ORA-/ {timestamp = substr($0, 1, 23); getline; print timestamp, $0}' grep 'ORA-' /u01/app/oracle/diag/rdbms/dborcl/dborcl/alert_dborcl.log
awk '/ORA-/ {timestamp = substr($0, 1, 23); getline; print timestamp, $0}' /u01/app/oracle/diag/rdbms/dborcl/dborcl/trace/alert_dborcl.log
To export variable:
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=ALF10G
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
dbv command for block corruption issue:
dbv FILE=/data/bwmsprd/oracle/JXBUS/oradata_03/bwms_data_32k_02.dbf FEEDBACK=100
Mcafee process start and stop in linux server:
ENSLTP 10.6.6 and later including 10.7.x:
To stop the ENSLTP service, run the following commands:
# /opt/McAfee/ens/tp/init/mfetpd-control.sh stop
# /opt/McAfee/ens/esp/init/mfeespd-control.sh stop
To start the ENSLTP service, run the following commands:
# /opt/McAfee/ens/esp/init/mfeespd-control.sh start
# /opt/McAfee/ens/tp/init/mfetpd-control.sh start
To check the status of the ENSLTP service, run the following commands:
# /opt/McAfee/ens/tp/init/mfetpd-control.sh status
# /opt/McAfee/ens/esp/init/mfeespd-control.sh status
for service in $(srvctl config service -d DATABASE_NAME|awk 'BEGIN {SERVICE=""; PREF=""; OFS=";"} { if($0 ~ /Service name:/) SERVICE=$NF; if($0 ~ /Preferred instances:/) {PREF=$NF;print SERVICE,PREF}}');do
SERVICE=$(echo ${service}|cut -d ";" -f1)
INSTANCES=$(echo ${service}|cut -d ";" -f2)
RUNNINGINSTANCES=$(srvctl status service -d DATABASE_NAME -s ${SERVICE}|awk '{print $NF}')
STATUS="KO"
if [[ ${INSTANCES} == ${RUNNINGINSTANCES} ]];then
STATUS="OK"
fi
echo "$SERVICE: $STATUS (Preferred: ${INSTANCES},Running: ${RUNNINGINSTANCES})"
done;
Removing a Swap File:
1.# swapoff -v /swapfile
2.Remove its entry from the /etc/fstab file.
3.# rm -rf /swapfile
Alert log file script:
./check_oracle_logs.sh
#!/bin/bash
# Get the current time
now=$(date +"%Y-%m-%d %H:%M:%S")
# Check the database alert log file
echo "Checking database alert log file..."
if grep -i "error|ORA-" alert_<database_sid>.log; then
echo "Found errors in alert_<database_sid>.log"
mail -s "Oracle database errors" <email_address>
fi
# Check the ASM alert log file
echo "Checking ASM alert log file..."
if grep -i "error|ORA-" alert_asm.log; then
echo "Found errors in alert_asm.log"
mail -s "Oracle database errors" <email_address>
fi
# Check the listener log file
echo "Checking listener log file..."
if grep -i "error|ORA-" listener.log; then
echo "Found errors in listener.log"
mail -s "Oracle database errors" <email_address>
fi
# Check the operating system level
echo "Checking operating system level..."
if top -bn1 | grep "load average" | awk '{print $11}' > 1; then
echo "Found high CPU load"
mail -s "High CPU load" <email_address>
fi
if free | awk '{print $7}' > 1; then
echo "Found low memory"
mail -s "Low memory" <email_address>
fi
if df -h | grep "100%" > 1; then
echo "Found low disk space"
mail -s "Low disk space" <email_address>
fi
Download Linux from the below link
Enjoy the work and do like me if you like this article!!!