Monday, 7 November 2016

One liner to get DB space usage

With this article I'd like to share a clever one liner to calculate the space used by DB file systems provided that the DB uses conventional file systems & not ASM.

I tried it in Linux but it should work in other OS as well after a little tweaking.

So, here is the df output from a Linux DB server after filtering for uXX file systems & /export file system:

[root@~]#  df -m /u?? /export | grep -v usr
Filesystem           1M-blocks      Used Available Use% Mounted on
/dev/mapper/vg02-lv00
                          9072      5444      3168  64% /u00
/dev/mapper/vg02-lv01
                         11088      9303      1222  89% /u01
/dev/mapper/vg02-lv02
                         11088      9303      1222  89% /u02
/dev/mapper/vg02-lv03
                         15119      9374      4978  66% /u03
/dev/mapper/vg02-lv04
                       1239758    252874    923909  22% /u04
/dev/mapper/vg02-lv05
                         35278      5222     28264  16% /u05
/dev/mapper/vg02-lv06
                        455586    381127     51321  89% /u06
/dev/mapper/vg02-lv07
                        332618      1649    314077   1% /u07
/dev/mapper/vg02-lv08
                       1456463   1277325    105168  93% /u08
/dev/mapper/vg02-lv09
                        120952     96470     18339  85% /u09
/dev/mapper/vg02-lv10
                        680355    620184     25614  97% /u10
/dev/mapper/vg02-lv11
                       1995707   1473802    420550  78% /u11
/dev/mapper/vg02-lv12
                        163286    117519     37473  76% /u12
/dev/mapper/vg02-lv13
                         72572     21574     47311  32% /u13
/dev/mapper/vg02-lv14
                        201587    181424      9924  95% /u14
/dev/mapper/vg02-lv15
                        489856    460667      4310 100% /u15
/dev/mapper/vg00-lv02
/dev/mapper/vg02-lv16
                         15119      4877      9475  34% /export

So, to get the space used by these file systems we can type the following one liner:

 df -m /u?? /export | grep -v usr | awk '{sum += $2} END {print sum/1024}'

4812.64

& That's it!

No comments:

Post a Comment

Using capture groups in grep in Linux

Introduction Let me start by saying that this article isn't about capture groups in grep per se. What we are going to do here with gr...