and PolarDB for PostgreSQL (Oracle-compatible) support multiple stored procedure languages, such as PLpgSQL, PL/Python, PL/Perl, PL/Tcl, and PL/Java. You can use these stored procedure languages to create functions or stored procedures. PolarDB provides the pldebugger extension to debug stored procedures.
Prerequisites
The pgAdmin 4 client must be version 4.19 or later. To download pgAdmin 4, see the pgAdmin Download page.
Usage notes
By default, each cluster supports a maximum of three concurrent debugging sessions, which use a total of six connections. If you require more than three concurrent sessions, go to Quota Center. In the Operation column of the quota named pldebugger plug-in usage for PolarDB for PostgreSQL, click Apply to increase your quota.
For example, if three debugging sessions are already active, you cannot start a fourth session. To proceed, you must close one of the active sessions.
Create the extension
Use the polar_superuser user to create and debug the extension.
postgres=# CREATE EXTENSION if not exists pldbgapi;
CREATE EXTENSION
Use the extension
-
Connect to your PolarDB cluster with the pgAdmin 4 client. For more information, see Connect to a database cluster.
-
Find the function that you want to debug, right-click the function, and then select Debugging > Debug.
-
You can now use the pldebugger extension in pgAdmin 4.
declare v_result int; begin v_result := 0; if i<0 then raise notice 'Please enter i >=0.'; raise exception ''; end if; for x in 0..i loop v_result := v_result + x; end loop; return v_result; exception when others then raise; end;-
In the debugging pane on the right side of the pgAdmin 4 page, you can step through the function. For example, you can use
step into/overandcontinue, set breakpoints, and stop the session. -
At the bottom of the pgAdmin 4 page, you can view local variables, debugging output, and the function stack.
-
Monitor debugging connections
PolarDB provides a function to monitor the number of debugging connections used by the pldebugger extension. You can use this function to view the current number of debugging connections and the configured maximum number of connections.
postgres=# select * from polar_monitor_pldebugger_count();
current_connection | max_connection
--------------------+----------------
6 | 6
(1 row)
-
current_connection: The current number of connections in use. -
max_connection: The configured maximum number of debugging connections.
The example shows that six connections are in use. Because each pldebugger session uses two connections, this indicates that three pldebugger processes are running. A maximum of three pldebugger processes can run concurrently.