# No specific table, no specific index, either we have a specific database,
# or were told to do all databases. Do it!
else
sql="SELECT distinct tablename FROM pg_indexes WHERE tablename NOT LIKE 'pg_%'"
# We set IFS to newline only so that the for-loops won't misinterpret
# spaces in the lists we retrieved via psql. Note also the use of
# regclass to handle spaces, mixed-case names, and schema awareness.
sql="SELECT DISTINCT c.oid::pg_catalog.regclass FROM pg_catalog.pg_index x JOIN pg_catalog.pg_class c ON c.oid = x.indrelid JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid WHERE nspname NOT LIKE 'pg\\\\_%'"
IFS='
'
for db in$dbname;do
# Only print which database we're currently reindexing if not in
# quiet mode, and we're doing more than one database.
["$alldb"]&&[-z"$quiet"]&&echo"Reindexing $db"
# Ok, reindex every table in the database. Use the same method
# we used to get a list of databases, and get a list of tables in this
# database that we may reindex.
tables=`$PSQL$PSQLOPT-q-t-A-d$db-c"$sql"`
IFS='
'
# Get a list of non-system tables that have indexes.