Re: Adding foreign key constraints without integrity check?

Поиск
Список
Период
Сортировка
От Florian G. Pflug
Тема Re: Adding foreign key constraints without integrity check?
Дата
Msg-id 44967DBF.9050308@phlo.org
обсуждение исходный текст
Ответ на Adding foreign key constraints without integrity check?  (Wes <wespvp@syntegra.com>)
Ответы Re: Adding foreign key constraints without integrity  (Wes <wespvp@syntegra.com>)
Список pgsql-general
Wes wrote:
> Is there a way to add a foreign key constraint without having to wait for it
> to check the consistency of all existing records?  If a database is being
> reloaded (pg_dumpall then load), it really shouldn't be necessary to check
> the referential integrity - or at least I should be able to stipulate that I
> am accepting that risk.
You could create the fk-constraints _first_, then disable them, load
the data, reindex, and reenable them afterwards.

pg_dump/pg_restore can enable and disable fk-constraints before restoring
the data, I believe. It does so by tweaking the system catalogs.

The only problem I can see is that creating the fk-constraints might create
some indices too. But maybe you can manually drop those indices afterwards - I
don't know if the fk really _depends_ on the index, or if it creates it only
for convenience.

greetings, Florian Pflug


В списке pgsql-general по дате отправления:

Предыдущее
От: Alban Hertroys
Дата:
Сообщение: Re: A slow query - Help please?
Следующее
От: "Gurjeet Singh"
Дата:
Сообщение: Re: A slow query - Help please?