# PG throws could not resize shared memory segment error

**URL:** https://meta.discourse.org/t/pg-throws-could-not-resize-shared-memory-segment-error/84744
**Category:** Self-hosting
**Created:** [April 6, 2018, 4:52pm UTC](https://meta.discourse.org/t/pg-throws-could-not-resize-shared-memory-segment-error/84744 "2018-04-06T16:52:20Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Gunnar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gunnar/32/119647_2.png) [@Gunnar](https://meta.discourse.org/u/Gunnar)
#### Post date: [April 6, 2018, 4:52pm UTC](https://meta.discourse.org/t/pg-throws-could-not-resize-shared-memory-segment-error/84744/1 "2018-04-06T16:52:21Z")

</div>

After upgrading (with ‘launcher rebuild app’ times two) to Postgres 10, we’ve started seeing errors like this in /logs:

```plaintext
Failed to handle exception in exception app middleware :
PG::DiskFull: ERROR: could not resize shared memory segment "/PostgreSQL.682207201" to 283432 bytes: No space left on device :
SELECT "topics"."id" AS t0_r0, "topics"."title" AS t0_r1, "topics"."last_posted_at" AS t0_r2, …

```

Ideas? Looks like PG is unable to increase the size of a shared memory segment, can this be tuned somewhere?

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [April 6, 2018, 5:21pm UTC](https://meta.discourse.org/t/pg-throws-could-not-resize-shared-memory-segment-error/84744/3 "2018-04-06T17:21:09Z")

</div>

This is due to the fact that docker by default [restricts shared memory size](https://www.postgresql.org/message-id/CAEepm%3D2wXSfmS601nUVCftJKRPF%3DPRX%2BDYZxMeT8M2WwLSanVQ%40mail.gmail.com) to 64MB which makes pg10 run afoul of this limitation when doing a number of scatter/gather jobs in parallel:

```plaintext
Outside the container:
supermathie@host: ~ $ df -h /dev/shm
Filesystem Size Used Avail Use% Mounted on
none 63G 1.2M 63G 1% /run/shm

Inside the container:
supermathie@host: ~ $ docker exec -it postgres-master df -h /dev/shm
Filesystem Size Used Avail Use% Mounted on
shm 64M 8.0K 64M 1% /dev/shm

```

You should raise the limit when launching the postgres container by including the `--shm-size=1g` parameter.

We’ll look at fixing this in the launcher.

(or as the link suggests, disable parallelism in pg10 with `max_parallel_workers_per_gather = 0`)

---

<div class="post-metadata">

### Author: ![Gunnar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gunnar/32/119647_2.png) [@Gunnar](https://meta.discourse.org/u/Gunnar)
#### Post date: [April 6, 2018, 6:37pm UTC](https://meta.discourse.org/t/pg-throws-could-not-resize-shared-memory-segment-error/84744/5 "2018-04-06T18:37:33Z")

</div>

> [@supermathie](#):
>
> You should raise the limit when launching the postgres container by including the --shm-size=1g parameter.
> 
> We’ll look at fixing this in the launcher.
> 
> (or as the link suggests, disable parallelism in pg10 with max\_parallel\_workers\_per\_gather = 0)

Thanks. How would I do either of those? I searched, found this post ([Starting Discourse on a Specific Docker Network - #3 by dlynch158](https://meta.discourse.org/t/starting-discourse-on-a-specific-docker-network/49401/3)) and following the example added the following line to my app.yml:

`docker_args: "--shm-size=1g"`

Then ran launcher rebuild app. That didn’t make any difference though, shm is still 64M inside the container.

Thanks,  
Gunnar

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [April 6, 2018, 6:40pm UTC](https://meta.discourse.org/t/pg-throws-could-not-resize-shared-memory-segment-error/84744/6 "2018-04-06T18:40:23Z")

</div>

You need to make sure that’s on your data container.

EDIT:

OK, adding the following:

```plaintext
docker_args: "--shm-size=512m"

```

to your `app.yml` (if all-in-one) or `data.yml` (if separate pg) containers should prevent this from happening. I’ve left the shm size at a conservative 512MB.

Or if you pull latest and relaunch it’ll now start the container with that shm size.

@tgxworld I’ve pushed a change that changes the launcher to always launch with 512MB SHM size under bootstrap or run. Should be safe.

---

<div class="post-metadata">

### Author: ![Gunnar](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gunnar/32/119647_2.png) [@Gunnar](https://meta.discourse.org/u/Gunnar)
#### Post date: [April 6, 2018, 8:53pm UTC](https://meta.discourse.org/t/pg-throws-could-not-resize-shared-memory-segment-error/84744/7 "2018-04-06T20:53:59Z")

</div>

Thanks for adding that to launcher, shm is now 512m inside our container (and yes, we have just the one).

Just FYI, for some reason, adding the

`docker_args: "--shm-size=512m"`

line to app.yml (and rebuilding) did nothing.

Thanks!  
Gunnar

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [April 6, 2018, 8:55pm UTC](https://meta.discourse.org/t/pg-throws-could-not-resize-shared-memory-segment-error/84744/8 "2018-04-06T20:55:37Z")

</div>

Weird - it did when I tested it.

But that’s OK, launcher just takes care of it now.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [June 8, 2024, 12:37pm UTC](https://meta.discourse.org/t/pg-throws-could-not-resize-shared-memory-segment-error/84744/9 "2024-06-08T12:37:37Z")

</div>

This topic was automatically closed after 2254 days. New replies are no longer allowed.
