I know this has been asked before, but for my case it looks like it doesnt fit.
Our postgres db is running replicated (which might lead to the problem). This is the code