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?

  • 1
    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 '15 at 3:41

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.


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 .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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