PostgreSQL:如何在不延迟插入响应的情况下执行插入触发器?

发布于 2024-08-19 13:49:27 字数 72 浏览 2 评论 0原文

有谁知道如何设置插入触发器,以便当从我的应用程序执行插入时,即使在触发器完成执行之前,数据也会被插入并且 postgres 返回?

Does anyone knows how can I set up an insert trigger so when a perform an insert from my application, the data gets inserted and postgres returns, even before the trigger finishes executing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少女情怀诗 2024-08-26 13:49:27

对此没有内置支持;你将不得不破解一些东西。选项包括:

  • 用 C、Perl 或 Python 编写触发器,并让它启动一个单独的进程来执行您想要的操作。这可能会变得很棘手,并且可能对您的数据库系统有点危险,并且只有当您想要做的事情在数据库之外时它才有效。

  • 编写一个轻量级触发器函数,仅将条目记录到日志或任务表中,并有一个单独的作业或守护程序按自己的计划查看该表并从那里执行操作。这或多或少就是 Slony 的工作原理。

There is no built-in support for this; you will have to hack something up. Options include:

  • Write the trigger in C, Perl, or Python and have it launch a separate process to do the things you want. This can get tricky and possibly slightly dangerous to your database system, and it only works if the things you want to do are outside of the database.

  • Write a lightweight trigger function that only records an entry into a log or task table, and have a separate job or daemon that looks into that table on its own schedule and executes things from there. That's more or less how Slony works.

铜锣湾横着走 2024-08-26 13:49:27

问题是:为什么需要它?触发器应该很快。如果您需要做一些复杂的事情,请编写触发器来向执行复杂部分的某些守护进程发送通知 - 例如使用 PostgreSQL 的 LISTEN/NOTIFY 功能。

The question is : why do you need it? Triggers should be fast. If you need to do something complicated, write trigger that send notification to some daemon that does the complex part - for example using LISTEN/NOTIFY feature of PostgreSQL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文