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 Tpad api账户 api口令
    • ¥30 ppt进度条制作,vba语言
    • ¥15 stc12c5a60s2单片机测光敏ADC
    • ¥15 生信simpleaffy包下载
    • ¥15 请教一下simulink中S函数相关问题
    • ¥15 在二层网络中,掩码存在包含关系即可通信
    • ¥15 端口转发器解析失败不知道电脑设置了啥
    • ¥15 Latex算法流程图行号自定义
    • ¥15 关于#python#的问题:我在自己的电脑上运行起来总是报错,希望能给我一个详细的教程,(开发工具-github)
    • ¥40 基于51单片机实现球赛计分器功能