PostgreSQL stored Procedure debug: PostgreSQL Function NOTICE

Source: Internet
Author: User
Tags postgresql function

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.