The original task: in my application I need to have 2 different connections to the same database with the same credentials simultaneously. I need that because one connection is used for data transactions, which may be long. And another is for application level locks, which should be instant (obviously I want to see the application level lock as soon as it appears, not after the data transaction ends, when it's too late).
So the question is: how to force PDO to open the second connection in case if I use persistent connections option?
Right now - I retrieve the same connection twice if persistent connections are turned on (desired) and 2 different connections if persistent connections are turned off (just to check)
Thoughts?
One option is to disable persistent connections. Instead, use a lightweight external connection pooler like PgBouncer to reduce connection setup/teardown overhead and re-use backends.
It's best to keep transactions short anyway.