如何在Postgresql中记录数据更改? [英] How to log data change in postgresql?

查看:702
本文介绍了如何在Postgresql中记录数据更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该问题似乎可能是与该主题相关的其他一些问题的重复。我发现了一些类似的问题(几年前有人问了一些问题,关于该主题的讨论似乎已经结束了)。但是没有找到解决我的问题的可行方案。我有一个数据库,其中包含大量数据的表。我需要记录存储在特定数据库表中的数据所发生的每一次更改。

This question may seem to be a possible duplicate of some other questions that are related to this topic. I've found some similar questions(some questions were asked years back and discussion on the topic seemed to be almost over). But no feasible solutions were found for my problem. I've a database with plenty of tables with huge amount of data in it. I need to log each and every changes that is happening to the datas that are stored in the tables of the particular database.

例如,我有一个用于存储员工详细信息的表。

For example, I have a table for storing employee details.

id    employeename
 1    ab

并且,此数据更改为

id    employeename
 1    cd

所以我需要记录此数据。

So i need to log this data.

即员工姓名


ab

ab

更改为


cd

cd

表中的员工详细信息中的

in the table employee details

每次更改存储在其中的内容时,我都需要记录数据桌子。真的有可能吗?如果是这样,我该怎么做?它涉及哪些步骤?在这种情况下,我非常担心日志文件的大小。在这种情况下,什么是更好的选择?我正在使用postgresql8.4。任何好的建议都会对我有很大帮助。

I need to log the data every time a change is made to the contents stored in the tables. Is it really possible? If so, how can I do that? What are the steps involved in it? I'm pretty concerned about the size of the log files in such a case. In such a situation what can be a good alternative? I'm using postgresql8.4. Any good suggestion will help me a lot. Thanks in advance.

推荐答案

这里是触发器的示例,而不是记录这样的更改:审核触发器

Here is the example of a trigger, than logs such changes: Audit trigger.

这篇关于如何在Postgresql中记录数据更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆