These are the ten most important commands to know as a DBA working in a Linux environment. This is not specific to any Linux distribution or single database platform necessarily, however, I have added some really good links specific to MSSQL Server running on Linux at the end. The commands presented here are available for all Linux flavors and typically are pre-installed.
This article assumes a basic working knowledge of the Linux command line interface i.e., logging in, basic directory structure and navigation, and basic file management.
Here is a link to a basic primer on Linux/Unix to get you up to speed in case you need it:
As we move forward there are two special tools that will help you immensely. These are necessary tools that every Linux user should be aware of.
Man (manual) pages are help files. Personally, I’ve never used an MS help file, I have used man pages extensively for over twenty years. They are a quick and concise source of documentation that take only a few seconds of skimming to find what you need. They follow a simple syntax: man command_name
Vi is actually an application so I’m not really counting it in the list of ten either. Obviously, a text editor is an essential tool. Vi is universally available and is quite functional. It has a somewhat steep learning curve and can be cumbersome, especially at first. However, it is fast, clean, and was designed to be used in a command line environment. Refer to the following tutorial.
- ssh (Secure Shell)
It’s often necessary to log into a Linux system remotely, whether it’s in a different geographical location, or you just don’t feel like walking to the other side of the data center, ssh is a Linux command that allows you to establish a secure remote connection to another Linux based system. Provided security features ( passwords and or encryption keys) are configured on both systems you can administer the remote system as if it were local using the now familiar terminal. Security is the main concern here as ssh encrypts your traffic in order to protect the two systems.
- cat and more/less
The ‘cat’ commands most basic use is to simply view a text file. It’s real strength is in its ability to connect (concatenate) multiple text files and send them as an input to standard output. This is a simple yet essential tool, especially for aggregating data from multiple sources. The downside to ‘cat’ when viewing a file is that it simply dumps the file contents to your screen with no control. Because of this. I’ve included the ‘more’ and ‘less’ commands as they can be used to view a single file by themselves just like ‘cat,’ but they also allow you to view the cat output one page at a time.
As an example:
$ cat file1.txt file2.txt | less
Notice the | (pipe) – This command string will concatenate (cat) file1.txt and file2.txt and pipe or send them to the less command and allow you to page through the information at your own pace instead of just dumping it all on your screen too quickly to read.
This is another utility that allows the admin to view text files. As the name implies, ‘tail’ looks at the end of a file, rather than the whole file. The benefit to this is that it can be used to actively monitor the file/log as it changes. That is to say, it allows you to watch the output of whatever process is logging the data as the file is being written.
tail -f /var/log/logfile.txt
ps displays a snapshot of user and system processes that are currently running. It displays the user who initiated the process, the process ID, percentage of cpu usage, percentage of memory usage, and more depending on the options you use with the command. The information is helpful to quickly determine if a process is running, or if it is taking up more resources than might be reasonable.
For real-time monitoring of Linux processes ‘top’ is very helpful. This command shows a great deal more information than ps does with many options for displaying other system resource information. It’s a good idea, as always, to know the available options (man) to pass to the command, as well as hotkeys to use while it’s running in order to maximize the power of this tool.
For monitoring output activity of each available processor, mpstat is a great tool. Offering a number of reporting options, the quick default is a simple utilization report. The available level of detail is pretty impressive, however, the basic information is enough to determine if processor resources are being overtaxed.
Linuxconfig.org – top
df shows how much disk space the file system is using and how it is distributed across volumes. Depending on your distribution the default information may differ, however, many command options can be passed along to customize the information displayed.
du displays estimated file or directory space usage. It takes the argument of a directory or a file. If no path is provided it will use the present working directory. With both df and du the -h option provides “human readable” output…bytes rather than blocks
Ifconfig (might be called ip addr depending on your distribution) displays basic information about your network interfaces and allows some control over starting and stopping them. This is usually one of the first steps towards troubleshooting potential network issues.
One of the most powerful commands in Linux is grep. With the impossible amount of information to dig through in Linux systems narrowing down results using customized criteria is a huge timesaver. Whether you wish to find a particular string(s) in a file, a specific running process or service, audit a log file, etc.., the uses are quite extensive.
Configuration and log files:
Knowing if a particular process is running, how much of a given resource is being utilized or which are available are absolutely essential.
A very simple example: If you want to find a running process whose name begins with rpc and show detailed information:
ps -aux | grep rpc*
grep can do this with a lot of different data sources. Additionally, grep utilizes regular expressions or, similarly, with egrep you can use extended expressions. When combined with the ‘sed’ utility this becomes a powerful set of search and editing tools. Make your life easier, read the following tutorial.
Beyond the list:
There are a couple of other extremely helpful commands. They are a little more advanced, however learning to use them will certainly be very helpful.
systemctl is a great tool for displaying and controlling system processes. It’s kind of advanced and can be really dangerous, however all the cool kids are using it.
Dstat might have to be installed, but it is highly recommended as it has nearly every reporting tool you might need.
Obviously there are many more tools available either installed by default, available freely for download, or from third party commercial vendors. Your particular platform and personal preferences will determine which tools best suit your needs. This list is far from comprehensive, but it is a good start towards increasing competency and reducing downtime.
Unix commands for DBAs – Oracle-Base: knowledge base article
Microsoft’s attempt at being helpful – https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-troubleshooting-guide
A really great video. Includes all the necessary tools, goes into setup of MSSQL and even discusses PowerShell in Linux (in beta at the time of this writing). I highly recommend watching it.