@@ -64,6 +64,62 @@ to run with a 'trial' policy initially, allowing code to run but logging
6464permissions that may need to be added in ` pljava.policy ` . How to do that is
6565described [ here] ( trial.html ) .
6666
67+ ### Debugging PL/Java functions
68+
69+ #### Java exception stack traces
70+
71+ PL/Java catches any Java exceptions uncaught by your Java code, and passes them
72+ on as familiar PostgreSQL errors that will be reported to the client, or can be
73+ caught, as with PL/pgSQL's ` EXCEPTION ` clause. However, the created PostgreSQL
74+ error does not include the stack trace of the original Java exception.
75+
76+ If either of the PostgreSQL settings ` client_min_messages ` or ` log_min_messages `
77+ is ` DEBUG1 ` or finer, the Java exception stack trace will be printed to
78+ the standard error channel of the backend process, where it will be collected
79+ and saved in the server log if the PostgreSQL setting ` logging_collector ` is on.
80+ Otherwise, it will go wherever the error channel of the backend process is
81+ directed, possibly nowhere.
82+
83+ #### Connecting a debugger
84+
85+ To allow connecting a Java debugger, the PostgreSQL setting ` pljava.vmoptions `
86+ can be changed, in a particular session, to contain a string like:
87+
88+ ```
89+ -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=localhost:0
90+ ```
91+
92+ On the first action in that session that uses PL/Java, the debugger transport
93+ will be set up as specified. For the example above, PL/Java will listen for
94+ a connection from a Java debugger at a randomly-chosen port, which will be
95+ identified with this message (where _ nnnnn_ is the port number):
96+
97+ ```
98+ Listening for transport dt_socket at address: nnnnn
99+ ```
100+
101+ A Java debugger can then be started and attached to the listening address and
102+ port.
103+
104+ The "Listening" message, however, is written to the standard output channel
105+ of the PostgreSQL backend process. It may be immediately visible if you are
106+ running PostgreSQL in a [ test harness] ( ../develop/node.html ) , but in a
107+ production setting it may go nowhere. In such a setting, you may prefer to set
108+ a specific port number, rather than 0, in the ` pljava.vmoptions ` setting, to
109+ be sure of the port the debugger should attach to. Choosing a port that is not
110+ already in use is then up to you.
111+
112+ As an alternative, ` server=y ` can be changed to ` server=n ` , and PL/Java will
113+ then attempt to attach to an already-listening debugger process. The
114+ address: port should be adjusted to reflect where the debugger process is
115+ listening.
116+
117+ With ` suspend=n ` , PL/Java proceeds normally without waiting for the debugger
118+ connection, but the debugger will be able to set break or watch points, and will
119+ have control when Java exceptions are thrown. With ` suspend=y ` , PL/Java only
120+ proceeds once the debugger is connected and in control. This setting is more
121+ commonly used for debugging PL/Java itself.
122+
67123### The thread context class loader
68124
69125Starting with PL/Java 1.6.3, within an SQL-declared PL/Java function, the
0 commit comments