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.

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

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法