Can I log query execution time in PostgreSQL 8.4?

前端 未结 3 1505
刺人心
刺人心 2020-12-31 08:32

I want to log each query execution time which is run in a day.

For example like this,

2012-10-01 13:23:38 STATEMENT: SELECT * FROM pg_stat_database           


        
3条回答
  •  时光取名叫无心
    2020-12-31 09:00

    If you set

    log_min_duration_statement = 0
    log_statement = all 
    

    in your postgresql.conf, then you will see all statements being logged into the Postgres logfile.

    If you enable

    log_duration
    

    that will also print the time taken for each statement. This is off by default.

    Using the log_statement parameter you can control which type of statement you want to log (DDL, DML, ...)

    This will produce an output like this in the logfile:

    2012-10-01 13:00:43 CEST postgres LOG:  statement: select count(*) from pg_class;
    2012-10-01 13:00:43 CEST postgres LOG:  duration: 47.000 ms
    

    More details in the manual:

    • http://www.postgresql.org/docs/8.4/static/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHEN
    • http://www.postgresql.org/docs/8.4/static/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHAT

    If you want a daily list, you probably want to configure the logfile to rotate on a daily basis. Again this is described in the manual.

提交回复
热议问题