Skip to content

Instantly share code, notes, and snippets.

@we4tech
Last active May 5, 2022 19:51
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 we4tech/857e93b179fbaec439ae246acbb21901 to your computer and use it in GitHub Desktop.
Save we4tech/857e93b179fbaec439ae246acbb21901 to your computer and use it in GitHub Desktop.
PostgresSQL alter owner for all tables
-- Geneate query
SELECT format('alter table %s owner to root;', tablename) FROM pg_tables WHERE schemaname = 'public'
-- On psql execute \gexec to eval all above queries.
\gexec
-- Generate query for sequences
select format('alter sequence %s owner to root;', sequencename) FROM pg_sequences WHERE schemaname = 'public';
\gexec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment