Prevent drop table if conditions are not met

。_饼干妹妹 提交于 2020-01-07 05:48:06

问题


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


回答1:


I'm going to guess that you are trying to ask:

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

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

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.

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

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

See also: How to prevent table from being dropped?



来源:https://stackoverflow.com/questions/17419944/prevent-drop-table-if-conditions-are-not-met

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!