"Andrus" <kobruleht2@xxxxxx> writes: > from pgAdmin, it takes 1 second. > When I run this command from script it takes 11 minutes! > Any idea why running this command from script takes 11 minutes? Different plans maybe? Try EXPLAIN ANALYZE in both cases. Do you have work_mem set the same in both cases? > My script in running in single transaction. > Should I use commit after index creation or after ANALYZE command? Hmm, there are some extra cycles involved in examining not-yet-committed tuples, but I hardly see how that would create a discrepancy of this size. Check the plans first. regards, tom lane