# Discourse Randomly Does Not run or Rebuild

**URL:** https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231
**Category:** Self-hosting
**Tags:** postgres
**Created:** [March 20, 2025, 9:28pm UTC](https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231 "2025-03-20T21:28:11Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![joshhabka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshhabka/32/452328_2.png) [@joshhabka](https://meta.discourse.org/u/joshhabka)
#### Post date: [March 20, 2025, 9:28pm UTC](https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231/1 "2025-03-20T21:28:11Z")

</div>

Out of nowhere, Discourse is no longer wanting to run and is not even rebuilding using ./launcher rebuild app. I commented out all plugins too.

Here is the logs when I try to start it: [https://codefile.io/f/8XUuOqyEDd](https://codefile.io/f/8XUuOqyEDd)

Here are the logs when I use ./launcher rebuild app. I see something about “failed listening on port 6379 (TCP) aborting” but I have nothing running on that port!

[https://codefile.io/f/zxCBRzEOA9](https://codefile.io/f/zxCBRzEOA9)

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [March 20, 2025, 10:12pm UTC](https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231/3 "2025-03-20T22:12:37Z")

</div>

> [@joshhabka](#):
>
> `failed listening on port 6379 (TCP)`

I don’t think it’s related to your issue. This warning often (always?) appear during a rebuild.

> `error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: Connection refused`

I think your issue more likely comes from this.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [March 20, 2025, 10:17pm UTC](https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231/4 "2025-03-20T22:17:41Z")

</div>

This might give clues:

> [@Cannot rebuild app,](https://meta.discourse.org/t/cannot-rebuild-app/350172/3):
>
> socat[33] E connect(, AF=1 “/shared/postgres\_run/.s.PGSQL.5432”, 36): Connection refused Based on that error, it appears the database did not shut down cleanly when you stopped the app container. This typically happens when you have some application(s) still connecting to the database. I [posted a reply](https://meta.discourse.org/t/postgresql-15-update/349515/69) in the other topic.

---

<div class="post-metadata">

### Author: ![joshhabka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshhabka/32/452328_2.png) [@joshhabka](https://meta.discourse.org/u/joshhabka)
#### Post date: [March 20, 2025, 11:40pm UTC](https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231/5 "2025-03-20T23:40:31Z")

</div>

Would this be what is causing it to not work when I run it(without doing any ./launcher rebuild app)?

---

<div class="post-metadata">

### Author: ![joshhabka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshhabka/32/452328_2.png) [@joshhabka](https://meta.discourse.org/u/joshhabka)
#### Post date: [March 21, 2025, 5:15am UTC](https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231/6 "2025-03-21T05:15:23Z")

</div>

I stopped all other services on my server and updated to the latest Ubuntu LTS and it still shows this:

```Caused
PG::ConnectionBad: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: Connection refused (PG::ConnectionBad)
        Is the server running locally and accepting connections on that socket?

```

which is what I would think the error is.

---

<div class="post-metadata">

### Author: ![joshhabka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshhabka/32/452328_2.png) [@joshhabka](https://meta.discourse.org/u/joshhabka)
#### Post date: [March 21, 2025, 5:37am UTC](https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231/7 "2025-03-21T05:37:53Z")

</div>

Swapping templates with 13 and even 15 did not solve the issue, which is what was shown in the referenced post.

Caused by:  
PG::ConnectionBad: connection to server on socket “/var/run/postgresql/.s.PGSQL.5432” failed: No such file or directory (PG::ConnectionBad)  
Is the server running locally and accepting connections on that socket?

---

<div class="post-metadata">

### Author: ![mwaniki](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mwaniki/32/313097_2.png) [@mwaniki](https://meta.discourse.org/u/mwaniki)
#### Post date: [March 21, 2025, 6:58am UTC](https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231/8 "2025-03-21T06:58:40Z")

</div>

> [@joshhabka](#):
>
> Here is the logs when I try to start it: [https://codefile.io/f/8XUuOqyEDd](https://codefile.io/f/8XUuOqyEDd)

> timeout: down: postgres: 1s, normally up, want up

Seems like the database isn’t starting up correctly. The logs show it appears to occasionally start up properly, but only for a short time, so that could be a red herring.

> ok: run: postgres: (pid 315501) 0s

The postgres logs could have some hint of the problem, especially when trying to start the app container.

```plaintext
tail -f shared/standalone/log/var-log/postgres/current

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 21, 2025, 1:38pm UTC](https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231/9 "2025-03-21T13:38:37Z")

</div>

Did you do the [PostgreSQL 15 update](https://meta.discourse.org/t/postgresql-15-update/349515)

I too think it’s about an unclean shutdown. If you’ve got a backup, what I would do is spin up a new vm and restore it. You can follow [Move a Discourse site to another VPS with rsync](https://meta.discourse.org/t/move-a-discourse-site-to-another-vps-with-rsync/43812) and exclude `postgres_*`.

The alternative, which is your only option if you don’t have a backup, will be to figure out a bunch of stuff about postgres that you don’t want to learn about.

---

<div class="post-metadata">

### Author: ![joshhabka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshhabka/32/452328_2.png) [@joshhabka](https://meta.discourse.org/u/joshhabka)
#### Post date: [March 22, 2025, 12:33am UTC](https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231/10 "2025-03-22T00:33:09Z")

</div>

How can I access my backups if my forum is down(as in I cannot go to admin settings and download a backup)?

I also did not try to migrate anything, I have been using it as normal and updating via the web ui? Why would the database have an unclean shutdown??

---

<div class="post-metadata">

### Author: ![joshhabka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshhabka/32/452328_2.png) [@joshhabka](https://meta.discourse.org/u/joshhabka)
#### Post date: [March 22, 2025, 12:33am UTC](https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231/11 "2025-03-22T00:33:58Z")

</div>

> [@mwaniki](#):
>
> `tail -f shared/standalone/log/var-log/postgres/current`

I will provide the Postgres logs, one second

---

<div class="post-metadata">

### Author: ![joshhabka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshhabka/32/452328_2.png) [@joshhabka](https://meta.discourse.org/u/joshhabka)
#### Post date: [March 22, 2025, 12:35am UTC](https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231/12 "2025-03-22T00:35:32Z")

</div>

2025-03-22 00:30:44.110 UTC [4922] FATAL: lock file “postmaster.pid” is empty  
2025-03-22 00:30:44.110 UTC [4922] HINT: Either another server is starting, or the lock file is the remnant of a previous server startup crash.  
2025-03-22 00:30:45.127 UTC [4964] FATAL: lock file “postmaster.pid” is empty  
2025-03-22 00:30:45.127 UTC [4964] HINT: Either another server is starting, or the lock file is the remnant of a previous server startup crash.  
2025-03-22 00:30:46.151 UTC [4966] FATAL: lock file “postmaster.pid” is empty  
2025-03-22 00:30:46.151 UTC [4966] HINT: Either another server is starting, or the lock file is the remnant of a previous server startup crash.  
2025-03-22 00:30:47.168 UTC [4970] FATAL: lock file “postmaster.pid” is empty  
2025-03-22 00:30:47.168 UTC [4970] HINT: Either another server is starting, or the lock file is the remnant of a previous server startup crash.  
2025-03-22 00:30:48.192 UTC [4977] FATAL: lock file “postmaster.pid” is empty  
2025-03-22 00:30:48.192 UTC [4977] HINT: Either another server is starting, or the lock file is the remnant of a previous server startup crash.

---

<div class="post-metadata">

### Author: ![joshhabka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshhabka/32/452328_2.png) [@joshhabka](https://meta.discourse.org/u/joshhabka)
#### Post date: [March 22, 2025, 12:41am UTC](https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231/13 "2025-03-22T00:41:23Z")

</div>

-rw------- 1 syslog kvm 0 Mar 18 19:48 /var/discourse/shared/standalone/postgres\_data/postmaster.pid

This is where my lockfile is

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 22, 2025, 3:23am UTC](https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231/14 "2025-03-22T03:23:03Z")

</div>

> [@joshhabka](#):
>
> How can I access my backups if my forum is down

They are in /var/discourse/shared/standalone/backups/default

If you follow the rsync instructions I linked earlier, you’ll get them.

> [@joshhabka](#):
>
> Why would the database have an unclean shutdown?

It crashed or the server rebooted or something things happen.

The database is “migrated” from one set of tables (tables get added and changed) to another on most upgrades.

You might try to stop the container and delete that lock file

And look in PG\_VERSION to see what version you have, since I think you tried changing the template.

---

<div class="post-metadata">

### Author: ![joshhabka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshhabka/32/452328_2.png) [@joshhabka](https://meta.discourse.org/u/joshhabka)
#### Post date: [March 22, 2025, 3:24am UTC](https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231/15 "2025-03-22T03:24:34Z")

</div>

Yes, I did try to change after I saw the error.

So, would I do rm /var/discourse/shared/standalone/postgres\_data/postmaster.pid ? to delete the lockfile then try to rebuild

Also thank you for helping me with this

---

<div class="post-metadata">

### Author: ![joshhabka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshhabka/32/452328_2.png) [@joshhabka](https://meta.discourse.org/u/joshhabka)
#### Post date: [March 22, 2025, 3:27am UTC](https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231/16 "2025-03-22T03:27:59Z")

</div>

> [@joshhabka](#):
>
> rm /var/discourse/shared/standalone/postgres\_data/postmaster.pid

I would do this command to delete the lockfile?

---

<div class="post-metadata">

### Author: ![joshhabka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joshhabka/32/452328_2.png) [@joshhabka](https://meta.discourse.org/u/joshhabka)
#### Post date: [March 22, 2025, 3:51am UTC](https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231/17 "2025-03-22T03:51:15Z")

</div>

rm /var/discourse/shared/standalone/postgres\_data/postmaster.pid was the solution, thank you!

---

<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: [April 21, 2025, 3:51am UTC](https://meta.discourse.org/t/discourse-randomly-does-not-run-or-rebuild/358231/18 "2025-04-21T03:51:43Z")

</div>

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