Last active
June 2, 2021 10:41
-
-
Save garciparedes/6c134536756415755644522fb09b2f47 to your computer and use it in GitHub Desktop.
Remove roles with name pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # If out of memory is raised: https://stackoverflow.com/a/43530569/3921457 | |
| do $$ | |
| declare tablename text; | |
| declare rolename text; | |
| begin | |
| for tablename in select datname FROM pg_database where datname like 'test_%' | |
| loop | |
| execute 'DROP DATABASE ' || tablename; | |
| end loop; | |
| for rolename in select rolname from pg_roles where rolname like 'test_%' | |
| loop | |
| execute 'DROP ROLE ' || rolename; | |
| end loop; | |
| end $$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment