DBAs need some basic commands on Linux to better administer the database and server. Here I will be discussing a few of these commands.
Checking Uptime
`uptime` command shows; since when server is up and running. It also shows current load average (1 minute, 5 minute and 15 minute)
`uptime` command shows; since when server is up and running. It also shows current load average (1 minute, 5 minute and 15 minute)
[root@dbserver ~]# uptime
11:58:31 up 431 days, 18:20, 2 users, load average: 4.39, 5.89, 7.07
|
Top
When we execute top command, the screen shows uptime, connected users, load average, total tasks (running and sleeping), any zombie process, current CPU, RAM and SAWP space usage. Screen automatically refreshes every 3 seconds.
When we execute top command, the screen shows uptime, connected users, load average, total tasks (running and sleeping), any zombie process, current CPU, RAM and SAWP space usage. Screen automatically refreshes every 3 seconds.
top - 12:11:09 up 431 days, 18:33, 2 users, load average: 6.40, 6.01, 6.33
Tasks: 988 total, 3 running, 985 sleeping, 0 stopped, 0 zombie
Cpu(s): 3.8%us, 1.1%sy, 0.0%ni, 86.4%id, 8.5%wa, 0.0%hi, 0.1%si, 0.0%st
Mem: 66069772k total, 65937496k used, 132276k free, 303792k buffers
Swap: 52420052k total, 2472380k used, 49947672k free, 51443700k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
18869 oracle 20 0 16.1g 15g 15g S 16.8 24.3 225:01.80 oracle
18881 oracle 20 0 16.1g 15g 15g S 16.5 24.3 225:27.10 oracle
18195 oracle 20 0 16.1g 15g 15g S 11.6 24.3 225:24.49 oracle
12174 oracle 20 0 16.1g 15g 15g S 11.0 24.3 212:40.49 oracle
18201 oracle 20 0 16.1g 15g 15g S 10.3 24.3 225:27.08 oracle
18865 oracle 20 0 16.1g 15g 15g S 10.3 24.3 222:46.36 oracle
11175 oracle 20 0 16.1g 1.9g 1.9g S 9.4 3.0 0:45.53 oracle
18970 oracle 20 0 16.1g 15g 15g S 9.4 24.3 223:51.78 oracle
18867 oracle 20 0 16.1g 15g 15g D 9.1 24.3 224:26.24 oracle
18429 oracle 20 0 16.1g 15g 15g R 7.8 24.3 1524:36 oracle
5456 oracle 20 0 16.1g 15g 15g D 5.5 24.3 24334:57 oracle
12564 oracle 20 0 13424 1840 848 R 2.9 0.0 0:06.98 top
4330 oracle 20 0 16.2g 31m 30m S 0.6 0.0 2689:24 oracle
12459 oracle 20 0 16.1g 12g 12g R 0.6 19.3 31:37.58 oracle
98 root 20 0 0 0 0 S 0.3 0.0 31:39.11 events/23
261 root 20 0 0 0 0 S 0.3 0.0 3498:14 kswapd0
262 root 20 0 0 0 0 S 0.3 0.0 3022:42 kswapd1
263 root 20 0 0 0 0 S 0.3 0.0 2984:17 kswapd2
264 root 20 0 0 0 0 S 0.3 0.0 3009:54 kswapd3
|
File system usage
`df` command shows current file system mount information with total and used space.
`df` command shows current file system mount information with total and used space.
[root@dbserver1 ~]$ df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/cciss/c0d0p2 50G 4.2G 43G 9% /
/dev/cciss/c0d0p3 51G 503M 48G 2% /home
/dev/cciss/c0d0p6 45G 181M 42G 1% /tmp
/dev/cciss/c0d0p5 50G 1.5G 46G 4% /var
/dev/cciss/c0d2p1 100G 7.0G 88G 8% /u01
/dev/cciss/c0d3p1 98G 3.3G 90G 4% /redolog
/dev/cciss/c0d4p1 196G 11G 176G 6% /archive
/dev/cciss/c1d0p1 1.1T 974G 47G 96% /oradata01
/dev/cciss/c0d5p1 439G 395G 22G 95% /oradata02
/dev/cciss/c0d0p1 99M 73M 21M 78% /boot
tmpfs 32G 0 32G 0% /dev/shm
x.x.x.x:/backupnfsserver
5.7T 2.2T 3.6T 38% /backup
|
Directory Size
`du` command can be used to see the directory sizes.
[root@dbserver u01]$ cd app/oracle
[root@dbserver oracle]$ du -sh *
4.5G 1020
1.1G admin
290M agent10g
584M agent12c
15M oraInventory
[root@dbserver oracle]$
|
Find Linux version
There are multiple commands which show different types of results related to Linux version and kernel version ets.
[root@dbserver ~]# cat /proc/version
Linux version 3.8.13-35.3.1.el7uek.x86_64 (mockbuild@ca-build56.us.oracle.com) (gcc version 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC) ) #2 SMP Wed Jun 25 15:27:43 PDT 2014
[root@salman1 ~]# uname
Linux
[root@salman1 ~]# uname -r
3.8.13-35.3.1.el7uek.x86_64
[root@salman1 ~]# uname -mrs
Linux 3.8.13-35.3.1.el7uek.x86_64 x86_64
[root@salman1 ~]# uname -a
Linux salman1.salman.com 3.8.13-35.3.1.el7uek.x86_64 #2 SMP Wed Jun 25 15:27:43 PDT 2014 x86_64 x86_64 x86_64 GNU/Linux
|
CPU Information
To find CPUs information in the server.
[root@sdbserver ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 69
model name : Intel(R) Core(TM) i5-4310U CPU @ 2.00GHz
stepping : 1
microcode : 0x19
cpu MHz : 2570.664
cache size : 6144 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 5
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl pni ssse3 lahf_lm
bogomips : 5141.32
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 69
model name : Intel(R) Core(TM) i5-4310U CPU @ 2.00GHz
stepping : 1
microcode : 0x19
cpu MHz : 2570.664
cache size : 6144 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
apicid : 1
initial apicid : 1
fpu : yes
fpu_exception : yes
cpuid level : 5
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl pni ssse3 lahf_lm
bogomips : 5141.32
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
Summary of CPUs [root@mydbserver5 ~]# lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 72 On-line CPU(s) list: 0-71 Thread(s) per core: 2 Core(s) per socket: 18 Socket(s): 2 NUMA node(s): 2 Vendor ID: GenuineIntel CPU family: 6 Model: 63 Stepping: 2 CPU MHz: 2301.000 BogoMIPS: 4589.98 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 46080K NUMA node0 CPU(s): 0-17,36-53 NUMA node1 CPU(s): 18-35,54-71 |
Memory Information
[root@dbserver ~]# cat /proc/meminfo
MemTotal: 3785956 kB
MemFree: 2432588 kB
Buffers: 756 kB
Cached: 611264 kB
SwapCached: 0 kB
Active: 669596 kB
Inactive: 463368 kB
Active(anon): 521636 kB
Inactive(anon): 8712 kB
Active(file): 147960 kB
Inactive(file): 454656 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 4095996 kB
SwapFree: 4095996 kB
Dirty: 12 kB
Writeback: 0 kB
AnonPages: 521012 kB
Mapped: 89900 kB
Shmem: 9404 kB
Slab: 112276 kB
SReclaimable: 62928 kB
SUnreclaim: 49348 kB
KernelStack: 2432 kB
PageTables: 20668 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 5988972 kB
Committed_AS: 2170600 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 56324 kB
VmallocChunk: 34359655416 kB
HardwareCorrupted: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 12224 kB
DirectMap2M: 4182016 kB
|
Memory and Swap Usage
[root@salman1 ~]# free
total used free shared buffers cached
Mem: 3785956 1353032 2432924 9404 756 601868
-/+ buffers/cache: 750408 3035548
Swap: 4095996 0 4095996
|
Using fdisk to Create Disk Partitions
Suppose we have a new disk (64G size) attached to our server, and we want to partition it and mount it on a directory, we will start by first find our disk under /dev directory. As we see bellow, /deb/sdb is my new disk
[root@dbserver ~]# ls -l /dev/sd*
brw-rw----. 1 root disk 8, 0 Feb 11 11:47 /dev/sda
brw-rw----. 1 root disk 8, 1 Feb 11 11:47 /dev/sda1
brw-rw----. 1 root disk 8, 2 Feb 11 11:47 /dev/sda2
brw-rw----. 1 root disk 8, 3 Feb 11 11:47 /dev/sda3
brw-rw----. 1 root disk 8, 4 Feb 11 11:47 /dev/sda4
brw-rw----. 1 root disk 8, 5 Feb 11 11:47 /dev/sda5
brw-rw----. 1 root disk 8, 16 Feb 11 11:47 /dev/sdb
|
Now we can use fdisk command to create partition(s) of this new disk. Please see comments in red color which explain how to use fdisk
[root@dbserver ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x38230405.
On the following prompt, type “n” to create new partition of this disk.
Command (m for help): n
On the following prompt, specify what type of partition you want to create, Primary or Extended, I selected Primary here by keying in “p”
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Select partition number, I just pressed <enter> to select default “1”
Partition number (1-4, default 1):
Select sector of the disk which will be first sector of the new partition. By default, the first available sector of the disk is selected, press <enter>
First sector (2048-134217727, default 2048):
Using default value 2048
Select last sector of the disk. Alternatively you can also specify the size of the disk in K, M and G. I selected last sector as I want a single partition of this disk.
Last sector, +sectors or +size{K,M,G} (2048-134217727, default 134217727):
Using default value 134217727
Partition 1 of type Linux and of size 64 GiB is set
Type “w” to write table to the disk and exit.
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@sdbserver ~]#ls –l /dev/sd*
See new partition highlighted bellow
brw-rw----. 1 root disk 8, 0 Feb 11 11:47 /dev/sda
brw-rw----. 1 root disk 8, 1 Feb 11 11:47 /dev/sda1
brw-rw----. 1 root disk 8, 2 Feb 11 11:47 /dev/sda2
brw-rw----. 1 root disk 8, 3 Feb 11 11:47 /dev/sda3
brw-rw----. 1 root disk 8, 4 Feb 11 11:47 /dev/sda4
brw-rw----. 1 root disk 8, 5 Feb 11 11:47 /dev/sda5
brw-rw----. 1 root disk 8, 16 Feb 11 12:44 /dev/sdb
brw-rw----. 1 root disk 8, 17 Feb 11 12:36 /dev/sdb1
|
Next step is to format the partition using some file system. I used xfs file system using mkfs.xfs command. You may also use mkfs.ext3 or mkfs.ext3 command etc.
[root@dbserver ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=256 agcount=4, agsize=4194240 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=16776960, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=8191, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
|
Now mount the file system to some directory
[root@dbserver ~]# mkdir /u02
[root@dbserver ~]# mount /dev/sdb1 /u02
[root@dbserver ~]# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 15G 5.0G 9.7G 35% /
devtmpfs 1.8G 0 1.8G 0% /dev
tmpfs 1.9G 84K 1.9G 1% /dev/shm
tmpfs 1.9G 8.8M 1.8G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda5 235G 33M 235G 1% /u01
/dev/sda1 247M 125M 122M 51% /boot
[root@dbserfver ~]# mkfs.xfs /dev/sdb1
|
You may also want to add an entry in /etc/fstab file to automount this fie system on every system startup. You will log in as root and use "vi" to open /etc/fstab which should look as follows
#
# /etc/fstab
# Created by anaconda on Wed Feb 4 16:41:21 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=1203b9b5-fcd5-4c44-b32c-6b13b291627b / xfs defaults 1 1
UUID=bf20f46d-07d1-4f3e-ae0e-f4c712ebc648 /boot xfs defaults 1 2
UUID=0fb10a7d-c7c0-4981-82cb-91c3e31acab9 /u01 xfs defaults 1 2
UUID=ee5fc3cb-24c0-4c8c-83b1-89ffff67adc3 swap swap defaults 0 0
/dev/sdb1 /u02 xfs defaults 0 0
|
No comments:
Post a Comment