New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setReadOnly does not work with pgbouncer and transaction pooling mode #848
Comments
haven't looked at too many details, but it seems reasonable in autocommit = false mode this would be possible, yes. |
Is there any update on this? I am trying to use pg bouncer in transaction pooling mode and running into this issue as well |
Pull requests are welcome |
Got same problem here. Any chance we get fix? |
So the harder problem here is creating the test case. Can someone provide the specification of what they want this to do, and a configuration for pgbouncer which exhibits this ? |
It appears setting this to 1 will resolve this particular issue, the problem is I don't know if it in turn induces any other issues
@davecramer I'd love to try to make a PR but I am not even sure where to start. Pg Bouncer in transaction mode pools the connections and expects that there are no session level things set. So let's take just the READ ONLY issue, line 699, for instance. A client connects, that gets invoked on the session, work is done. Then Pg Bouncer puts that connection that can only perform READ ONLY work into its pool another connection takes it. If that connection tries to perform READ WRITE work, it bombs out. Like @eshkinkot mentions would I would like to see is that TRANSACTION READ ONLY not be applied to the session but instead to the particular transaction that needs it. So instead of:
It would instead be
So everything that is currently stored on the session gets pushed down to the actual transaction that needs it so that connection can be re-used with a clean session state. |
I was thinking same here. Already set up: |
@jamestenglish , I think the key point is to add
Does it make sense? |
@vlsi That is a very helpful starting point, I'll see what I can do about making an at least somewhat repeatable failure state. |
Just adding, since it wasn't mentioned here before, that the same should probably be done for transaction isolation level. It's also currently set for the session (but can be set as part of the begin transaction) |
Hi all, I have a question related to this topic here and since you are experts in this field you probably can help me.
Given that the I am asking this since I want to use session variables for row-level security policies and if that would work this way with pgbouncer in transaction pooling mode. |
Further:
|
This post on the postgres mailing list clarified a lot of things for me and problably is also helpful for this issue here:
Also have a look a the example in the post. |
If autocommit is set to false, read only will be set on begin transaction. If autocommit is true, it will continue to be managed at session level. The queries to change session have been cached to avoid re-parsing each time readonly value changes. pgjdbc#1228 pgjdbc#848
* feat: read only transactions If autocommit is set to false, read only will be set on begin transaction. If autocommit is true, it will continue to be managed at session level. The queries to change session have been cached to avoid re-parsing each time readonly value changes. #1228 #848 * feat: read only transactions * checkstyle and hamcrest test import * add connection property with 3 options to control read only behavior * fix missing property methods on BaseDataSource * avoid redundant static modifier * more loosely couple read only hints to backend * return default read only mode from data source. * avoid case conversion
Hi Guys, |
From what I can tell #1252 committed a fix for this and it was released. See
Does this not work or do what you require ? |
Hi Dave, How can I ignore the read-only transaction with the new feature implemented? I see the PGProperty class but don't know how to set them on my spring boot application. Thank you again. |
@azraino I think DataSources can take any property. There are setters and getters for the properties in the datasource |
@davecramer Can you please confirm that the documentation on https://jdbc.postgresql.org/documentation/head/connect.html is up to date ? |
readOnly = boolean Put the connection in read-only mode |
But is should be readOnlyMode and not readOnly `READ_ONLY_MODE("readOnlyMode", |
ah, good point. You are correct. Care to send in a PR ? |
change the documentation by completing documentation with parameter that didn't exist the change is due to pgjdbc#848
@davecramer please find the PR for documentation fix. |
change the documentation by completing documentation with parameter that didn't exist the change is due to #848 Co-authored-by: Mohamed Amghari <med.amghari@gmail.com>
https://github.com/pgjdbc/pgjdbc/blob/REL42.1.1/pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java#L698
Currently setReadOnly change mode for all session, not for transaction. It breaks work through pgbouncer in transaction pooling mode.
Can this be changed? For example like in psycopg2 python driver, see:
https://github.com/psycopg/psycopg2/blob/2_7_1/psycopg/pqpath.c#L504
psycopg2 can set read only as part of BEGIN clause, like:
BEGIN READ ONLY;
this work perfectly over pgbouncer in transaction pooling mode too.
The text was updated successfully, but these errors were encountered: