1. Essential Linux for the SQL
Server DBA
Kellyn PotāVin-Gorman
Technical Intelligence Manager, Delphix
2. 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/kel
lynpotvin
3. 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
6. 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
7. 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
8. 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
9. 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
10. 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
11. 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
12. 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
13. 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
14. 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
15. 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
17. Editors
ā¢ VI/VIM makes you cool- old school
ā¢ Nano
ā¢ eMacs
ā¢ Create a file easily by issuing the touch command
$ touch <filename>
17
18. 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!
19. 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
20. 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
21. 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
22. 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
23. 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
24. 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
26. 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
27. 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
28. 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
29. 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
31. 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
35. 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
36. 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]
37. 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
38. 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)
42. 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.
46. 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
50. 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
58. 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
59. 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
60. 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
62. 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
63. 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
64. 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 ms
216.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
65. What is TCPDUMP?
ā¢ Dump/sniff traffic on a network
ā¢ Another one that may be missing:
$ yum install tcpdump āy
$ apt-get install tcpdump
65
67. 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
68. 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
69. 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 ā
70. 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
71. What is FINDMNT?
ā¢ A [somewhat] directory tree view of Linux
ā¢ To Install:
$ yum install findmnt āy
$ apt-get install findmnt
71
74. 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
76. 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