Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I would like to test the behaviour of a program which executes queries to a PostgreSQL server in case of a query timeout.

How could I simulate that?

share|improve this question
    
When you say "query timeout" do you mean a statement_timeout? Or do you mean a TCP/IP timeout due to connection loss? Quite different behaviour. –  Craig Ringer Jul 22 at 3:41

2 Answers 2

If you are just trying to simulate a timeout on your application side you could just use a dummy query like:

SELECT pg_sleep(seconds);

Where seconds is some integer value that would simulate a query just not coming back in a reasonable timeframe.

If you want to never come back from a query just run the above and kill the database.

pgrep posgres | xargs kill -15 $1

This would also simulate a query timeout I believe.

share|improve this answer

How are you simulating the successful queries? You should be able to use the same mechanism, but return PGRES_FATAL_ERROR (and appropriate message strings) in your PGresult return value .

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.