How do I modify the owner of all tables in a PostgreSQL database?
I tried ALTER TABLE * OWNER TO new_owner but it doesn’t support the asterisk syntax.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
See
REASSIGN OWNEDcommandNote: As @trygvis mentions in the answer below, the
REASSIGN OWNEDcommand is available since at least version 8.2, and is a much easier method.Since you’re changing the ownership for all tables, you likely want views and sequences too. Here’s what I did:
Tables:
Sequences:
Views:
You could probably DRY that up a bit since the alter statements are identical for all three.