如何在 postgresql 中创建时间驱动的触发器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9804844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 23:45:15  来源:igfitidea点击:

How to create a time-driven trigger in postgresql

postgresqltriggerstimer

提问by artaxerxe

I have a table in my database (postgres), that keeps in it the user accounting trace. I need to create a trigger that will perform a clean up at a given amount of time (let's say 30 minutes.) Is it possible to do that from postgres, or do I need to use something else? (By something else I mean C or Java or any other programming language that can sleep for a given time).

我的数据库 (postgres) 中有一个表,其中保存了用户记帐跟踪。我需要创建一个触发器,它将在给定的时间(假设是 30 分钟)执行清理。是否可以从 postgres 执行此操作,或者我是否需要使用其他方法?(我的意思是 C 或 Java 或任何其他可以在给定时间内休眠的编程语言)。

回答by wildplasser

Without PgAgent, things like this can be done using a cron script.

如果没有 PgAgent,这样的事情可以使用 cron 脚本来完成。

In both cases the periodic thing will be running from a different context (database owner, superuser, postgres), and in a separate transaction, obviously.

在这两种情况下,周期性的事物都将在不同的上下文(数据库所有者、超级用户、postgres)中运行,并且显然在一个单独的事务中。