あなたは正しい順序でそれらを変更する必要があります私は恐れています。あなたは最初のテーブルを参照するためhttps://www.postgresql.org/docs/current/static/catalog-pg-constraint.htmlとループを選択し、残りの部分を変更することができ :
t=# create table s134(i int primary key, e int);
CREATE TABLE
t=# create table s135(i int references s134(i), e int primary key);
CREATE TABLE
t=# alter table s134 add constraint c1 foreign key (e) references s135(e);
ALTER TABLE
t=# alter table s134 set unlogged;
ERROR: could not change table "s134" to unlogged because it references logged table "s135"
t=# alter table s135 set unlogged;
ERROR: could not change table "s135" to unlogged because it references logged table "s134"
をしかし、あなたはどんなことを達成できないだろう:すべてのことで
begin;
do
$$
declare
_r record;
_t text;
begin
for _r in (
select relname,conrelid
from pg_constraint
join pg_class c on c.oid = conrelid
where confkey is not null
order by conrelid desc
-- Order by oid with logic that you should start from latest added objects to earliest - of course it does not garantee anything
) loop
_t := format('alter table %I set unlogged',_r.relname);
raise info '%',_t;
execute _t;
end loop;
for _r in (select tablename from pg_tables where tablename like 's%' and schemaname = 'public') loop
_t := format('alter table %I set unlogged',_r.tablename);
raise info '%',_t;
execute _t;
end loop;
end;
$$
;
rollback;
あなたは、再帰的なFKに持っている場合、それは失敗を意味します私は信じています。
また、不正なシャットダウンまたは障害が発生した後に、未ログインのテーブルが切り捨てられることを忘れないでください。
そして最後に、あなたは「すべての変換の後に」と言う - あなたが作成した場合などに変換、多分あなただけのログに記録されないそれらを作成する必要があります。..
、;もちろん
をあなたがそれらをドロップ前FKSにを生成するためのクエリを実行する必要があります。そして、
すべての制約を削除するスクリプトを生成私はすべてのテーブルを未記録にすることができましたが、テストの実行は〜20%遅くなりました。だから、それをしないでください。 – mshutov