如果不满足条件,则防止掉落表

如果不满足条件,则防止掉落表

问题描述:

我想问问是否有可能处理删除表命令并在不满足某些条件的情况下中断它?

I'd like to ask if it is possible to handle dropping table command and break it if some conditions are not met?

我猜你是在问:


如何防止 DROP TABLE 根据某些应用程序定义的条件成功执行

How do I prevent a DROP TABLE from succeeding based on certain application-defined conditions

如果是这样,则唯一的内置选项是使用权限。请参见PostgreSQL手册中的 GRANT REVOKE

If so, your only built-in option is to use permissions. See GRANT and REVOKE in the PostgreSQL manual.

如果您想要更复杂的东西,可以编写一个 ProcessUtility_hook ,但是这要求您使用C编写一个扩展并将其编译并加载到服务器中。

If you want something more complex, you can write a ProcessUtility_hook, but this requires that you write an extension in C that is compiled and loaded into the server.

编写 ProcessUtility_hook 其实并不难,但是PostgreSQL 9.2和9.3定义之间存在差异意味着您将需要单独的扩展名。这是一个基本示例: https://github.com/ringerc/scrapcode/tree / master / postgresql / example_processutility_hook ,这是一个ProcessUtility钩子,它实际上在做一些有用的事情: https://github.com/ringerc/postgres/blob/bdr-reject-unsafe-commands/contrib/bdr/bdr_commandfilter.c

Writing a ProcessUtility_hook isn't actually too hard, but there are differences between the PostgreSQL 9.2 and 9.3 definitions that mean you'll need separate extensions. Here's a basic example: https://github.com/ringerc/scrapcode/tree/master/postgresql/example_processutility_hook and here's a ProcessUtility hook that actually does something useful: https://github.com/ringerc/postgres/blob/bdr-reject-unsafe-commands/contrib/bdr/bdr_commandfilter.c

如果您没有C编程经验并且有一段时间,那么 ProcessUtility_hook 不适合您。

If you don't have C programming experience and some time, a ProcessUtility_hook isn't for you.

另请参阅:如何防止表格掉落?