psql -d postgres -c "REASSIGN OWNED BY app TO postgres;"
Transfer object ownership before a role drop
Moves ownership of every object the role owns to postgres, the usual prelude to dropping a role without losing its databases and tables. Follow with DROP OWNED BY to clear the remaining privileges.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.