0

I am trying to debug some Java code that is a client of a PostgreSQL database by stepping through the Java code. I have found a query that is being executed by the client code that is not returning the expected results. In order to understand why the code is failing, I'd like to be able to manually run the query (eg, in pgAdmin or from psql command line tool) to see what the contents of the database is.

The problem with the above is that the Java code I'm trying to debug is executing within an uncommitted transaction. When I paste the query into pgAdmin it fails in a completely different way because it doesn't have visibility into the same data snapshot that the code being debugged has.

Is there a way in either pgAdmin or in psql that I can run a query from a perspective inside the transaction? I know that such a thing is typically prohibited (for good reasons relating to transaction isolation), but it would be very useful thing for debugging.

Please note that I am not asking for other ways to debug my situation (eg, by enabling JDBC logging and watching the statements that are logged). I am aware of other ways to do it - but they are all quite a bit less convenient. Hence, I do not believe that this question should be closed as a duplicate of How to enable logging for SQL statements when using JDBC (indeed, I am aware of more convenient options available to me than using JDBC logging to debug my situation even if the answer to my question is "No, it's not possible.")

Fr Jeremy Krieg
  • 482
  • 5
  • 13
  • Enable logging of SQL statements, so you can see exactly what Java has done to the database. That way you can repeat those same statements in the tool of your choice, to get the database into the same state for testing. Just make sure the tool doesn't commit either. Seeing the statements might also clue you in to what is going wrong. See [How to enable logging for SQL statements when using JDBC](https://stackoverflow.com/q/27060563/5221149). – Andreas Sep 02 '20 at 02:24
  • @Andreas, thank you for your suggestion. I can see that that will work as a workaround, but it doesn't directly address the question I asked - if it is possible to do what I asked in the OP, then that would be much more convenient that this workaround. – Fr Jeremy Krieg Sep 02 '20 at 02:39
  • 1
    Addressing the question you asked: No – Andreas Sep 02 '20 at 02:40

0 Answers0