12

I'm using PostgreSQL 8.3+PostGIS 1.3 to store geospatial data on Ubuntu 8.04 Hardy.

This particular version of PostGIS has a bug when calculating a buffer() on very complex segments, which causes the query to take more and more memory until the entire machine gets stuck.

I'm looking for a PostgreSQL mechanism that can:

  • Limit the memory consumption (and perhaps other resources) used by a specific query.
  • Automatically stop queries whose execution time exceeds a certain threshold.

Any ideas?

asked Feb 20, 2011 at 11:58
2
  • Why do you keep using a version that has a bug that bites you? Use a version that is fixed and your problem is gone. Commented Feb 21, 2011 at 7:42
  • True, but sometimes there are bugs in our code, or just queries that take toooooooo long. I want them to die with log error message. Commented Feb 21, 2011 at 12:05

2 Answers 2

9

To limit memory consumption, the main configuration parameter is work_mem. Since this applies per operation, not per query, you cannot simply set it to N if you want to spend N amount of memory, but you have to tweak and tune it a bit to get the desired result.

This doesn't help, however, in case of bugs and other memory leaks in the server code or extensions. You could control that with the process-specific resource limits controlled by ulimit. But if you reach the limit and memory allocation fails, what do you want to have happen? It probably won't behave too nicely. Better fix those bugs or use a different version.

The stop queries whose execution time passed a threshold, use the parameter `statement_timeout', e.g.,

SET statement_timeout TO '10min';
answered Feb 20, 2011 at 15:38
1
  • Great. Just what I was looking for. Commented Feb 21, 2011 at 12:05
2

Have a look at the Postgres Wiki:

PostgreSQL has no facilities to limit what resources a particular user, query, or database consumes, or correspondingly to set priorities such that one user/query/database gets more resources than others. It's necessary to use operating system facilities to achieve what limited prioritization is possible.

You can adjust performance settings on a per user or per database but not when to abort certain queries.

answered Feb 20, 2011 at 12:07
1
  • +1 What about setting a maximum to the amount of memory the entire cluster can consume? Commented Feb 20, 2011 at 12:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.