简体   繁体   English

如何判断 Postgres 触发器是否/何时执行

[英]How to tell if/when Postgres triggers are executing

I'm working in a legacy codebase/database.我在遗留代码库/数据库中工作。 The code previously depended on triggers but at one point stopped using them - the logic was moved into the main (Nodejs) codebase and the CREATE TRIGGER statements were removed.代码以前依赖于触发器,但在某一时刻停止使用它们 - 逻辑被移动到主(Nodejs)代码库中,并且CREATE TRIGGER语句被删除。 Nonetheless, the triggers still exist in the DB.尽管如此,触发器仍然存在于数据库中。 I can see them searching the pg_trigger table:我可以看到他们搜索pg_trigger表: 在此处输入图像描述

As far as I can tell they're still enabled which is weird because to my knowledge they shouldn't be doing anything.据我所知,它们仍然处于启用状态,这很奇怪,因为据我所知,它们不应该做任何事情。 If they're not being used I'd like to remove them.如果它们没有被使用,我想删除它们。 My questions:我的问题:

  1. Is there way to tell the last time a trigger executed?有没有办法告诉最后一次执行触发器的时间?
  2. Are there any other ways I can figure out if these triggers are even doing anything anymore?有没有其他方法可以确定这些触发器是否还在做任何事情?

There is no way to do that, unless you modify the triggers to record the execution somewhere.没有办法做到这一点,除非您修改触发器以在某处记录执行。

Perhaps session_replication_role is set to replica .也许session_replication_role设置为replica Then normal triggers ( tgenabled = 'O' ) don't fire.然后正常触发器( tgenabled = 'O' )不会触发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM