Reprinted from http://zhenghaoju700.blog.163.com/blog/static/13585951820116782843994/
Install a PostgreSQL first (see Supplemental knowledge)
Compare Oracle PL/SQL
Dbms_output.put_line ("This is a log") in PL/SQL; Simple commissioning is possible
Of course our PostgreSQL also has the corresponding function RAISE NOTICE ' This is a log% ', param;
% placeholder param replacement Value
RAISE There are other levels debug,log,info,exception
You can configure the client_min_messages and log_min_messages in their postgresql.conf in the configuration file
RAISE EXCEPTION pauses the operation of the function, and the other levels should be displayed to the client by default.
Give me a simple example.
For example, before you first determine if your database is installed Plpgsql
SELECT * from Pg_language;
If not,
Create language Plpgsql;
Simple example:
CREATE OR REPLACE FUNCTIONperctl.testraise ()RETURNSvoid as$$DeclarebeginRaise Notice'==============='; while(2>1) loopraise Notice'=========================================================================================================== ========================================================================='; raise Notice'=========================================================================================================== ========================================================================='; raise Notice'=========================================================================================================== ========================================================================='; raise Notice'=========================================================================================================== ========================================================================='; raise Notice'=========================================================================================================== ========================================================================='; raise Notice'=========================================================================================================== ========================================================================='; raise Notice'=========================================================================================================== ========================================================================='; raise Notice'=========================================================================================================== ========================================================================='; raise Notice'=========================================================================================================== ========================================================================='; raise Notice'=========================================================================================================== =========================================================================';Endloop;raiseLog '===============';End; $$ LANGUAGE plpgsql VOLATILE Cost -;ALTER FUNCTIONperctl.fx_test_outofmemory_1 () OWNER toRoot
Test it.
Select Testraise (' This is a message ');
Why only Notice and info information?
Find the PostgreSQL installation directory with Find/-name PostgreSQL
[Email protected]:/etc/postgresql/8.4/main$ pwd
/etc/postgresql/8.4/main
View configuration files under etc Vim postgresql.conf
See the client minimum display level is notice so must be greater than notice to show this is why log is not displayed
Debug is not shown because they only have debug (1-5)
This can be assured debugging!!!!
Additional knowledge:
Installation Environment Ubuntu 11.03
1.sudo Apt-get Install PostgreSQL
2.sudo passwd postgres Change Password This user is created by the database itself
3. Start Services service PostgreSQL start
4.su Postgres
5.psql Open Interactive shell
6.\l List all databases
Resources:
http://www.postgresonline.com/journal/archives/83-quick-guide-to-writing-plpgsql-functions-part-3-notices,- Recursion,-and-more.html
PostgreSQL stored Procedure debug: PostgreSQL Function NOTICE