Senior DBA Interview Questions
Senior DBA Interview Questions
Here I
have collected some common Interviews questions asked to a DBA relating to Unix
environment. These questions are mostly asked for senior Oracle DBA positions.
I have compiled these questions based upon the feedback I got from many candidat
es who have attended interviews in various MNC'
1. How do you see how many instances are running?
A: Issue the following command "ps -ef |grep pmon"
[oracle@host ~]$ ps -ef |grep pmon |grep v grep
oracle 7200 1 0 21:16 ? 00:00:00 ora_pmon_my_db_SID
oracle 9297 9181 0 21:42 pts/0 00:00:00 grep pmon
This will show within the paths returned the names of all instances (if you are
OFA compliant - Oracle Flexible Architecture).
#Count them all:
[oracle@host ~]$ ps -ef |grep pmon |grep v grep |wc -l
1
2. How do you automate starting and shutting down of databases in Unix?
A: One of the approaches is to use dbstart and dbshut scripts by init.d
Another way is to create your own script. To do that, create your own script "db
ora" in /etc/init.d/ directory
3. You have written a script to take backups. How do you make it run automatica
lly every week?
The Crontab will do this work.
Crontab commands:
crontab -e (edit user's crontab)
crontab -l (list user's crontab)
crontab -r (delete user's crontab)
crontab -i (prompt before deleting user's crontab)
Crontab syntax :
crontab entry consists of five fields: day date and time followed by the user (o
ptional) and command to be executed at the desired time
* * * * * user command to be executed
_ _ _ _ _
| | | | |
| | | | +----- day of week(0-6)the day of the week (Sunday=0)
| | | +------- month (1-12) the month of the year
| | +--------- day of month (1-31) the day of the month
| +----------- hour (0-23) the hour of the day
+------------- min (0-59) the exact minute
#Run automatically every week - every 6th day of a week (Saturday=6)
* * * * 6 root /home/root/scripts/my_backup.sh
#TIP: Crontab script generator:
http://generateit.net/cron-job/
4. What is OERR utility?
Oerr is an Oracle utility that extracts error messages with suggested actions fr
om the standard Oracle message files.
Oerr is installed with the Oracle Database software and is located in the ORACLE
_HOME/bin directory.
Usage: oerr facility error
Facility is identified by the prefix string in the error message.
For example, if you get ORA-7300, "ora" is the facility and "7300"
is the error. So you should type "oerr ora 7300".
If you get LCD-111, type "oerr lcd 111", and so on. These include ORA, PLS, EXP,
etc.
The error is the actual error number returned by Oracle.
Example:
$ oerr ora 600
ora-00600: internal error code, arguments: [%s], [%s], [%s], [%s], [%s], [%s], [
%s], [%s]
*Cause: This is the generic internal error number for Oracle program
exceptions. This indicates that a process has encountered an
exceptional condition.
*Action: Report as a bug - the first argument is the internal error number
5. How do you see Virtual Memory Statistics in Linux?
A: There is several ways to check mem stats: cat /proc/meminfo, top, free, vmsta
t...
"cat /proc/meminfo"
[user@host ~]$ cat /proc/meminfo
MemTotal: 5974140 kB
MemFree: 1281132 kB
Buffers: 250364 kB
Cached: 754636 kB
SwapCached: 68540 kB
Active: 3854048 kB
Inactive: 599072 kB
HighTotal: 5111744 kB
HighFree: 1018240 kB
LowTotal: 862396 kB
LowFree: 262892 kB
SwapTotal: 2096472 kB
SwapFree: 1880912 kB
Dirty: 364 kB
Writeback: 0 kB
Mapped: 3494544 kB
Slab: 203372 kB
CommitLimit: 5083540 kB
Committed_AS: 16863596 kB
PageTables: 19548 kB
VmallocTotal: 106488 kB
VmallocUsed: 3536 kB
VmallocChunk: 102608 kB
HugePages_Total: 0
HugePages_Free: 0
Hugepagesize: 2048 kB
"top"
[user@host ~]$ top (sort by memory consumption by pressing SHIFT+O and then pres
s "n")
"free"
[user@host ~]$ free
total used free shared buffers cached
Mem: 5974140 4693336 1280804 0 250364 754636
-/+ buffers/cache: 3688336 2285804
Swap: 2096472 215560 1880912
TIP: free -m shows results in MB
"vmstat"
[user@host ~]$ vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 215560 1281652 250364 754636 0 0 18 15 1 2 3 2 95 0
6. How do you see how much hard disk space is free in Linux?
A: "df" - reports filesystem disk space usage
TIP: "df -h" shows results in human readable format M/G/T
[user@host ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/lvroot 4.3G 3.3G 723M 2% /
/dev/sda1 104M 14M 85M 14% /boot
none 3.1G 0 3.1G 0% /dev/shm
/dev/mapper/lvtmp 2.2G 209M 1.8G 11% /tmp
/dev/mapper/lvvar 2.2G 267M 1.8G 14% /var
/dev/mapper/lvoracle 38G 11G 26G 31% /u01
TIP: df -h /home (shows disk space usage only for /home)
7. What is SAR?
A: sar - Collect, report, or save system activity information.
[user@host ~]$ sar
Linux 3.6.10-26.0.0.0.2.ELsmp (host.domain.local) 02/23/2021
01:30:01 PM CPU %user %nice %system %iowait %idle
...
04:10:01 PM all 2.00 0.00 2.05 0.08 95.86
04:20:02 PM all 2.70 0.00 2.30 0.07 94.93
Average: all 2.73 0.00 2.28 0.16 94.83
8. What is SHMMAX?
A: shmmax maximum size (in bytes) for a UNIX/Linux shared memory segment
DESCRIPTION (docs.hp.com)
Shared memory is an efficient InterProcess Communications (IPC) mechanism.
One process creates a shared memory segment and attaches it to its address space
.
Any processes looking to communicate with this process through the shared memory
segment, then attach the shared memory segment to their corresponding address s
paces as well.
Once attached, a process can read from or write to the segment depending on the
permissions specified while attaching it.
How to display info about shmmax:
[user@host ~]$ cat /etc/sysctl.conf |grep shmmax
kernel.shmmax=3058759680
9. Swap partition must be how much the size of RAM?
A: A tricky question coz opinions about this are always a good topic for any dis
cussions.
In the past; once upon the time, when systems used to have 32/64 or max 128Mb of
RAM memory it was recommended to allocate as twice as your RAM for swap partiti
on.
Nowadays we do have a bit more memory for our systems.
An advice: always take software s vendor recommended settings into account and the
n decide.
For example, Oracle recommends always minimum 2GB for swap and more for their pr
oducts - depends of the product and systems size.
Example of ORACLE Database 11g recommendations:
Amount of RAM Swap Space
Between 1 GB and 2 GB 1.5 times the size of RAM
Between 2 GB and 16 GB Equal to the size of RAM
More than 16 GB 16 GB
Another common example:
Equal the size of RAM, if amount of RAM is less than 1G
Half the size of RAM for RAM sizes from 2G to 4G.
More than 4G of RAM, you need 2G of Swap.
TIP: To determine the size of the configured swap space in Linux, enter the foll
owing command:
[user@host]~ grep SwapTotal /proc/meminfo
SwapTotal: 2096472 kB
To determine the available RAM and swap space use "top" or "free".
10. What is DISM in Solaris?
A: DISM = Dynamic Intimate Shared memory, which is used to support Oracle in Sol
aris Environment.
11. How do you see how many memory segments are acquired by Oracle Instances?
A: ipcs - provides information on the ipc facilities for which the calling proc
ess has read acccess
#UNIX: SEGSZ
root> ipcs -pmb
IPC status from <running system> as of Mon Sep 10 13:56:17 EDT 2001
T ID KEY MODE OWNER GROUP SEGSZ CPID
Shared Memory:
m 2400 0xeb595560 --rw-r----- oracle dba 281051136 15130
m 601 0x65421b9c --rw-r----- oracle dba 142311424 15161
#Linux: bytes
[user@host ~]$ icps
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 32769 oracle 644 122880 2 dest
12. How do you see which segment belongs to which database instances?
A: This can be achieved with help of ipcs tool and sqlplus; oradebug ipc
#Linux
[user@host ~]$ icps
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 32769 oracle 644 122880 2 dest
#UNIX:
root> ipcs -pmb
IPC status from <running system> as of Mon Sep 10 13:56:17 EDT 2001
T ID KEY MODE OWNER GROUP SEGSZ CPID
Shared Memory:
m 32769 0xeb595560 --rw-r----- oracle dba 281051136 15130
m 601 0x65421b9c --rw-r----- oracle dba 142311424 15161
m 702 0xe2fb1874 --rw-r----- oracle dba 460357632 15185
m 703 0x77601328 --rw-r----- oracle dba 255885312 15231
#record value of shmid "32769" (ID in UNIX)
[user@host ~]$ sqlplus /nologin
SQL> connect system/manager as sysdba;
SQL> oradebug ipc
#Information have been written to the trace file. Review it.
In case of having multiple instances, grep all trace files for shmid 32769 to id
entify the database instance corrsponding to memory segments.
#scrap of trace file MY_SID_ora_17727.trc:
Area Subarea Shmid Stable Addr Actual Addr
1 1 32769 000000038001a000 000000038001a000
13. What is VMSTAT?
A: vmstat - Reports virtual memory statistics in Linux environments.
It reports information about processes, memory, paging, block IO, traps, and cp
u activity.
[user@host ~]$ vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
3 0 170224 121156 247288 1238460 0 0 18 16 1 0 3 2 95 0
14. How do you set Kernel Parameters in Red Hat Linux, AIX and Solaris?
A: sysctl - configure kernel parameters at runtime
EXAMPLES
/sbin/sysctl -a (Display all values currently available)
/sbin/sysctl -w kernel.shmmax = 3058759680 ( -w this option changes a sysctl set
ting)
To modify settings permanetly edit /etc/sysctl - kernel sysctl configuration fil
e and then issue the following command:
/sbin/sysctl -p /etc/sysctl.conf ( Load in sysctl settings from the file specifi
ed or /etc/sysctl.conf if none given)
15. How do you remove Memory segments?
A: We can use ipcs and ipcrm command
ipcs - provides information on ipc facilities
ipcrm - removes a message queue, semaphore set or shared memory id
First kill all Oracle database processes; A shared memory object is only removed
after all currently attached processes have detached.
#UNIX
root> ps -ef | grep $ORACLE_SID | grep -v grep | awk '{print $2}' | xargs -i ki
ll -9 {}
root> ipcs -pmb #displays held memory
IPC status from /dev/kmem as of Tue Sep 30 11:11:11 2011
T ID KEY MODE OWNER GROUP SEGSZ CPID LPID
Shared Memory:
m 25069 0x4e00e002 --rw-r----- oracle dba 35562418 2869 23869
m 1 0x4bc0eb18 --rw-rw-rw- root root 31008 669 669
RAM memory segment owned by Oracle is ID=25069.
root> ipcrm m 25069 #this command will release that memory segment
16. What is the difference between Soft Link and Hard Link?
"Symbolic links" (symlinks/soft link) are a special file type in which the link
file actually refers to a different file or directory by name.
When most operations (opening, reading, writing, and so on) are passed the symbo
lic link file, the kernel automatically "dereferences" the link and operates on
the target
of the link. But remove operation works on the link file itself, rather than on
its target!
A "hard link" is another name for an existing file; the link and the original ar
e indistinguishable.
They share the same inode, and the inode contains all the information about a fi
le.
It will be correct to say that the inode is the file. Hard link is not allowed f
or directory (This can be done by using mount with --bind option)!
ln - makes links between files. By default, it makes hard links; with the "-s"
option, it makes symbolic (soft) links.
Synopses:
ln [OPTION]... TARGET [LINKNAME]
ln [OPTION]... TARGET... DIRECTORY
EXAMPLE:
#hard links
[user@host ~]$ touch file1
[user@host ~]$ ln file1 file2
[user@host ~]$ ls -li
total 0
459322 -rw-r--r-- 2 userxxx users 0 May 6 16:19 file1
459322 -rw-r--r-- 2 userxxx users 0 May 6 16:19 file2 (the same inode, rights,
size, time and so on!)
[user@host ~]$ mkdir dir1
[user@host ~]$ ln dir1 dir2
ln: `dir1': hard link not allowed for directory
#symbolic links
[user@host ~]$ rm file2 #hard link removed
[user@host ~]$ ln -s file1 file2 #symlink to file
[user@host ~]$ ln -s dir1 dir2 #symlink to directory
[user@host ~]$ ls -li
total 12
459326 drwxr-xr-x 2 userxxx users 4096 May 6 16:38 dir1
459327 lrwxrwxrwx 1 userxxx users 4 May 6 16:39 dir2 -> dir1 (dir2 refers t
o dir1)
459322 -rw-r--r-- 1 userxxx users 0 May 6 16:19 file1
459325 lrwxrwxrwx 1 userxxx users 5 May 6 16:20 file2 -> file1 (different i
node, rights, size and so on!)
[user@host ~]$ rm file2 #will remove a symlink NOT a targed file; file1
[user@host ~]$ rm dir2
[user@host ~]$ ls -li
[user@host ~]$ ls -li
total 4
459326 drwxr-xr-x 2 userxxx users 4096 May 6 16:38 dir1
459322 -rw-r--r-- 1 userxxx users 0 May 6 16:19 file1
[user@host ~]$ info coreutils ln #(should give you access to the complete manual
)
17. What is stored in oratab file?
A: This file is being read by ORACLE software, created by root.sh script which i
s being executed manually during the software installation and updated by the Da
tabase Configuration Assistant (dbca) during the database creation.
File location: /etc/oratab
ENTRY SYNTAX:
$ORACLE_SID:$ORACLE_HOME:<N|Y>:
$ORACLE_SID - Oracle System Identifier (SID environment variable)
$ORACLE_HOME - Database home directory
<N|Y> Start or not resources at system boot time by the start/stop scripts if co
nfigured.
Multiple entries with the same $ORACLE_SID are not allowed.
EXAMPLES:
[user@host ~]$ cat /etc/oratab
MYDB1:/u01/app/oracle/product/10.2.0/db:Y
emagent:/u01/app/oracle/product/oem/agent10g:N
client:/u01/app/oracle/product/10.2.0/client_1:N
emcli:/u01/app/oracle/product/oem/emcli:N
18. How do you see how many processes are running in Unix?
A: "ps" with "wc" or "top" does teh job.
ps - report a snapshot of the current processes
wc - print the number of newlines, words, and bytes in files
top - display Linux tasks (better solution)
In other words ps will display all running tasks and wc will count them displayi
ng results:
[user@host ~]$ ps -ef | wc -l
149
[user@host ~]$ ps -ef |grep -v "ps -ef" | wc -l #this will not count ps proces e
xecuted by you
148
#using top
[user@host ~]$ top -n 1 | grep Tasks
Tasks: 148 total, 1 running, 147 sleeping, 0 stopped, 0 zombie
19. How do you kill a process in Unix?
A: kill - terminate a process
killall - kill processes by name
kill -9 <PID> #kill process with <PID> by sending SIGKILL 9 Term Kill signal
killall <process name>
EXAPLES:
[user@host ~]$ ps -ef | grep mc
user 31660 31246 0 10:08 pts/2 00:00:00 /usr/bin/mc -P /tmp/mc-user/mc.pwd.3
1246
[user@host ~]$ kill -9 31660
Killed
#killall
[user@host ~]$ killall mc
Terminated
[user@host ~]$ killall -9 mc
Killed
20. Can you change priority of a Process in Unix?
A: YES. nice & renice does the job.
nice - Runs COMMAND with an adjusted scheduling priority. When no COMMAND
specified prints the current scheduling priority.
ADJUST is 10 by default. Range goes from -20 (highest priority) to 19 (lowest).
renice - alters priority of running processes
EXAMPLES: (NI in top indicates nice prio)
[user@host ~]$ mc
[user@host ~]$ top
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1896 userxxx 17 0 7568 1724 1372 S 0 0.0 0:00.03 mc
[user@host ~]$ nice -n 12 mc #runs the mc command with prio of 12.
[user@host ~]$ top
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1763 userxxx 26 12 6832 1724 1372 S 0 0.0 0:00.03 mc
[root@host ~]# renice +16 1763 #must be a root user
1763: old priority 12, new priority 16