Replies: 4 comments 2 replies
-
As long as the query does not take a lock you should be fine. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your answer, Dave. Sometimes, my app fails when it is running: cannot execute UPDATE in a read-only transaction. But I don't use transactions in the relevant code block, which makes me feel very confused. So I tried to get a detailed log of the transaction from postgres:
|
Beta Was this translation helpful? Give feedback.
-
sorry for the late reply, what is 20912, is that the pid ? |
Beta Was this translation helpful? Give feedback.
-
It definitely seems like something specific to your application. If you're sharing database connections directly between threads, you need to be careful to reset the state of the connection. PostgreSQL even has a special command that does just that called If you are manually sharing connections and each is modifying the state with things like transaction management, you probably want to issue a ROLLBACK / DISCARD to reset the connection before a different thread uses a connection. Some connection pools handle this type of thing for you. You do need to be careful not to concurrently use a JDBC connection with multiple threads. To debug, try adding some logging before you SQL execution in the Java program to log the current thread, connection ID, and call stack. That should give you more information on where the problem is happening. |
Beta Was this translation helpful? Give feedback.
-
My web application uses jdbc to connect to the database. When I first query the database with a read-only transaction, will subsequent updates be affected by previous read-only transactions?
Beta Was this translation helpful? Give feedback.
All reactions