From: | hubert depesz lubaczewski <depesz(at)depesz(dot)com> |
---|---|
To: | Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com> |
Cc: | pgsql-performance <pgsql-performance(at)postgresql(dot)org> |
Subject: | Re: BASH script for collecting analyze-related info |
Date: | 2013-09-30 07:05:11 |
Message-ID: | 20130930070511.GC18650@depesz.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Xenofon Papadopoulos | 2013-09-30 12:45:46 | pg_statio_all_tables columns |
Previous Message | didier | 2013-09-30 06:11:05 | Re: Slow plan for MAX/MIN or LIMIT 1? |