dongqu9917 2015-01-08 12:18
浏览 56
已采纳

跟踪由单个PHP脚本调用引起的Postgres数据库活动

Is it possible to track database activity from the beginning, until the end of a PHP script invocation?

For example, let's say I have a script which creates a new record for a user in a database. You fill in a form, hit submit and provided all the data is valid the script proceeds to affect multiple tables inserting data.

The script inserts data into a main user table; (name, address, tel, etc...) is returned a new userid and then also adds a record to a department table (userid, departmentid) and a salary amount to a payroll table (userid, salary).

Is there a way to see all the tables that were affected by the script, the order in which they were used and the data passed to them for a single invocation?

Extra info: I'm using Ubuntu 14.04 LTS with Apache 2.4.7, PHP 5.5.9 and Postgres 9.3.5. I am the sole user of this machine; Everything will be run locally.

Ultimately I want to set the script running and watch what it does in the Postgres DB.

Thank you.

  • 写回答

1条回答 默认 最新

  • douchun5976 2015-01-09 03:47
    关注

    You can do this server-side, by setting log_statement = 'all' and setting a suitable log_line_prefix to include the backend process ID, transaction ID, etc.

    You might find it useful to set an application_name in the client connection string or SET application_name = 'blah' in your script, so it's easier to find in the logs too.

    Note that you can set log_statement on a per-user basis with ALTER USER blah SET log_statement = 'all', or on a per-database basis with ALTER DATABASE blah SET log_statement = 'all'. You can clear the setting later with ALTER ... RESET log_statement.

    Use of CSV format logs makes it easier too.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 fluent无法启动
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。