#!/bin/bash

set -e

psql -AtF',' -c 'SELECT datname FROM pg_database WHERE datistemplate = false;' | rg -v rdsadmin | 
  while read -r line 
  do
    echo "running for $line"

    psql -d "$line" -AtF',' -c '
SELECT pg_class.relname
FROM pg_class, pg_index
WHERE pg_index.indisvalid = false
AND pg_index.indexrelid = pg_class.oid;'

    echo
  done

#psql <<EOF
#EOF

#SELECT pg_class.relname
#FROM pg_class, pg_index
#AND pg_index.indexrelid = pg_class.oid;
