# 502 bad gateway on specific searches

**URL:** https://meta.discourse.org/t/502-bad-gateway-on-specific-searches/104616
**Category:** Self-hosting
**Created:** [December 19, 2018, 2:53am UTC](https://meta.discourse.org/t/502-bad-gateway-on-specific-searches/104616 "2018-12-19T02:53:06Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![CT075](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ct075/32/375367_2.png) [@CT075](https://meta.discourse.org/u/CT075)
#### Post date: [December 19, 2018, 2:53am UTC](https://meta.discourse.org/t/502-bad-gateway-on-specific-searches/104616/1 "2018-12-19T02:53:06Z")

</div>

(I’ve read [this thread](https://meta.discourse.org/t/bad-gateway-502-errors-on-some-specific-searches-in-some-specific-categories/57092), but it didn’t seem to help)

We recently updated our site to a more recent version of docker + discourse, and several users reported general site slowdown (I suspect this has to do more with disk space than the site itself). Something we did notice, however, is that now specific searches are giving us a 502 bad gateway (this seems to be category-independent). We also upgraded our postgres install as part of the rebuild process.

As with the linked thread, it seems that the searches are timing out with zero hits (the failing searches are things like “`abcd`” or similar nonsense).

Two things:

- It was mentioned this could be fixed with a “Postgres statistics rebuild”. I googled this, but was having difficulty determining what actual actionable steps we could take to achieve this. I would really prefer an option that avoids reinstalling from scratch + restoring backup.

- Can I submit this as a bug report/feature request? I think having a more informative error than 502 would be a good idea, as I’m sure many people would believe this to be a fault of the configuration (myself included! I haven’t ruled out the possibility)

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [December 19, 2018, 3:26am UTC](https://meta.discourse.org/t/502-bad-gateway-on-specific-searches/104616/2 "2018-12-19T03:26:41Z")

</div>

How many posts the forum have?

What is the forum hardware specs?

What is the error logged in the logs page during those 502 errors?

If you have many posts and a underspecified server, the setting `search prefer recent posts` may help.

---

<div class="post-metadata">

### Author: ![CT075](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ct075/32/375367_2.png) [@CT075](https://meta.discourse.org/u/CT075)
#### Post date: [December 19, 2018, 3:53am UTC](https://meta.discourse.org/t/502-bad-gateway-on-specific-searches/104616/3 "2018-12-19T03:53:00Z")

</div>

…as I went to go look up that information, I tried some of the failing searches and found that they now work perfectly. Amazing? Thanks anyway. I wonder if it was just postgres “warming up”.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [December 19, 2018, 12:47pm UTC](https://meta.discourse.org/t/502-bad-gateway-on-specific-searches/104616/5 "2018-12-19T12:47:59Z")

</div>

> [@CT075](#):
>
> I wonder if it was just postgres “warming up”.

Very likely, if for any reason a search takes longer than 30 seconds you will see this kind of timeout. The web worker gets killed and NGINX sends a 502.

- How many topics/posts are there on your forum?
- What are the specs of your server?
- If this is an import it may make sense to run a full vacuum [VACUUM FULL - PostgreSQL wiki](https://wiki.postgresql.org/wiki/VACUUM_FULL) `./launcher enter app` and then `sudo -u postgres psql discourse` …

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [January 18, 2019, 12:52pm UTC](https://meta.discourse.org/t/502-bad-gateway-on-specific-searches/104616/6 "2019-01-18T12:52:56Z")

</div>

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