Skip to content

Instantly share code, notes, and snippets.

@pmargreff
Last active October 30, 2019 18:35
Show Gist options
  • Save pmargreff/0462c69dd67ede714ab00a81063508cb to your computer and use it in GitHub Desktop.
Save pmargreff/0462c69dd67ede714ab00a81063508cb to your computer and use it in GitHub Desktop.
Create queries to reset postgres database owners (excluding protected schemas/tables).
SELECT 'ALTER TABLE '|| schemaname || '.' || tablename ||' OWNER TO username;'
FROM pg_tables WHERE NOT schemaname IN ('pg_catalog', 'information_schema')
ORDER BY schemaname, tablename;
SELECT 'ALTER SEQUENCE '|| sequence_schema || '.' || sequence_name ||' OWNER TO username;'
FROM information_schema.sequences WHERE NOT sequence_schema IN ('pg_catalog', 'information_schema')
ORDER BY sequence_schema, sequence_name;
SELECT 'ALTER VIEW '|| table_schema || '.' || table_name ||' OWNER TO username;'
FROM information_schema.views WHERE NOT table_schema IN ('pg_catalog', 'information_schema')
ORDER BY table_schema, table_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment