检查 IBM Netezza 中哪些程序修改了数据
Check what procedure modified data in IBM Netezza
我发现 Netezza 将历史数据存储在 HISDB 模式中。是否可以加入他们,这样我就可以得到 table 被什么程序修改的历史记录?
原因是我有加载 Netezza table 的 DataStage 作业,并且在 SQL 命令触发过程后将另一组数据添加到同一个 table。我需要记录所有事件以用于数据沿袭目的。
我进行的当前查询 returns 过程的调用时间。问题在于加入 USER_HISTDB."$hist_table_access_3"
。唯一匹配的字段是 NPSINSTANCEID
。 LOGENTRYID
、OPID
和 SESSIONID
具有不同的值。
这使我无法执行 table link。
SELECT
b.SUBMITTIME,
b.QUERYTEXT,
b.USERNAME,
b.DBNAME,
b.SCHEMANAME,
a.*
FROM USER_HISTDB."$hist_log_entry_3" a
JOIN USER_HISTDB."$hist_query_prolog_3" b
ON a.LOGENTRYID = b.LOGENTRYID
AND a.SESSIONID = b.SESSIONID
AND a.NPSID = b.NPSID
AND a.NPSINSTANCEID = b.NPSINSTANCEID
WHERE b.QUERYTEXT like '%PROCEDURE_NAME%'
事务 ID 对于给定语句的每次执行都是唯一的,并且它在 table 中的记录中可见(称为 CreateXid 和 DeleteXid 的隐藏列)。可以在 HISTDB tables 上找到相同的 ID。
您需要帮助查询那些 table 吗?
-- By default, information about stored procedures is not logged
-- in the query history database. To enable logging of such ...
set ENABLE_SPROC_HIST_LOGGING = on;
-------------------------------------------------------------------------
-- TABLE -- All Info About All Accesses
-- ====================================
SELECT
QP.submittime,
substr(QP.querytext, 1, 100) as SQL_STATEMENT,
xid, -- the transaction id (which might be either a CREATEXID or DELETEXID)
username,
CASE
when usage = 1 then 'SELECTED'
when usage = 2 then 'INSERTED'
when usage = 3 then 'SELECTED/INSERTED'
when usage = 4 then 'DELETED'
when usage = 5 then 'SELECTED/DELETED'
when usage = 8 then 'UPDATED'
when usage = 9 then 'SELECTED/UPDATED'
when usage = 16 then 'TRUNCATED'
when usage = 32 then 'DROPPED'
when usage = 64 then 'CREATED'
when usage = 128 then 'GENSTATS'
when usage = 256 then 'LOCKED'
when usage = 512 then 'ALTERED'
else 'other'
END AS OPERATION,
TA.dbname,
TA.schemaname,
TA.tablename,
TA.tableid,
PP.planid -- The MAIN query plan (not all table operations involve a query plan)
-- If you want to see EVERYTHING, uncomment the next line.
-- Or pick and choose the columns you want to see.
-- ,*
FROM
---- SESSION information
"$hist_session_prolog_3" SP
left outer join "$hist_session_epilog_3" SE using ( SESSIONID, npsid, npsinstanceid )
---- QUERY information (to include the SQL statement that was issued)
left outer join "$hist_query_prolog_3" QP using ( SESSIONID, npsid, npsinstanceid )
left outer join "$hist_query_epilog_3" QE using ( OPID, npsid, npsinstanceid )
left outer join "$hist_table_access_3" TA using ( OPID, npsid, npsinstanceid )
---- PLAN information
---- Not all queries result in a query plan (for example, TRUNCATE and DROP do not)
---- And some queries might result in multiple query plans (such as a GROOM statement)
---- By including these joins we might get multiple rows (for any given row in the $hist_table_access_3 table)
left outer join "$hist_plan_prolog_3" PP using ( OPID, npsid, npsinstanceid )
left outer join "$hist_plan_epilog_3" PE using ( PLANID, npsid, npsinstanceid )
WHERE
(ISMAINPLAN isnull or ISMAINPLAN = true)
---- So ...
---- If there is NO plan file (as with a truncate) ... then ISMAINPLAN will be null. Include this row.
---- If there is a plan file, include ONLY the record corresponding to the MAIN plan file.
---- (Otherwise, there could end up being a lot of duplicated information).
and TA.tableid > 200000
---- Ignore access information for SYSTEM tables (where the OBJID # < 200000)
----
----Add any other restrictions here (otherwise, this query as written will return a lot of data)
----
ORDER BY 1;
我发现 Netezza 将历史数据存储在 HISDB 模式中。是否可以加入他们,这样我就可以得到 table 被什么程序修改的历史记录?
原因是我有加载 Netezza table 的 DataStage 作业,并且在 SQL 命令触发过程后将另一组数据添加到同一个 table。我需要记录所有事件以用于数据沿袭目的。
我进行的当前查询 returns 过程的调用时间。问题在于加入 USER_HISTDB."$hist_table_access_3"
。唯一匹配的字段是 NPSINSTANCEID
。 LOGENTRYID
、OPID
和 SESSIONID
具有不同的值。
这使我无法执行 table link。
SELECT
b.SUBMITTIME,
b.QUERYTEXT,
b.USERNAME,
b.DBNAME,
b.SCHEMANAME,
a.*
FROM USER_HISTDB."$hist_log_entry_3" a
JOIN USER_HISTDB."$hist_query_prolog_3" b
ON a.LOGENTRYID = b.LOGENTRYID
AND a.SESSIONID = b.SESSIONID
AND a.NPSID = b.NPSID
AND a.NPSINSTANCEID = b.NPSINSTANCEID
WHERE b.QUERYTEXT like '%PROCEDURE_NAME%'
事务 ID 对于给定语句的每次执行都是唯一的,并且它在 table 中的记录中可见(称为 CreateXid 和 DeleteXid 的隐藏列)。可以在 HISTDB tables 上找到相同的 ID。
您需要帮助查询那些 table 吗?
-- By default, information about stored procedures is not logged
-- in the query history database. To enable logging of such ...
set ENABLE_SPROC_HIST_LOGGING = on;
-------------------------------------------------------------------------
-- TABLE -- All Info About All Accesses
-- ====================================
SELECT
QP.submittime,
substr(QP.querytext, 1, 100) as SQL_STATEMENT,
xid, -- the transaction id (which might be either a CREATEXID or DELETEXID)
username,
CASE
when usage = 1 then 'SELECTED'
when usage = 2 then 'INSERTED'
when usage = 3 then 'SELECTED/INSERTED'
when usage = 4 then 'DELETED'
when usage = 5 then 'SELECTED/DELETED'
when usage = 8 then 'UPDATED'
when usage = 9 then 'SELECTED/UPDATED'
when usage = 16 then 'TRUNCATED'
when usage = 32 then 'DROPPED'
when usage = 64 then 'CREATED'
when usage = 128 then 'GENSTATS'
when usage = 256 then 'LOCKED'
when usage = 512 then 'ALTERED'
else 'other'
END AS OPERATION,
TA.dbname,
TA.schemaname,
TA.tablename,
TA.tableid,
PP.planid -- The MAIN query plan (not all table operations involve a query plan)
-- If you want to see EVERYTHING, uncomment the next line.
-- Or pick and choose the columns you want to see.
-- ,*
FROM
---- SESSION information
"$hist_session_prolog_3" SP
left outer join "$hist_session_epilog_3" SE using ( SESSIONID, npsid, npsinstanceid )
---- QUERY information (to include the SQL statement that was issued)
left outer join "$hist_query_prolog_3" QP using ( SESSIONID, npsid, npsinstanceid )
left outer join "$hist_query_epilog_3" QE using ( OPID, npsid, npsinstanceid )
left outer join "$hist_table_access_3" TA using ( OPID, npsid, npsinstanceid )
---- PLAN information
---- Not all queries result in a query plan (for example, TRUNCATE and DROP do not)
---- And some queries might result in multiple query plans (such as a GROOM statement)
---- By including these joins we might get multiple rows (for any given row in the $hist_table_access_3 table)
left outer join "$hist_plan_prolog_3" PP using ( OPID, npsid, npsinstanceid )
left outer join "$hist_plan_epilog_3" PE using ( PLANID, npsid, npsinstanceid )
WHERE
(ISMAINPLAN isnull or ISMAINPLAN = true)
---- So ...
---- If there is NO plan file (as with a truncate) ... then ISMAINPLAN will be null. Include this row.
---- If there is a plan file, include ONLY the record corresponding to the MAIN plan file.
---- (Otherwise, there could end up being a lot of duplicated information).
and TA.tableid > 200000
---- Ignore access information for SYSTEM tables (where the OBJID # < 200000)
----
----Add any other restrictions here (otherwise, this query as written will return a lot of data)
----
ORDER BY 1;