Skip to content

Instantly share code, notes, and snippets.

@kossoff
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kossoff/9cdafab6983fb503b6ec to your computer and use it in GitHub Desktop.
Save kossoff/9cdafab6983fb503b6ec to your computer and use it in GitHub Desktop.
Change owner to all tables in PostgreSQL database
#!/bin/sh
dbname=$1
dbuser1=$2
dbuser2=$3
for TABLE in `psql ${dbname} -U ${dbuser1} -c "\dt *.*"|grep ${dbuser1}|cut -f 3` ;
do
psql -U ${dbuser1} -c "ALTER TABLE ${TABLE} OWNER to ${dbuser2}";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment