# Server stopping by OutOfMemoryError: Java heap space

**URL:** <https://discuss.elastic.co/t/server-stopping-by-outofmemoryerror-java-heap-space/170221>\
**Category:** Elasticsearch\
**Created:** [February 27, 2019, 6:14pm UTC](https://discuss.elastic.co/t/server-stopping-by-outofmemoryerror-java-heap-space/170221 "2019-02-27T18:14:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomTom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomtom/32/3676_2.png) [@TomTom](https://discuss.elastic.co/u/TomTom)\
**Post date:** [February 27, 2019, 6:14pm UTC](https://discuss.elastic.co/t/server-stopping-by-outofmemoryerror-java-heap-space/170221/1 "2019-02-27T18:14:00Z")

</div>

I'm using ElasticSearch 6.2 on a server with 4GB of RAM and 2 vCPUs.

Recently I have seen many errors of the type:

```
[ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [main-node] fatal error in thread [elasticsearch[main-node][search][T#4]], exiting

java.lang.OutOfMemoryError: Java heap space

[ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [main-node] fatal error in thread [Thread-11269], exiting

java.lang.OutOfMemoryError: Java heap space

```

If I increase the RAM of the server, for example, to 8GB and modify the value of the heap size (according to Article [https://www.elastic.co/guide/en/elasticsearch/reference/6.2/heap-size.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/heap-size.html)). Will this correct the problem?

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [March 1, 2019, 10:31am UTC](https://discuss.elastic.co/t/server-stopping-by-outofmemoryerror-java-heap-space/170221/2 "2019-03-01T10:31:48Z")

</div>

Hi,

it depends a bit what is causing your `OutOfMemoryError`s. It might be because you are running very heavy aggregations that create too many aggregation buckets - in that case increasing the heap size might not help and only defer the problem. In general, increasing the heap size will give you more headroom though. If you stay on the same hardware, increasing the heap size means that there is less RAM available for the page cache though so it _might_ be the case that see worse performance. In any case it is hard to accurately predict the impact and I recommend that you [run targeted experiments to get hard data](https://www.elastic.co/blog/seven-tips-for-better-elasticsearch-benchmarks) but I hope I could provide some pointers.

Daniel

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 29, 2019, 10:31am UTC](https://discuss.elastic.co/t/server-stopping-by-outofmemoryerror-java-heap-space/170221/3 "2019-03-29T10:31:49Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
