Re: BASH script for collecting analyze-related info - Mailing list pgsql-performance

From hubert depesz lubaczewski
Subject Re: BASH script for collecting analyze-related info
Date
Msg-id 20130930070511.GC18650@depesz.com
Whole thread Raw
In response to BASH script for collecting analyze-related info  (Ken Tanzer <ken.tanzer@gmail.com>)
Responses Re: BASH script for collecting analyze-related info
List pgsql-performance
On nie, wrz 29, 2013 at 02:09:07 -0700, Ken Tanzer wrote:
> p.s.,  This script runs fine on my computer (Ubuntu 13.04), but on a Fedora
> 11 machine it dies with
>
> pg_analyze_info.sh: line 18: unexpected EOF while looking for matching `)'
> pg_analyze_info.sh: line 57: syntax error: unexpected end of file
>
> If anyone knows why, or encounters a similar error and fixes it, please let
> me know!

Fixed by changing it to:

#v+
# Get tables
TABLES=$(
cat <(
# Indexed tables
egrep -o 'Index Scan using \b[a-zA-Z0-9_-]* on [a-zA-Z0-9_-]*' $FILE  | cut -f 6 -d ' '
) <(
# Scanned Tables
egrep -o 'Seq Scan on \b[a-zA-Z0-9_-]* ' $FILE | cut -f 4 -d ' '
) | sort | uniq

)
#v-

That is - I removed the "\" at the end - it's of no use.

There are couple of issues/questions though:
1. instead of: "SELECT 'Postgres Version';" it's better to use \echo Postgres Version
2. why is there union with nulls in the last query?
3. When extracting table names you are missing:
   a. Index Scan Backward
   b. Bitmap Heap Scan
4. When extracting index names, you're missing Index Only Scans and Index Scan
   Backwards.
5. The whole script will fail if you're using table names with spaces (not that
   I think this is sane, but the script should recognize it)
6. It's generally better to use
   if [[ ...
   than
   if [ ...
   reason - [[ is internal for bash, while [ is fork to external program
7. instead of | sort | uniq, it's better to use sort -u
8. usage of all-upper-case variables in bash is (by some, more
   bash-skilled people, like on #bash on irc.freenode) frowned upon.
   all-uppercase is supposed to be for environment variables only.

All in all - looks pretty good.

depesz


pgsql-performance by date:

Previous
From: didier
Date:
Subject: Re: Slow plan for MAX/MIN or LIMIT 1?
Next
From: Xenofon Papadopoulos
Date:
Subject: pg_statio_all_tables columns