Created
February 12, 2020 09:22
-
-
Save gtors/a8bd57ad945fcecd5c882734a28a7919 to your computer and use it in GitHub Desktop.
PostgreSQL move all extensions into separate schema
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
| DO $$ | |
| DECLARE | |
| _name TEXT; | |
| _ver TEXT; | |
| BEGIN | |
| -- Loop over all extensions in `public` schema (except timescaledb) | |
| -- and move it into `ext` schema | |
| FOR _name, _ver IN ( | |
| SELECT | |
| extname, | |
| extversion | |
| FROM | |
| pg_extension ex | |
| INNER JOIN | |
| pg_namespace ns ON ns.oid = ex.extnamespace | |
| WHERE | |
| nspname = 'public' AND extname not in ('timescaledb') | |
| ) LOOP | |
| RAISE NOTICE 'Counter: %: %', _name, _ver; | |
| EXECUTE 'UPDATE pg_extension SET extrelocatable = TRUE WHERE extname = ''' || _name || ''''; | |
| EXECUTE 'ALTER EXTENSION ' || _name || ' SET SCHEMA "ext"'; | |
| EXECUTE 'ALTER EXTENSION ' || _name || ' UPDATE TO ''' || _ver || 'next'''; | |
| EXECUTE 'ALTER EXTENSION ' || _name || ' UPDATE TO ''' || _ver || ''''; | |
| END LOOP; | |
| END $$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment