From bfe2239dc19849c5269e780089c1a7dfb2405f2e Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 10 Dec 2014 22:45:21 +0000 Subject: [PATCH] pg_count --- bin/pg_count | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 bin/pg_count diff --git a/bin/pg_count b/bin/pg_count new file mode 100755 index 00000000..890c7c74 --- /dev/null +++ b/bin/pg_count @@ -0,0 +1,25 @@ +#!/bin/bash +# NB affiche les tables avec leur nombre d'enregistrement d'une base de donne +# postgres +dbs="$@" +[ -z "$dbs" ] && dbs=`psql -l | perl -ane 'print $F[0]."\n" if $i++>2 and /^\s*\w/ and !/^\s*template\d/'` +for db in $dbs; do + + [ "$db" == "" ] && db=`whoami` + + echo "* $db" + + tables=`psql $db -Atc '\dt' | grep -v '^No relations found' | cut -d\| -f2` + length=`echo "$tables" | perl -pe 's/^(.*)$/length($1)/e' | sort -n -r | head -1` + ( + for tb in $tables; do + + echo "SELECT '$tb',count(*) FROM $tb;" + + done + ) | psql -At $db | awk -F'|' '{printf "%-'$length's %9d\n",$1,$2}' + + echo + shift + +done -- 2.47.3