Нашел ответ тут -
https://fraserclark.net/2023-10-06-rds-oids/
Вот скрипт, который он предложил:
#!/bin/bash
# I found without setting this the script would fail
export PGPASSWORD=xxxx
# Define your query
QUERY="SELECT current_database(),n.nspname ,c.relname, c.relkind from pg_class c, pg_attribute a, pg_namespace n where c.oid = a.attrelid and a.attname = 'oid' AND c.relnamespace = n.oid AND n.nspname NOT IN ('pg_catalog', 'information_schema') and c.relkind = 'r';"
# Get a list of all databases in the RDS cluster
DATABASES=$(psql -h hostname.eu-west-2.rds.amazonaws.com -p 5432 -U postgres -c "SELECT datname FROM pg_database WHERE datname NOT IN ('template0', 'template1');" -t)
# Loop through each database and execute the query
for DB in $DATABASES; do
echo "Running query on database: $DB"
psql -h qa-hostname.eu-west-2.rds.amazonaws.com -t -c "$QUERY" -U postgres -d $DB
done