سؤال

We heavily utilize pg_query_params() for querying our PostgreSQL database from PHP. When analyzing postgres logs, however our queries are logged like:

SELECT
    email_address
FROM
    user u
WHERE
    user_id = $1
    AND user_mode = $2
LIMIT $3;

with only the array placeholders, not the actual values. Our PHP application is able to log errors returning the array, but the process of tuning would be much easier if we could track the parameters of trouble queries directly.

Is there a way to do this internal to PostgreSQL 9.2.4?

هل كانت مفيدة؟

المحلول

If you set log_statement = all then parameters will be recorded in the logs on a separate line. You may find setting a log_line_prefix that includes the session pid useful for making sure you can associate the statement text with the parameters.

There is no feature to substitute the parameters into the query text in-line. This is quite consciously avoided as substituting query params in makes it much harder for log analysis tools to collect stats about multiple runs of the same statement with different parameters.

It'd be nice if there was a convenient way to do both, or to say "I want to see statements with params subbed in" .... but there isn't.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top