Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres: see statement generated implictly by FKs?

Tags:

postgresql

I'm using Postgres 9.6 in Ubuntu.

With many tables and many foreign keys, when I delete certain data it generates the respective commands implicitly to clean up the foreign relations.

This can be "seen" when a long running DELETE statement is interrupted with e.g. CTRL-c it shows which "background" statement was running.

Is there way to see all the statements which are generated/executed in the background? The log_statement configuration does not show them either.

like image 288
mark Avatar asked Jun 07 '26 20:06

mark


1 Answers

There's no built-in way, but it's possible with an ExecutorStart_hook.

The auto_explain contrib module can trace "nested" statements. See auto_explain.log_nested_statements. I'm not sure if it ignores FK checks or considers them; the nested statements feature is mainly used for things like PL/PgSQL.

like image 190
Craig Ringer Avatar answered Jun 10 '26 11:06

Craig Ringer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!