`chown -R` equivalent for PostgreSQL
My answer doesn't answer your question directly, but addresses your method of operation.

You shouldn't be logging in as postgres, just like you shouldn't be logging in as root on your servers. On your servers you should be logging in as real users and be using sudo for the odd occasion that you need superuser privileges. And preferably sudo su - &lt;other_user&gt; rather than just doing everything directly using sudo &lt;command&gt;.

In PostgreSQL we can implement more fine-grained policies.

Create a role structure something like:

create role admin noinherit;
grant &lt;owner&gt; to admin;
grant admin to &lt;real_person&gt;;


Then login as &lt;real_person&gt;.

To your scripts to deploy into &lt;owner&gt;, add the first line:

set role &lt;owner&gt;;


Then you should never have the problem again that you describe in your question.

And you never need to login as a superuser -- unless you need to create new schemas or users.