essential linux for the sql · •1991 project by linux torvalds from finland to create free...

77
Essential Linux for the SQL Server DBA Kellyn Pot’Vin-Gorman Technical Intelligence Manager, Delphix

Upload: others

Post on 04-Jun-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Essential Linux for the SQL

Server DBA

Kellyn Pot’Vin-GormanTechnical Intelligence Manager, Delphix

Page 2: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Community

Board President of Rocky Mountain Oracle User Group and for Denver SQL Server User Group and presenter at 45 technical events annually.

Kellyn Pot’Vin-Gorman

Deck of ACEs

2018 Idera ACE and Oracle ACE Alumnus and member of Oak Table Network, a group of Oracle scientists.

Two Decades of Data Management

Managing Oracle, SQL Server, MySQL, Sybase and big data. Current Technical Intelligence Manager for the Office of CMO for Delphix.

http://dbakevlar.com

@DBAKevlar

https://linkedin/in/kellynpotvin

Page 3: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

So SQL Server Has Come to the World of Linux

There are tools out there that have been the go-to success for Oracle DBAs since Linux adoption…

These utilities provide the information we need to:

• Manage the environment

• Troubleshoot issues

• Gather information

• Report on usage

Page 4: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

But You Need to Learn to Walk Before You Run..

4

Page 5: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

And it Should Never Be Like This…

5

Linux

Page 6: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

History Lesson

• 1991 project by Linux Torvalds from Finland to create free operating system kernel.

• Based on C programming

• Over 15 million lines of code in base kernel.

• Almost was named Freax

• Now all part of the GNU Project

• Debian, Redhat, Oracle Linux, Ubuntu, Suse are all flavors of Linux.

• Microsoft introduces SQL Server on Linux in version 2016

6

Page 7: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

User, Groups and Penguins, Oh My!

• Don’t do everything as ROOT, (aka super user)

• Perform administrator tasks by using SUDO, (switch user domain owner)

• Log in as with your own user ID and su, (switch user) to the application owner.

• There is a UID, (User ID) for every user name.

• Each user is assigned a group(s) for role hierarchy

• A home directory will contain the following:• Profile, (RC) with environment variables, alias’ and other necessary configurations for the user

environment.

7

Page 8: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

RC and Profiles

• RC file stands for Run Commands

• Profile is similar, but set up as a secondary set of profile settings, including:• Shell to be used

• Alias’

• Environment variables

• Path information

• File name begins with a “.”

• View with command ls -la

.bashrc

.bash_rc

.profile

.profile_xx

8

Page 9: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Example of a profile#/! /usr/bin/sh

EDITOR=nano

sudo visudo

export PATH = $PATH:.

# export ORACLE_HOME=/u01/app/oracle/dbhome_1/db12c

export SQL_HOME=/u01/app/mssql/140

export LANG=en.UTF-8

export JAVA_HOME=/usr/bin/java

# alias info

alias reload=’source ~/.bash_profile’

alias pre-‘open -a Preview’

alias cd.. =’cd ..’

9

Page 10: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Creating Users

• Useradd has different results than adduser, but both work.

• Useradd will require you to:• Manually update the password with passwd <username>

• Manually assign a group with usermod after creating a manual group with groupadd command

• If you wish to add any pertinent information about the user, that must be added manually.

A user should be created for every user logging in. Don’t share logins.

Avoid non-audited, such as direct ROOT access.

Grant SUDO with great care.

Grant SU to only those that require it.

10

Page 11: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

SU and SUDO

• To switch to from existing user to become jsmith:

$ su – jsmith

• To execute a command as ROOT after being granted SUDO privileges

$ sudo setsys.sh –y

11

Page 12: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Understanding File Permissions

Where this can be confusing for some, is that we visibly identify the grants by their values, either as separate values or as totals.

• Read,(r)= 4

• Write,(w)= 2

• Execute, (x)=1

• owner has 4+2+1=7

• group has 4+2+1=7

• other has 4+2+1=7

12

Page 13: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Changing Permissions

• CHMOD= change modify

$ chmod <filename> XXX

$ chmod test.txt 764 • Owner- read, write, execute

• Group- read, write

• Other- read

You must have permissions to update the permissions or must SU/SUDO to perform them:

$ sudo chmod test.txt 764

13

Page 14: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Changing File Owner

• CHOWN = change owner

$ chown <newuser>:<group> <filename>

$ chown jsmith:dba test.sh

• You must have privileges or own the file to begin with to change the ownership.

14

Page 15: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Basics

What Command Common

Change Diretory cd cd, cd .. ,cd /directory path

List or Directory information ls ls, ls –lf, ls –la

Locate program find <program name> find java, find sql

Locate which installation used which <program name> which mssql

Current Directory pwd pwd

Create Directory mkdir mkdir scripts mkdir

/u01/apps/scripts

Create File touch <filename>, vim <filename> touch test.sh

Edit File vim <filename>, vi <filename> vim touch.sh

Remove rm <filename> rm touch.sh

15

Page 16: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Processes

• Ps command

$ ps

$ ps –ef

To Kill a process, (BECAREFUL!)

$ kill <PID>

16

Page 17: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Editors

• VI/VIM makes you cool- old school

• Nano

• eMacs

• Create a file easily by issuing the touch command

$ touch <filename>

17

Page 18: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

VI(M)Command line editor

$ vi <filename>

• Go down a line: j

• Go up a line: k

• Go to the right: l

• Go to the left: h

• Insert: i

• Append: a

• Append to the end of a line: a

• Add a line and insert below your cursor: o

18

Add a line and insert ABOVE your

cursor: <shft> o

Undo: u

Quit without saving: :q

Quit without saving to a read only file:

:q!

Write to a file: :w

Write to a read only file, (override): :w!

Write to a file and quit: :wq

Write to a read only file, (override) and

quit: :wq!

Page 19: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Redirecting Data Output to a File

• $ <command> > <filename>

$ ls > filelist.txt

$ ls >> filelist.txt

• If run again with the “>>”, the results will be appended to the first file’s contents.

19

Page 20: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Running an Update on Linux

• Updates and Installations are done most often via Yum, APT-GET or Zypper

• Using APT-GET

• Update from repository, (stored in

$ apt-get update

• Install updates, (may require SUDO)

$ apt-get install

20

Page 21: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Adding Utilities is Done via Packages

• Common Installers for Linux• YUM

• APT-GET

• ZYPPER

Installing a package with APT-GET

$ sudo apt-get install –y <pkgname>

Viewing package information:

$apt-cache pkgname <pkgname>

Display package information:

$apt-cache show <pkgname>

21

Page 22: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Cheat Sheets for Common Installers

• Yum: https://access.redhat.com/articles/yum-cheat-sheet

• Apt-Get https://blog.packagecloud.io/eng/2015/03/30/apt-cheat-sheet/

• Zypper: https://en.opensuse.org/images/1/17/Zypper-cheat-sheet-1.pdf

22

Page 23: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Mission Impossible

• No Powershell

• BASH, (Born again shell)

• KSHELL, (Korn Shell)

• CSHELL, (based off C)

• Shell scripting is very similar in each of these languages and very different from Powershell.

23

Page 24: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Linux system-level diagnostics

• CPU and Memory

• Process

• Network

• Traces

• Other useful Linux diagnostic utilities

• Support recommended diagnostic tools

• A great source of living technical information

Page 25: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Utilities to

View

Resource

Usage

• SAR

• SADC/SADF

• MPSTAT

• VMSTAT

• TOP

25

Page 26: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Common Arguments and Values

• Some of the utilities aren’t standard and may need to be installed.• Yum and apt-get are your friend

• You may require sudo, (super user) privileges to install

• <command> -x(xx)• Arguments are cap sensitive, (as is everything in Unix world.)

• <command> -x 5 5• First how many second sleep, Second value is how many results to return

• <command> -h• Provides help information about the utility or command

26

Page 27: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

What is SAR?

• System Activity Report• Provides information about

• CPU

• Memory and virtual memory

• I/O

• Network

• Provided by the SYSSTAT package

• What if it’s missing?

• Install it as root:

$yum -y install sysstat

$apt-get install sysstat

27

Page 28: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

sar Utility

• CPU utilization: sar -u• %usr, %sys, %idle

• %nice

• Intervals of CPU: sar 1 3• 3 times, every 1 second

• CPU run queue report: sar -q• Runq-sz

• plist-sz and load averages

• Context switching activity: sar -w• cswch/s

• Virtual memory swapping: sar -W• swpin/s, swpot/s

• Virtual memory paging: sar -B • pgpgin/s, pgpgot/s

Page 29: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

sar Utility

$ sar -u 5 5

Linux 2.6.32-573.22.1.el6.x86_64 (linuxsource.delphix.local) 11/28/2017 _x86_64_ (2 CPU)

06:15:31 PM CPU %user %nice %system %iowait %steal %idle

06:15:36 PM all 0.20 0.00 0.20 48.58 0.00 51.01

06:15:41 PM all 0.30 0.00 0.20 47.98 0.10 51.41

06:15:46 PM all 0.30 0.00 0.20 46.92 0.00 52.58

06:15:51 PM all 0.20 0.00 0.20 47.77 0.00 51.82

06:15:56 PM all 0.20 0.00 0.20 47.78 0.10 51.72

Average: all 0.24 0.00 0.20 47.81 0.04 51.71

Page 30: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

sar Utility$ sar -q 5 5

Linux 2.6.32-573.22.1.el6.x86_64 (linuxsource.delphix.local)

11/28/2017 _x86_64_ (2 CPU)

06:16:45 PM runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15

06:16:50 PM 0 190 1.37 1.28 1.30

06:16:55 PM 0 190 1.34 1.28 1.29

06:17:00 PM 0 190 1.31 1.27 1.29

06:17:05 PM 0 190 1.36 1.29 1.30

06:17:10 PM 0 190 1.34 1.28 1.30

Average: 0 190 1.34 1.28 1.30

Page 31: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

What is SADC/SADF?

• sadc: back-end system activity data collector utility behind sar• Collects specified system data at configured intervals

• Saves data to specified binary files

• sadf: system activity data formatter • report on data collected by sadc/sar

• output to be consumed by other programs like awk, MS-Excel, etc

• Options for translating and displaying dates, numbers, text

• Output to plain text or XML

Page 32: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

mpstat utilityProcessor Level Statisitcs

$ mpstat –P ALL

Linux 2.6.32-573.22.1.el6.x86_64 (linuxsource.delphix.local) 11/28/2017 _x86_64_

(2 CPU)

06:18:10 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle

06:18:10 PM all 1.42 0.00 0.19 8.01 0.00 0.00 0.02 0.00 90.36

06:18:10 PM 0 1.38 0.00 0.21 15.10 0.00 0.00 0.02 0.00 83.29

06:18:10 PM 1 1.45 0.00 0.17 0.94 0.00 0.00 0.02 0.00 97.42

Page 33: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

vmstat Utility

Virtual Memory Statistics

vmstat 5 5

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----

r b swpd free buff cache si so bi bo in cs us sy id wa st

0 2 28612 131668 255192 6766272 0 0 0 148 1 3 1 0 90 8 0

0 1 28612 234736 255204 6766424 0 0 24 1480 1485 2737 2 1 48 49 0

0 2 28612 234752 255208 6766536 0 0 0 1511 1365 2632 0 0 50 50 0

1 1 28612 234752 255208 6766664 0 0 0 1399 1353 2626 0 0 50 50 0

0 2 28612 218164 255216 6766784 0 0 18 1310 1337 2591 0 0 49 51 0

Page 34: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

top Utility

Tasks: 165 total, 1 running, 164 sleeping, 0 stopped, 0 zombie

Cpu(s): 0.3%us, 0.2%sy, 0.0%ni, 53.5%id, 46.0%wa, 0.0%hi, 0.0%si, 0.0%st

Mem: 8057984k total, 7827928k used, 230056k free, 255324k buffers

Swap: 311292k total, 28612k used, 282680k free, 6771660k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

9888 delphix 20 0 636m 43m 16m S 0.7 0.5 51:40.68 mssql

9892 delphix 20 0 636m 43m 16m D 0.7 0.5 51:18.86 mssql

9886 delphix 20 0 652m 43m 16m S 0.3 0.6 51:19.84 mssql

1 root 20 0 19232 976 820 S 0.0 0.0 0:26.11 delcli

2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd

3 root RT 0 0 0 0 S 0.0 0.0 0:09.92 migration/0

Page 35: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

What is UPTIME?

• uptime displays current time and up-time

• Also displays the average number of processes in run-queue over the past 1 minute, 5 minutes, and 15 minutes (a.k.a. load average)

35

Page 36: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

uptime and w Utilities

$ uptime

18:20:41 up 41 days, 17 min, 1 user, load average: 1.17, 1.28, 1.30

• w displays same info plus info about logged-in UNIX users

$ w

18:21:05 up 41 days, 17 min, 1 user, load average: 1.25, 1.29, 1.30

USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT

delphix pts/0 c-67-164-182-219 18:05 0.00s 0.02s 0.02s sshd: delphix

[priv]

Page 37: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Process Diagnostics

• ps• Process status

• pmap• Process mapping

• http://dbakevlar.com/2017/12/sql-server-2017-linux-processes/

• dstat• Disk, cpu and network monitoring

• nmon• Color coded display of cpu, disk and memory statistics

Page 38: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

ps Utility

• SysV version with many versions and variations:

$ ps -eaf

% ps -aux

# ps –eo opt[,opt…]

• Provides info about individual processes• Status, PID, PPID, user, command text and parameters

• Cumulative and recent CPU usage

• Memory (virtual, resident)

Page 39: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

ps Utility

• An easy home-grown “top” command

$ ps –eaf | sort –n | tail

root 689 2 0 Oct18 ? 00:00:00 [ext4-dio-unwrit]

root 7 2 0 Oct18 ? 00:00:12 [migration/1]

root 723 2 0 Oct18 ? 00:01:34 [kauditd]

root 781 2 0 Oct18 ? 00:00:18 [flush-253:0]

root 8 2 0 Oct18 ? 00:00:00 [stopper/1]

root 9 2 0 Oct18 ? 00:00:06 [ksoftirqd/1]

root 99 2 0 Oct18 ? 00:00:00 [kdmremove]

rpc 1101 1 0 Oct18 ? 00:00:01 rpcbind

Page 40: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

ps Utility

• Another home-grown “top” command

• Also displays memory consumption in Kbytes

$ ps -eo user,pid,pcpu,vsz,rss,comm | sort -n | tail

root 689 0.0 0 0 ext4-dio-unwrit

root 7 0.0 0 0 migration/1

root 723 0.0 0 0 kauditd

root 781 0.0 0 0 flush-253:0

root 8 0.0 0 0 stopper/1

root 9 0.0 0 0 ksoftirqd/1

root 99 0.0 0 0 kdmremove

rpc 1101 0.0 18980 588 rpcbind

Page 41: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

ps Utility

• Displaying environment variable values within a process

$ ps -eaf | grep jar

delphix 11313 1 0 Oct18 ? 00:23:10 /usr/java/jdk1.7.0_51/bin/java -Djava.util.logging.config.file=/u02/app/apache-tomcat-7.0.42/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/u02/app/apache-tomcat-7.0.42/endorsed -classpath /u02/app/apache-tomcat-7.0.42/bin/bootstrap.jar:/u02/app/apache-tomcat-7.0.42/bin/tomcat-juli.jar -Dcatalina.base=/u02/app/apache-tomcat-7.0.42 -Dcatalina.home=/u02/app/apache-tomcat-7.0.42 -Djava.io.tmpdir=/u02/app/apache-tomcat-7.0.42/temp org.apache.catalina.startup.Bootstrap start

$ ps eww 11313

PID TTY STAT TIME COMMAND

11313 ? Sl 23:10 /usr/java/jdk1.7.0_51/bin/java -Djava.util.logging.config.file=/u02/app/apache-tomcat-7.0.42/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/u02/app/apache-tomcat-7.0.42/endorsed -classpath /u02/app/apache-tomcat-7.0.42/bin/bootstrap.jar:/u02/app/apache-tomcat-7.0.42/bin/tomcat-juli.jar -Dcatalina.base=/u02/app/apache-tomcat-7.0.42 -Dcatalina.home=/u02/app/apache-tomcat-7.0.42 -Djava.io.tmpdir=/u02/app/apache-tomcat-7.0.42/temp org.apache.catalina.startup.Bootstrap start SHELL=/bin/bash TERM=xterm USER=delphix PATH=/sbin:/usr/sbin:/bin:/usr/bin PWD=/ HOME=/home/delphix SHLVL=3 LOGNAME=delphix _=/usr/java/jdk1.7.0_51/bin/java

Page 42: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

CPU/Memory Diagnostics

• Use top and/or ps to identify process activity in Linux• By current CPU activity

• By total CPU time consumed

• By time started

• By process name

• By UNIX account

• By process hierarchy

• parent processes, child processes, etc.

Page 43: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

pmap Utilities Example

$ pmap -x 11313

11313: /usr/java/jdk1.7.0_51/bin/java -Djava.util.logging.config.file=/u02/app/apache-tomcat-7.0.42/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/u02/app/apache-tomcat-7.0.42/endorsed -classpath /u02/app/apache-tomcat-7.0.42/bin/bootstrap.jar:/u02/app/apache-tomcat-7.0.42/bin/tomcat-juli.jar -Dcatalina.base=/u02/app/apache-tomcat-7.0.42 -Dcatalina.home=/u02/app/apache-tomcat-7.0.42 -Djava.io.tmpdir=/u02/app/apache-tomcat-7.0.42/temp org.apache.cata

Address Kbytes RSS Dirty Mode Mapping

0000000000400000 4 0 0 r-x-- java

0000000000600000 4 4 4 rw--- java

00007f09de9a6000 4 0 0 r--s- commons-daemon.jar

00007f09de9a7000 4 0 0 r--s- bootstrap.jar

00007f09de9a8000 32 16 12 rw-s- 11313

00007f09de9b3000 4 4 4 r---- ld-2.12.so

00007f09de9b4000 4 4 4 rw--- ld-2.12.so

00007f09de9b5000 4 4 4 rw--- [ anon ]

00007fff04ccb000 84 32 32 rw--- [ stack ]

00007fff04df6000 4 4 0 r-x-- [ anon ]

ffffffffff600000 4 0 0 r-x-- [ anon ]

---------------- ------ ------ ------

total kB 3294068 188964 186976

Page 44: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

fuser/lsof Utilities

• Displays list of UNIX processes with file handles

$ fuser /u01/app/delphix/oradata/orcl/system01.dbf

/u01/app/delphix/oradata/orcl/system01.dbf: 3801 9343 9349 9351 9353 9355

9357 9359 9911 10082 10084 22879 30148

$ ps -eaf | grep 9357

delphix 9357 1 0 Oct18 ? 00:00:19 ora_reco_orcl background

$ ps –eaf | grep 3801

delphix 3801 1 0 Oct22 ? 00:24:20 oracleorcl (LOCAL=NO)

$ ps –eaf | grep 30148

delphix 30148 1 0 Nov22 ? 00:02:04 ora_m002_orcl background

Page 45: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

fuser/lsof Utilities• Displays list of UNIX processes using file-system

$ df -k

Filesystem 1K-blocks Used Available Use% Mounted on

/dev/mapper/vg_linuxsource-lv_root

14600800 3135856 10720092 23% /

tmpfs 4028992 0 4028992 0% /dev/shm

/dev/xvda1 487652 132589 329463 29% /boot

/dev/xvdf 30832636 28133056 1126716 97% /u01

/dev/xvdg 20511356 4213904 15248876 22% /u02

$ fuser /dev/xvdf

/dev/xvdf: 727ctm 725ctm 723ctm 722tm 720ctom 633tom

623tom 462o 458o 456o 454o 452o 450o 448o 446o 444o

Page 46: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

What is DSTAT?

• Monitoring tool for CPU, disk and network activity

• Displays ongoing values in interval until q(uit)

• To Install:

$ yum install dstat –y

Or

$ sudo apt-get install dstat

46

Page 47: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

dstat Utility

47

Page 48: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

dstat Utility

• Dstat for one disk and only CPU info:

$ dstat -cdl -D xvda1

48

Page 49: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

dstat Utility

• Monitor Disk Reads

$ dstat -d

49

Page 50: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

What is NMON?

50

• information dump creation related to cpu, memory, IO or network.

• Install:

$ yum install nmon –y

• Use menu

• q<enter> to quit or

• <ctrl> c

Page 51: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

nmon CPU

• Click C <enter>

51

Page 52: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

nmon memory

• m<enter>

52

Page 53: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

nmon NFS

• NFS<enter>

53

Page 54: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

fuser/lsof Utilities

• Displays list of UNIX processes using file-system

# lsof /var

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

syslogd 350 root 5w VREG 222,5 0 440818 /var/adm/messag

syslogd 350 root 6w VREG 222,5 339098 6248 /var/log/syslog

cron 353 root cwd VDIR 222,5 512 254550 /var -- atjobs

Page 55: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Network Diagnostics

• ifconfig• Configure/display network interfaces

$apt-get install -y net-tools

• netstat/ss• Display cumulative network statistics

• ping• Send ICMP echo packets to network hosts

• traceroute• Trace the route of ICMP echo packets to network hosts

• tcpdump/snoop

Page 56: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

ifconfig Utility• Configures network interfaces

• Configure new network interface: ifconfig … create inet … up• Display network interface status: ifconfig -a

$ ifconfig -a

eth0 Link encap:Ethernet HWaddr 06:8D:24:F2:82:3C

inet addr:10.0.1.20 Bcast:10.0.1.255 Mask:255.255.255.0

inet6 addr: fe80::48d:24ff:fef2:823c/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:9001 Metric:1

RX packets:29480071 errors:0 dropped:0 overruns:0 frame:0

TX packets:26850299 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:4059464946 (3.7 GiB) TX bytes:9135825067 (8.5 GiB)

Interrupt:153

Page 57: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

What is NETSTAT?

• Displays network connections, routing tables, interface statistics• Network connections (a.k.a. sockets): netstat

• Cumulative networking statistics: netstat -s

• Routing tables: netstat -r

• STREAMS statistics (Solaris and AIX): netstat -m

• Verbose mode: add “-v” switch

Page 58: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

netstat Utility$ netstat

Active Internet connections (w/o servers)

Proto Recv-Q Send-Q Local Address Foreign Address State

tcp 0 0 linuxsource:12129 linuxsource:ncube-lm ESTABLISHED

tcp 0 64 linuxsource:ssh c-164-182-219.hsd1:50171 ESTABLISHED

tcp 0 0 linuxsource:ncube-lm ip-10-0-1-10.delphix.:58424 ESTABLISHED

tcp 0 0 linuxsource:ncube-lm landsharkengine.delph:63611 ESTABLISHED

tcp 0 0 linuxsource:ncube-lm linuxsource:12129 ESTABLISHED

udp 0 0 localhost:17493 localhost:17493 ESTABLISHED

Active UNIX domain sockets (w/o servers)

Proto RefCnt Flags Type State I-Node Path

unix 12 [ ] DGRAM 8754 /dev/log

unix 2 [ ] DGRAM 7377 @/org/kernel/udev/udevd

unix 3 [ ] STREAM CONNECTED 9499

unix 2 [ ] DGRAM 9338

unix 2 [ ] DGRAM 8927

Page 59: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

netstat Utility• Display network routing tables on the local host:

$ netstat -r

Kernel IP routing table

Destination Gateway Genmask Flags MSS Window irtt

Iface

10.0.1.0 * 255.255.255.0 U 0 0 0 eth0

link-local * 255.255.0.0 U 0 0 0 eth0

default 10.0.1.1 0.0.0.0 UG 0 0 0 eth0

Page 60: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

What is SS?

• SS stands for Socket Statistics

• Works like NETSTAT

• Gathers info from the kernel via NAD

• To install:

$apt-get install iproute2

60

Page 61: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

ss Utility

$ ss

$ ss -ltp

61

Page 62: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

ping Utility

• Simple diagnostic test for network connectivity• Be aware that many network administrator block ICMP traffic for security reasons$apt-get install iputils.ping

$ ping -c 4 www.amazon.com

PING e15316.ci.akamaiedge.net (104.86.87.164) 56(84) bytes of data.

64 bytes from a104-86-87-164.deploy.static.akamaitechnologies.com (104.86.87.164): icmp_seq=1 ttl=50 time=1.81 ms

64 bytes from a104-86-87-164.deploy.static.akamaitechnologies.com (104.86.87.164): icmp_seq=2 ttl=50 time=1.83 ms

64 bytes from a104-86-87-164.deploy.static.akamaitechnologies.com (104.86.87.164): icmp_seq=3 ttl=50 time=1.99 ms

64 bytes from a104-86-87-164.deploy.static.akamaitechnologies.com (104.86.87.164): icmp_seq=4 ttl=50 time=1.85 ms

--- e15316.ci.akamaiedge.net ping statistics ---

4 packets transmitted, 4 received, 0% packet loss, time 3004ms

rtt min/avg/max/mdev = 1.812/1.874/1.994/0.082 ms

Page 63: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

What is TRACEROUTE?

• Display the route taken by ICMP packets to an IP host

• If missing, install using:

$yum install traceroute –y

$apt-get install traceroute -y

63

Page 64: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

traceroute Utility$ traceroute www.amazon.com

traceroute to www.amazon.com (54.192.195.66), 30 hops max, 60 byte packets

1 216.182.225.134 (216.182.225.134) 16.379 ms 216.182.225.124 (216.182.225.124) 49.305 ms216.182.225.134 (216.182.225.134) 16.347 ms

2 100.66.8.70 (100.66.8.70) 19.966 ms 100.66.8.6 (100.66.8.6) 19.962 ms 100.66.8.250 (100.66.8.250) 14.142 ms

3 100.66.10.46 (100.66.10.46) 21.317 ms 100.66.10.100 (100.66.10.100) 19.104 ms 100.66.11.150 (100.66.11.150) 14.317 ms

4 100.66.7.237 (100.66.7.237) 15.802 ms 100.66.7.183 (100.66.7.183) 16.916 ms 100.66.6.67 (100.66.6.67) 16.800 ms

5 100.66.4.199 (100.66.4.199) 19.609 ms 100.66.4.127 (100.66.4.127) 14.576 ms 100.66.4.151 (100.66.4.151) 11.455 ms

6 100.65.9.65 (100.65.9.65) 0.349 ms 100.65.9.33 (100.65.9.33) 5.948 ms 100.65.9.1 (100.65.9.1) 0.275 ms

7 205.251.244.243 (205.251.244.243) 1.378 ms 72.21.220.120 (72.21.220.120) 1.280 ms 1.333 ms

8 54.239.111.120 (54.239.111.120) 24.074 ms 23.301 ms 54.239.110.22 (54.239.110.22) 37.663 ms

9 54.239.111.183 (54.239.111.183) 1.415 ms 54.239.111.179 (54.239.111.179) 1.234 ms 1.280 ms

10 72.21.220.9 (72.21.220.9) 1.326 ms 1.348 ms 1.391 ms

Page 65: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

What is TCPDUMP?

• Dump/sniff traffic on a network

• Another one that may be missing:

$ yum install tcpdump –y

$ apt-get install tcpdump

65

Page 66: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

tcpdump/snoop Utilities

$ tcpdump

tcpdump: listening on hme0

18:56:08.427002 IP linuxsource.ssh > c-67-164-182-219.hsd1.co.comcast.net.50171: Flags [P.], seq 529952:530160, ack 3681, win 172, length 208

18:56:08.428001 IP linuxsource.ssh > c-67-164-182-219.hsd1.co.comcast.net.50171: Flags [P.], seq 530160:530368, ack 3681, win 172, length 208

18:56:08.429695 IP c-67-164-182-219.hsd1.co.comcast.net.50171 > linuxsource.ssh: Flags [.], ack 515360, win 256, length 0

18:56:08.429707 IP c-67-164-182-219.hsd1.co.comcast.net.50171 > linuxsource.ssh: Flags [.], ack 517984, win 252, length 0

18:56:08.429723 IP c-67-164-182-219.hsd1.co.comcast.net.50171 > linuxsource.ssh: Flags [P.], seq 3681:3745, ack 515568, win 255, length 64

^C18:56:08.429925 IP linuxsource.ssh > c-67-164-182-219.hsd1.co.comcast.net.50171: Flags [P.], seq 530368:530960, ack 3745, win 172, length 592

2781 packets captured

2781 packets received by filter

0 packets dropped by kernel

Page 67: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Trace Utilities

• Different utilities on different platforms, but for Linux:• strace

• Attach to or run a process and then trace:• UNIX system calls executed

• Signals received

• Machine faults incurred

• (optional) entry/exit trace of user level function calls

Page 68: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

What is DTRACE?

• Performance analysis and troubleshooting tool (http://dtrace.org )

• Not just user-level software (i.e. applications, databases and webservers)

• also OS kernel and device drivers

• provides a language, (i.e. “D”) for writing DTrace scripts and one-liners

• Terrific case-study of I/O performance analysis using DTrace

• https://blogs.oracle.com/BestPerf/entry/i_o_analysis_using_dtrace

• Installation:

$apt-get install systemtap-sdt-dev

68

Page 69: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

dtrace Utility$ dtrace -n 'proc:::exec-success{printf("%d %s”,timestamp,curpsinfo-

>pr_psargs);}’

dtrace: description 'proc:::exec-success ' matched 1 probe

CPU ID FUNCTION:NAME

1 797 exec_common:exec-success 21935388676181394 man ls

0 797 exec_common:exec-success 21935388840101743 sh -c cd /usr/share/man;

tbl /usr/sha

1 797 exec_common:exec-success 21935388858652639 col –x

0 797 exec_common:exec-success 21935388863714971 neqn

/usr/share/lib/pub/eqnchar –

0 797 exec_common:exec-success 21935388867119787 tbl

/usr/share/man/man1/ls.1

1 797 exec_common:exec-success 21935388881310626 nroff -u0 -Tlp -man –

Page 70: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

file Utility“Finding Java”

$ file /usr/bin/java

/usr/bin/java: symbolic link to `/etc/alternatives/java’

$ file /etc/alternatives/java

/etc/alternatives/java: symbolic link to `/usr/java/jdk1.7.0_51/jre/bin/java’

$ file /usr/java/jdk1.7.0_51/jre/bin/java

/usr/java/jdk1.7.0_51/jre/bin/java: ELF 64-bit LSB executable, x86-64, version 1

(SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not

stripped

$ file make_logs.sql

make_logs.sql: ASCII C program text

Page 71: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

What is FINDMNT?

• A [somewhat] directory tree view of Linux

• To Install:

$ yum install findmnt –y

$ apt-get install findmnt

71

Page 72: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

findmnt Utility

72

Page 73: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

findmnt Utility

• findmnt -m

73

Page 74: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

What is NCDU?

• Quick utility to gather info on space usage in a directory

• To install:

$ yum install ncdu –y

$ apt-get install ncdu

Simply execute ncdu command in directory that you wish to gather detailed file/directory sizes on

74

Page 75: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

ncdu Utility

75

Page 76: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Linux for the DBA Summary

• Learn to walk before you run

• Command line is essential

• Utilities are your friends

• A few will get you far, choose which ones provide you with what you need.

• Build a knowledge of command line editing tools, such as VIM or Nano and Shell scripting to enhance utilities for full coverage.

• Tough at first, but will become second nature- I promise!

76

Page 77: Essential Linux for the SQL · •1991 project by Linux Torvalds from Finland to create free operating system kernel. •Based on C programming •Over 15 million lines of code in

Thank you!

77