Whenever you are running queries against the Illuminate database I recommend you set a statement_timeout. This timeout is a great way to make sure your queries are not running longer than you would expect.

According to the Postgres does this will:

Abort any statement that takes more than the specified number of milliseconds, starting from the time the command arrives at the server from the client.

This means that a single query can only take that long to run before the server kills it. By default we set this to 1 minute for you, however, there are very few cases where a query should take a minute to run. Generally I like to set my statement_timeout as low as possible so that I am not waiting forever for my query to return results.

To set the statement timeout use the following command. Also, Postgres requires that you send the statement_timeout in milliseconds. There are 1000 milliseconds in 1 second, so to get the number of milliseconds you can do number of seconds * 1000.

-- Set statement timeout to 10 seconds
SET statement_timeout TO '10000';

Calling this before your other queries ensures they run in under 10 seconds before timing out.

Examples

-- Set statement timeout to 1 second
SET statement_timeout TO '1000';

-- If this query takes longer than 10 seconds it will be aborted by the server
SELECT student_id, last_name, first_name
FROM students
LIMIT 100;