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