2

I just want to know what is the reason for having different time while executing the same query in PostgreSQL.

For Eg: select * from datas;

For the first time it takes 45ms For the second time the same query takes 55ms and the next time it takes some other time.Can any one say What is the reason for having non static time.

3 Answers 3

2

Simple, everytime the database has to read the whole table and retrieve the rows. There might be 100 different things happening in database which might cause a difference of few millis. There is no need to panic. This is bound to happen. You can expect the operation to take same time with some millis accuracy. If there is a huge difference then it is something which has to be looked.

Sign up to request clarification or add additional context in comments.

Comments

1

Have u applied indexing in your table . it also increases speed to a great deal!

Compiling the explanation from

Reference by matt b

EXPLAIN statement? helps us to display the execution plan that the PostgreSQL planner generates for the supplied statement.

The execution plan shows how the table(s) referenced by the statement will be scanned — by plain sequential scan, index scan, etc. — and if multiple tables are referenced, what join algorithms will be used to bring together the required rows from each input table

And Reference by Pablo Santa Cruz You need to change your PostgreSQL configuration file.

Do enable this property:

log_min_duration_statement = -1        # -1 is disabled, 0 logs all statements                                    
                                       # and their durations, > 0 logs only                                       
                                       # statements running at least this number                                  
                                       # of milliseconds   

After that, execution time will be logged and you will be able to figure out exactly how bad (or good) are performing your queries.

Comments

1

Well that's about the case with every app on every computer. Sometimes the operating system is busier than other times, so it takes more time to get the memory you ask it for or your app gets fewer CPU time slices or whatever.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.