Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug postgresql stored procedures?

I realize that there is nothing similar to SQL Server Management Studio, so I am mentally prepared to use the good old printf debugging.

The only question is how to do "printf" from a stored procedure?

like image 938
mark Avatar asked Nov 25 '13 10:11

mark


People also ask

Can we debug in PostgreSQL?

The debugger may be used to debug PL/pgSQL functions in PostgreSQL, as well as EDB-SPL functions, stored procedures and packages in EDB Postgres Advanced Server. The Debugger is available as an extension for your PostgreSQL installation, and is distributed as part of Advanced Server.

How do I debug a Postgres function in pgAdmin?

dll should be loaded successfully as can be verified by using the command show shared_preload_libraries , and I can see the debugging option in the context menu with a right click on a function in pgAdmin. When choosing "Debugging" --> Debug, a window pops up to allow me to enter the values for the input parameters.


1 Answers

To "print" a message, you can use raise notice from within a PL/pgSQL function:
http://www.postgresql.org/docs/current/static/plpgsql-errors-and-messages.html

Note that the client must have set the value of "client_min_messages" to the appropriate level in order to receive the "notice".

pgAdmin has a debugger for functions: http://www.pgadmin.org/docs/1.18/debugger.html

(But I have never use it as I don't use pgAdmin).

like image 124
a_horse_with_no_name Avatar answered Oct 11 '22 13:10

a_horse_with_no_name