Raghu On Tech

Pro tips on managing data at scale

Linux Tips And Tricks For DBA’s

by | Jun 7, 2018 | 0 comments

In this blog post I am going to discuss few Linux tips and tricks that I use every once in a while to troubleshoot problems or to understand existing environment.


Finding Top 10 Largest Files on the System Including Full Path:


If you run into a file system full condition and need to figure out which files are occupying the most space, below command will save your day. Of course there are many other ways to do this exact same thing.

find / -printf ‘%s %p\n’ 2>/dev/null| sort -nr | head -10

Above command basically says, print the size and name of the file with full path, if any file access resulted in an error throw the error to recycle bin, then perform a numerical sort in descending order, then print the 10 files at the top of the list.

Please pay special attention to “2>/dev/null” at the end of the find command. It will basically remove all the noise or chatter due to file permission issues to /dev/null so that you can focus on the important information on the screen. Here number 2 is the file descriptor, by default it stands for standard error messages.

A sample output of the above command is shown below.


How to Get Information About Filesystem Properties:


tune2fs command is a great tool to obtain information about supported filesystem(FS) features, mount info, FS state, FS Block size, FS Crash Info etc. Most probably you will be needing root access to run this command and might be helpful to you when troubleshooting issues related to storage.

grep Command Paragraph Mode Simulation in Linux:


If you were a DBA before commodity hardware and Linux became mainstream for Db2 servers and VM’s, you might have worked a lot on AIX machines. There is a good chance that you may have used grep in paragraph mode by using -p flag.

I am used to querying database info from database directory as follows. Displaying the whole database entry is important to me to look at stuff such as, if its a local or remote database, catalog info and alternate server info etc.

db2 list db directory|grep -ip “<DBNAME>”

However on Linux grep does not support paragraph mode, I can think of multiple ways to overcome this. I am going to show 3 different ways to accomplish this in this blog post.

Method 1 (perl):

In the first case, we are going to use perl. Below perl command simply says that -00 (turn the input into paragraph mode) -n (loop through the input) -e (execute the commands from command line rather than a script file) and finally print if the paragraph matches a regular expression case insensitively (i flag).


Method 2 (awk):

Below awk example is very similar to the perl example above. Here we are changing the input (RS) and output record separators (ORS) to two newlines and input (FS) and output field separators (OFS) to one new line.


Method 3 (awk):

Finally we play a little trick with awk, here we are using awk range match and print. Below command simply says, match the string TEST and until you find the next blank line keep printing. This approach is not as clean as the other two but works alright.



Monitor Open Ports on Remote Server:

This will be especially useful when you are troubleshooting connection problems. I can think of a couple of ways to check if a port on the remote Db2 server is open or not.

Method 1 (nmap):

Use nmap to scan the port or range of ports on a host or range of hosts. nmap is a very powerful tool used by network admins, you should at least check with your SA before you run this on your environments. Lot of intrusion detection software’s prevent utilities that scans ports from running. nmap comes with a lot of options, I am going to show something basic…


In the above command I am basically telling nmap to scan all the tcp ports on host that are not privileged. Remember on Unix systems ports 1-1024 are known as privileged and should only be used by root for necessary services. -sV option tells nmap to detect the service name for the port if one exists. In the above output you can see that port 50000, the default Db2 port is open.

There are tons of options to play around with nmap command, such as group pings, host discovery, skipping port scans, specifying DNS servers etc. I never had to mess around with many of the options given my technical role, but when troubleshooting an outage or a critical issue your role does not matter. The more you know the better you are equipped to confront the problem.

So nmap is a great tool to know if you are trying to identify all the open ports on a host or to check if a service is running on a host.


Method 2 (Telnet):

This method is more familiar to the DBA’s and less intrusive than nmap command. telnet command lets you remotely connect to a port so that you can validate the connection. Lets take a simple example below, to check the connectivity to host on port 50050.

As you can see from the above output, telnet was able to connect to the host on port 50050. If you enter a string or input at the prompt, db2sysc will recieve it and probably put some warnings in db2diag.log file. I have observed this behavior in the past with HADR ports.

To terminate the telnet connection you need to enter ^] or (ctrl+v)] on your windows machine.


Monitor the ports locally:


Your friend here is netstat command. In the below command -tpln flags tell netstat command to

-t –> show only tcp ports

-p –> show process id and service name attached to the socket

-l –> show only listening sockets

-n –> show numerical addresses for IP and port numbers rather than (hostnames and service names).

From the above output, you can confirm that Db2 is listening on port 50000 locally on your server.


There are lots of other tips and tricks that I can think of, I will be adding them to this blog post every now and then. Keep an eye out…


Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share This