如何检索在postgres中在数据库中执行的所有查询(带列名)

时间:2017-03-15 15:40:41

标签: sql postgresql logging

大家好日子!!

我的要求是这样的: 在我的Web应用程序中,我想要在我的数据库中执行的所有查询。我有postgres,我做了以下配置更改。

log_min_message = debug5;
log_statement='all';

让我举个例子: 比方说,我有表学生,其定义如下:

create table student(id integer, firstname text, lastname text);

案例1:从我的应用程序中,我插入一行:

insert into student(id,firstname,lastname) values (1,'a','b');

我在日志文件中有以下内容:

2017-03-15 10:12:39.751 GMT :: DEBUG:  parse <unnamed>: insert into student (id, firstname, lastname) values ($1, $2, $3)
2017-03-15 10:12:39.751 GMT :: DEBUG:  StartTransactionCommand
2017-03-15 10:12:39.751 GMT :: DEBUG:  bind <unnamed> to <unnamed>
2017-03-15 10:12:39.751 GMT :: LOG:  execute <unnamed>: insert into student (id, firstname, lastname) values ($1, $2, $3)
2017-03-15 10:12:39.751 GMT :: DETAIL:  parameters: $1 = 1, $2 = 'a', $3 = 'b'
2017-03-15 10:12:39.751 GMT :: DEBUG:  ProcessQuery
2017-03-15 10:12:39.758 GMT :: DEBUG:  CommitTransactionCommand
2017-03-15 10:12:39.758 GMT :: DEBUG:  bind <unnamed> to S_2
2017-03-15 10:12:39.758 GMT :: DEBUG:  StartTransactionCommand
2017-03-15 10:12:39.758 GMT :: LOG:  execute S_2: COMMIT

案例2:但是当我尝试插入此内容时:

insert into student values (2,'a','b');

我明白了:

2017-03-15 10:12:39.751 GMT :: DEBUG:  parse <unnamed>: insert into student values ($1, $2, $3)
    2017-03-15 10:12:39.751 GMT :: DEBUG:  StartTransactionCommand
    2017-03-15 10:12:39.751 GMT :: DEBUG:  bind <unnamed> to <unnamed>
    2017-03-15 10:12:39.751 GMT :: LOG:  execute <unnamed>: insert into student values ($1, $2, $3)
    2017-03-15 10:12:39.751 GMT :: DETAIL:  parameters: $1 = 1, $2 = 'a', $3 = 'b'
    2017-03-15 10:12:39.751 GMT :: DEBUG:  ProcessQuery
    2017-03-15 10:12:39.758 GMT :: DEBUG:  CommitTransactionCommand
    2017-03-15 10:12:39.758 GMT :: DEBUG:  bind <unnamed> to S_2
    2017-03-15 10:12:39.758 GMT :: DEBUG:  StartTransactionCommand
    2017-03-15 10:12:39.758 GMT :: LOG:  execute S_2: COMMIT

但我需要所有列名称的完全限定查询。 (与案例1一样)

insert into student (id, firstname, lastname) values ($1, $2, $3)

有可能吗?

0 个答案:

没有答案