# Discourse: PG::InternalError (ERROR: subplan "SubPlan 2" was not initialized CONTEXT: parallel worker )

**URL:** <https://community.unix.com/t/discourse-pg-internalerror-error-subplan-subplan-2-was-not-initialized-context-parallel-worker/384427>\
**Category:** Discourse System Administration\
**Created:** [November 4, 2021, 4:09am UTC](https://community.unix.com/t/discourse-pg-internalerror-error-subplan-subplan-2-was-not-initialized-context-parallel-worker/384427 "2021-11-04T04:09:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [November 4, 2021, 4:09am UTC](https://community.unix.com/t/discourse-pg-internalerror-error-subplan-subplan-2-was-not-initialized-context-parallel-worker/384427/1 "2021-11-04T04:09:04Z")

</div>

Looks like we will need to rebuild our (single) data container soon to get rid of this error in Discourse. Or, I will just build Discourse for scratch and restore the data and switch over when it is done to minimize down time.

```shell
PG::InternalError (ERROR: subplan "SubPlan 2" was not initialized
CONTEXT: parallel worker
)
app/models/private_message_topic_tracking_state.rb:29:in `report'
app/controllers/users_controller.rb:323:in `private_message_topic_tracking_state'
app/controllers/application_controller.rb:399:in `block in with_resolved_locale'
app/controllers/application_controller.rb:399:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:71:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:356:in `call'
config/initializers/100-quiet_logger.rb:23:in `call'
config/initializers/100-silence_logger.rb:31:in `call'
lib/middleware/enforce_hostname.rb:23:in `call'
lib/middleware/request_tracker.rb:187:in `call'

```

This error appears when using PMs / DMs (direct messages) in my account; but no one else has reported it.

---

<div class="post-metadata">

**Author:** ![vbe](https://community.unix.com/user_avatar/community.unix.com/vbe/32/266_2.png) [@vbe](https://community.unix.com/u/vbe)\
**Post date:** [November 4, 2021, 12:57pm UTC](https://community.unix.com/t/discourse-pg-internalerror-error-subplan-subplan-2-was-not-initialized-context-parallel-worker/384427/2 "2021-11-04T12:57:35Z")

</div>

> [@Neo](#):
>
> ```plaintext
> PG::InternalError (ERROR: subplan "SubPlan 2" was not initialized
> CONTEXT: parallel worker
> 
> ```

> **[Postgres error: subplan "SubPlan 2" was not initialized](https://meta.discourse.org/t/postgres-error-subplan-subplan-2-was-not-initialized/205440)**
>
> I have a user that says he’s getting 500 errors " when viewing random posts." Looking at the logs, all I see is these, which appear to affect only this user. This is a standard install up to date with PG13. I don’t see these errors for any other...

---

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [November 4, 2021, 1:10pm UTC](https://community.unix.com/t/discourse-pg-internalerror-error-subplan-subplan-2-was-not-initialized-context-parallel-worker/384427/3 "2021-11-04T13:10:15Z")

</div>

Rebuilding this data container as Jay did in that topic will cause the site to be off line for maybe 30 minutes.

---

<div class="post-metadata">

**Author:** ![vbe](https://community.unix.com/user_avatar/community.unix.com/vbe/32/266_2.png) [@vbe](https://community.unix.com/u/vbe)\
**Post date:** [November 4, 2021, 1:23pm UTC](https://community.unix.com/t/discourse-pg-internalerror-error-subplan-subplan-2-was-not-initialized-context-parallel-worker/384427/4 "2021-11-04T13:23:20Z")

</div>

[afael dos Santos Silva](https://meta.discourse.org/u/Falco)[Falco](https://meta.discourse.org/u/Falco)[team](https://meta.discourse.org/g/team)

[28d](https://meta.discourse.org/t/postgres-error-subplan-subplan-2-was-not-initialized/205440/2?u=victor_berridge)

That is indeed a PostgreSQL bug that was solved in latest minor version. Can you do a rebuild? That will update the PostgreSQL to latest minor.

Ok I saw this at the time but as Jay said it was one user, I thought we were not affected... 😕

---

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [November 4, 2021, 1:31pm UTC](https://community.unix.com/t/discourse-pg-internalerror-error-subplan-subplan-2-was-not-initialized-context-parallel-worker/384427/5 "2021-11-04T13:31:44Z")

</div>

Guess I will rebuild the data container this weekend…

---

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [November 5, 2021, 1:27am UTC](https://community.unix.com/t/discourse-pg-internalerror-error-subplan-subplan-2-was-not-initialized-context-parallel-worker/384427/6 "2021-11-05T01:27:30Z")

</div>

```ruby
community# docker exec -it pg13 bash -c 'psql --version'
psql (PostgreSQL) 13.1 (Debian 13.1-1.pgdg100+1)

```

---

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [November 5, 2021, 2:10am UTC](https://community.unix.com/t/discourse-pg-internalerror-error-subplan-subplan-2-was-not-initialized-context-parallel-worker/384427/7 "2021-11-05T02:10:36Z")

</div>

Rebuilding our data container did not work as per the meta instructions (above); but I managed to improvise and 30 minutes later, it's running again and all is good.

```ruby
community# docker exec -it pg13 bash -c 'psql --version'
psql (PostgreSQL) 13.4 (Debian 13.4-4.pgdg100+1)

```

As I understand meta from the past, they consider multi-containers solutions "not supported" so it is not a surprise that the instructions above did not work for us. I knew going into the data container rebuild that it would not go smoothly per the meta-talk on this bug.

The good news, is that bug is quashed, I assume, with the PG upgrade and new data container.

See Also:

[https://www.postgresql.org/docs/release/13.4/](https://www.postgresql.org/docs/release/13.4/)

---

<div class="post-metadata">

**Author:** ![Neo](https://community.unix.com/user_avatar/community.unix.com/neo/32/22838_2.png) [@Neo](https://community.unix.com/u/Neo)\
**Post date:** [November 5, 2021, 4:26am UTC](https://community.unix.com/t/discourse-pg-internalerror-error-subplan-subplan-2-was-not-initialized-context-parallel-worker/384427/8 "2021-11-05T04:26:22Z")

</div>

Note:

After this upgrade, although not required, performed:

```shell
VACUUM ANALYZE:
REINDEX SCHEMA CONCURRENTLY public;

```

.... just because I was already working on the DB and seems like a good housekeeping thing to do.

The site does seem a little faster after housekeeping; but that could all be in my imagination. I notice our cars and motorcycles always seem to run better after we wash them 🙂
