>_ IzzyLab

Hands-on task

This task is step 9 of the course “Logs: analysis and housekeeping”

Median SQL query time

medium~5 min

/var/log/db/queries.txt has lines QUERY_ID MS — how many milliseconds each database query took. There is an odd number of values. Find the median time (the middle element of the series sorted in ascending order) and write the number to /root/db_median.txt.

What you'll practise:
  • median
  • sort -n
  • awk
  • array by NR
  • column selection

Topic breakdown

The median is the value in the middle of an ordered series; unlike the mean, a single 20-second query barely moves it, so for a "typical" response time the median is more honest. For an odd number of values N it is element number (N+1)/2 after an ascending sort. The values must be sorted as numbers: a text sort compares character by character and puts 1200 before 33. If a line has extra columns, keep only the numbers first.

What's checked

  1. median computed correctly

What it looks like