简体   繁体   中英

detailed timing of operation in postgres

suppose i have some triggers on some table ON Insert. How can i know what time it actually takes to insert and what time it takes to execute trigger ?

If you use explain (analyze, verbose) for the statement that fires the trigger you will see the execution time of each trigger on the table.

So if you have a table foo with a trigger, and run something like this:

explain (analyze, verbose)
insert into foo (id) 
values (1);

You'll get an output similar to this:

Insert on foo (cost=0.00..0.01 rows=1 width=0) (actual time=938.776..938.776 rows=0 loops=1)
  ->  Result  (cost=0.00..0.01 rows=1 width=0) (actual time=0.014..0.014 rows=1 loops=1)
        Output: 1
Planning time: 0.040 ms
Trigger foo_trg: time=937.371 calls=1 <<<< here
Execution time: 938.802 ms

Note that explain (analyze) will in fact run that statement. So the new row will be inserted. You need to rollback if you don't want that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM