Is there any way to get the optimization time in PostgreSQL?
Yes, starting with Postgres 9.4 this information is included in the execution plan when using the analyze option:

psql (9.4.1)
Type "help" for help.

postgres=&gt; explain (analyze,verbose)
postgres-&gt; select count(*)
postgres-&gt; from product;
                                                                             QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=8431.92..8431.92 rows=1 width=0) (actual time=132.491..132.491 rows=1 loops=1)
   Output: count(*)
   -&gt;  Index Only Scan using product_pkey on public.product  (cost=0.42..7181.92 rows=500000 width=0) (actual time=0.622..91.129 rows=500000 loops=1)
         Output: product_id
         Heap Fetches: 8
 Planning time: 2.756 ms
 Execution time: 132.614 ms
(7 rows)