Created
November 19, 2016 08:40
-
-
Save dexalex84/967047723de18e78bb8e12c189388b30 to your computer and use it in GitHub Desktop.
PostgreSQL Set some tables to unlogged mode
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
do | |
$$ | |
declare var_sql character varying(8000); | |
begin | |
for var_sql in | |
select | |
'alter table '|| t1.table_schema||'."'||t1.table_name||'" set unlogged' | |
from | |
INFORMATION_SCHEMA.tables t1 | |
join | |
pg_namespace sch on ( | |
sch.nspname = t1.table_schema | |
) | |
join | |
pg_class t2 on | |
( | |
t2.relname = t1.table_name | |
and | |
t2.relnamespace = sch.oid | |
) | |
join | |
information_schema.schemata sc ON( | |
sc.catalog_name = t1.table_catalog | |
and | |
sc.schema_name = t1.table_schema | |
) | |
where | |
t1.table_type like 'BASE TABLE' | |
and | |
sc.schema_owner <>'postgres' | |
and | |
t1.table_schema = 'TEMP' | |
AND | |
relpersistence <> 'u' | |
loop | |
raise notice ' %',var_sql; | |
execute var_sql; | |
end loop; | |
end; | |
$$ | |
language plpgsql; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment