Logging queries

Learn about logging queries that were run in a stored procedure to query history DB.

With Netezza Performance Server, you can record queries that are run from a stored procedure and its nested stored procedures. The queries are recorded in the query history database.

To use this feature, set the enable_sproc_hist_logging postgres configuration parameter globally or at a session level. The feature is disabled by default.

With enable_sproc_hist_logging enabled, the feature records internal queries that are run by a stored procedure. For example, for the following stored procedure:
CREATE OR REPLACE PROCEDURE test_proc()
RETURNS INT4 LANGUAGE NZPLSQL AS
BEGIN_PROC
declare c integer;
BEGIN
RAISE NOTICE 'The customer name is beta';
create table netezza(i int);
insert into netezza values(10);
select count(*) into c from netezza;
END;
END_PROC;
If you run this stored procedure on a system with enable_sproc_hist_logging enabled, the lines in bold in the stored procedure definitions are logged to the history database.
HISTDB.QUERYOWNER(ADMIN)=> select opid, sessionid, dbname, query from "$v_hist_queries" where sessionid=298716 and dbname='SYSTEM' order by opid;
OPID | SESSIONID | DBNAME | QUERY
---------+-----------+--------+-----------------------------------------------------------
2279850 | 298716 | SYSTEM | select version(), 'OS Platform: Linux', 'OS Username: nz'
2279851 | 298716 | SYSTEM | SET CLIENT_VERSION = 'Release 7.2.1.6-P1 [Build 0]'
2279852 | 298716 | SYSTEM | select current_catalog, current_schema, current_user
2279981 | 298716 | SYSTEM | set enable_sproc_hist_logging=1
2280102 | 298716 | SYSTEM | show enable_sproc_hist_logging
2280202 | 298716 | SYSTEM | call test_proc()
2280203 | 298716 | SYSTEM | create table netezza(i int)
2280207 | 298716 | SYSTEM | insert into netezza values(10)
2280209 | 298716 | SYSTEM | SELECT count(*) from netezza
Note: The behavior differs for regular and encrypted and or obfuscated stored procedures.

Examples

Regular stored procedure call

All internal queries and nested stored procedures executions are recorded. If the nested stored procedure is encrypted and or obfuscated, its queries are not recorded.

Obfuscated and or encrypted store procedure call

Any internal queries or nested store procedures (regular or obfuscated) are not captured in the query history database.