Re: What have I done!?!?!? :-)

From: Jan Wieck <jan(at)wi3ck(dot)info>
To: Perry Smith <pedz(at)easesoftware(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: What have I done!?!?!? :-)
Date: 2022-04-07 15:10:44
Message-ID: 70c17f9b-1e6e-5dc2-ec1b-a60f9000026c@wi3ck.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 4/6/22 18:25, Perry Smith wrote:
> Rather than explain how I got here, I’ll just explain the state I’m in.
> ...
>
> I’m using Active Record with the psql adapter.  It has a
> disable_referential_integrity which takes a block of code.  When the
> block of code exists, the constraints are put back.  At least, that is
> what I thought.
>
> I’m wondering if the disabled constraints are still disabled somehow.
>  If so, how would I check for that and how would I turn them back on?
>  Or am I way off in the weeds?

That depends on how exactly Active Record does this disabling of
constraints. There is a GUC in PostgreSQL 'session_replication_role'.
Setting that to value 'replica' will do precisely that as a side effect.
Its primary purpose is for logical replication systems (like Londiste,
Slony and logical decoding based ones) to disable user triggers and
referential integrity actions (like on delete cascade) as well as
integrity checking under the assumption that those actions have been
performed on the origin database and will be replicated as well or are
unnecessary.

Note that changing that setting requires PostgreSQL superuser privilege.
Precisely because of the danger of getting your database into an
inconsistent state.

So **IF** Active Record is using that feature, then it can dump any
amount of garbage into your PostgreSQL database and PostgreSQL will
happily accept it with zero integrity checking.

Best Regards, Jan

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter J. Holzer 2022-04-07 16:55:34 Re: Resources on modeling ordered hierachies?
Previous Message Andrus 2022-04-07 13:16:17 How to get updated order data