Last active
August 29, 2015 13:57
-
-
Save adunstan/9770065 to your computer and use it in GitHub Desktop.
Vacuum a PostgreSQL schema's tables via dblink
This file contains 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
-- requires dblink extension the be installed | |
-- vacuum a schema via dblink | |
create or replace function vacuum_schema(schemaname text) | |
returns void | |
language plpgsql | |
as | |
$func$ | |
declare | |
rec record; | |
begin | |
-- fix connstr here to suit | |
perform dblink_connect('dbname='|| current_database()); | |
for rec in | |
select relname | |
from pg_class c | |
join pg_namespace n | |
on c.relnamespace = n.oid | |
and n.nspname = schemaname | |
where c.relkind in ('r','m') | |
loop | |
perform dblink('VACUUM ' || quote_ident(schemaname) || '.' | |
|| quote_ident(rec.relname)); | |
end loop; | |
perform dblink_disconnect(); | |
end; | |
$func$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment