postgres_result_timeout
The `postgres_result_timeout` directive defines the maximum time to wait for a result from a PostgreSQL query before timing out.
Description
The postgres_result_timeout directive is used to specify a timeout value for the PostgreSQL queries made through NGINX. This helps in controlling how long NGINX should wait for a response from the PostgreSQL server before giving up and terminating the query process. By setting this parameter, users can mitigate situations where a query hangs indefinitely, which could lead to resource exhaustion or degraded performance of the web application.
The timeout value is set in milliseconds, and it can be specified in the http, server, or location contexts. The directive accepts a single argument, which is the time limit for processing a result set from a query. If the specified timeout is reached without receiving a response, NGINX will abort the operation and return an error to the client, ensuring the application remains responsive. This is particularly useful in scenarios where database operations may take longer than expected due to a high load or inefficient queries.
To ensure optimal application performance, it’s essential to balance the timeout value. Too short a timeout may lead to unnecessary query terminations, while too long may result in prolonged waits during peak traffic times. Users should monitor query performance and adjust the timeout according to their specific application needs and database behavior.
Config Example
location /data {
postgres_pass my_upstream;
postgres_query SELECT * FROM my_table;
postgres_result_timeout 1000;
}Setting a timeout that is too short may cause legitimate queries to fail, leading to increased error rates for your application.
Adjusting the timeout without understanding the underlying query performance can lead to unexpected behavior or slow responsiveness.