When moving websites between servers the database user often changes. While it is easy to dump and restore database dumps using pg_dump and pg_restore this might lead to invalid table ownership's on the new host. This bash script will easily fix this issue.
if [ "$EUID" -ne 0 ]
then echo "This program should be run with sudo: sudo alter "
if test $# -lt 2; then
echo "Usage: sudo $0 "
tables=`psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" $database`
for tbl in $tables ; do
psql -c "alter table $tbl owner to $new_owner" $database ;
sudo alter unixsys unixsys