Postgres turn on log_statement programmatically

谁说胖子不能爱 提交于 2019-12-12 05:52:24

问题


I want to turn on logging of all SQL statements that modify the database. I could get that on my own machine by setting the log_statement flag in the configuration file, but it needs to be enabled on the user's machine. How do you enable it from program code? (I'm using Python with psycopg2 if it matters.)


回答1:


The "it needs to be enabled on the user's machine" phrase is confusing, indeed... I assume you mean "from the user (client) side".

In Postgresql some server run-time parameters can be changed from a connection, but only from a superuser - and only for those settings that do not require a server restart. I'm not sure if that includes the many log options. You might try with something like:

SELECT set_config('log_XXX', 'off', false);

where log_XXX is to be replaced by the respective logging setting, and 'false' by the value you want to set.

If that does not work, I guess you are out of luck.



来源:https://stackoverflow.com/questions/2888589/postgres-turn-on-log-statement-programmatically

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