Postgres以编程方式打开log_statement [英] Postgres turn on log_statement programmatically

查看:124
本文介绍了Postgres以编程方式打开log_statement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开所有修改数据库的SQL语句的日志记录.我可以通过在配置文件中设置log_statement标志在自己的计算机上获得该标志,但是需要在用户计算机上启用它.如何从程序代码启用它? (如果重要的话,我将Python与psycopg2一起使用.)

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.)

推荐答案

需要在用户计算机上启用它" 这句话令人困惑,的确……我假设您的意思是从用户(客户端)端" .

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

在Postgresql中,某些服务器运行时参数可以可以从连接更改,但只能从超级用户更改,并且只能更改不需要重启服务器的设置. 我不确定这是否包含许多日志选项.您可以尝试使用类似的方法:

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);

其中log_XXX将由相应的

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.

这篇关于Postgres以编程方式打开log_statement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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