Skip to content

Instantly share code, notes, and snippets.

@dexalex84
Created November 19, 2016 08:40
Show Gist options
  • Save dexalex84/967047723de18e78bb8e12c189388b30 to your computer and use it in GitHub Desktop.
Save dexalex84/967047723de18e78bb8e12c189388b30 to your computer and use it in GitHub Desktop.
PostgreSQL Set some tables to unlogged mode
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