I have a very long running function, which is an import process, and it is currently in the middle of running. It's been running for 10 hours, and according to my calculations - will take about 16-24 hours to finish.
However, one of the reasons it is taking so long is because one of the tables it is using for a lookup (as well as writing to) is not indexed properly.
I cannot interrupt the function, since that would cause it to roll back the transaction and undo its last 10 hours of work. However, I cannot create the index while it is mid-operation because it is retaining the lock on the table.
Is there any way I can force Postgres to obtain an explicit lock on the table and create the index (pausing the function execution while it is creating it)?
If not, is there anyway I can interrupt the function without having it roll back the work it did so far?