From: hubert depesz lubaczewski <depesz@depesz.com>
To: Ken Tanzer <ken.tanzer@gmail.com>
Cc: pgsql-performance <pgsql-performance@postgresql.org>
Subject: Re: BASH script for collecting analyze-related info
Date: Mon, 30 Sep 2013 09:05:11 +0200
Message-ID: <20130930070511.GC18650@depesz.com> (raw)
In-Reply-To: <CAD3a31Uah=tszPw6hD8PKdzTpVT6bjT1KsX5ooKPZ69+4gFi+Q@mail.gmail.com>
References: <CAD3a31Uah=tszPw6hD8PKdzTpVT6bjT1KsX5ooKPZ69+4gFi+Q@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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
--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: depesz@depesz.com, ken.tanzer@gmail.com
Subject: Re: BASH script for collecting analyze-related info
In-Reply-To: <20130930070511.GC18650@depesz.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox