Last Updated: February 25, 2016
·
5.659K
· dangaytan

Change the owner of all postgresql relations in a database

There are a lot of posts using bash commands selecting the tables from a table in the schema and looping through them.

There is actually a nice command that does this already in Postgresql. Here you have:

REASSIGN OWNED BY <user1> TO <user2>

Reassings all the current database objects owned by user1 to user2.

Here is the documentation of this command:

http://www.postgresql.org/docs/9.3/static/sql-reassign-owned.html

It is weird that it was a long time ago (Postgres 8.4), and many posts were using Postgresql 9.

Anyways... Enjoy :)