Is it possible to stop query execution on db server when process that start to run that query killed?

Hello all!
I have process (actually Task) that start an sql transaction, but for some reason (client disconnect) process stopped.
It would be cool if there is a way to stop execution of query on db server.
Thanks

Maybe you can ABORT the transaction in terminate/2 genserver callback. Or maybe you can use Ecto.Multi somehow.

You can use YourAppName.Repo.rollback/1 to stop a database transaction that is in progress.

1 Like

It will be what i’m really needed but method https://hexdocs.pm/ecto/Ecto.Repo.html#c:transaction/2 returns value or error.
So, there are no identificator/pid for transaction.
An example:
Starting task that start transaction:
{:ok, pid} = Task.Supervisor.start_child(:db_worker, fn -> “select sleep(15) from user” end)
Wnen i shutdown task by pid, query still running on the server. And it seems that there is no way to stop it