# Discourse setup on local server: PostgreSQL and setup script issues

**URL:** https://meta.discourse.org/t/discourse-setup-on-local-server-postgresql-and-setup-script-issues/289877
**Category:** Self-hosting
**Tags:** sql-query
**Created:** [December 27, 2023, 3:04pm UTC](https://meta.discourse.org/t/discourse-setup-on-local-server-postgresql-and-setup-script-issues/289877 "2023-12-27T15:04:12Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![a\_bet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/a_bet/32/350822_2.png) [@a\_bet](https://meta.discourse.org/u/a_bet)
#### Post date: [December 27, 2023, 3:04pm UTC](https://meta.discourse.org/t/discourse-setup-on-local-server-postgresql-and-setup-script-issues/289877/1 "2023-12-27T15:04:12Z")

</div>

Hello Discourse Community,  
I am a newbie when it comes to docker and linux sysadmin tasks in general. I am trying to convince my company to use Discourse and they asked me a demo first. So here I am trying to bring it to life on our servers.  
I’ve been attempting to set up Discourse on a local server and have encountered some issues that I’m hoping to get assistance with. Below is a summary of my setup and the steps I’ve taken so far:

**System Setup:**

- Operating System: Ubuntu 20.04.6 LTS
- Docker Version: 24.0.5, build 24.0.5-0ubuntu1~20.04.1
- Discourse Version: 3.2

**Issue:**  
I followed the official guide for installing Discourse on a cloud server ([discourse/docs/INSTALL-cloud.md at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/main/docs/INSTALL-cloud.md)), but I’m running into errors with the `discourse-setup` script related to PostgreSQL.

**Steps Taken:**

1. I confirmed that PostgreSQL is running by checking the process list.
2. I verified that PostgreSQL is listening on the correct port (5432) and that the Unix socket file exists.
3. I encountered errors indicating that the “discourse” database and user already exist, but when I checked using the `psql` command, neither the database nor the user were listed.

Here the commands I used:

- Checked PostgreSQL processes: `ps aux | grep postgres`
- Checked PostgreSQL listening port: `sudo netstat -plunt | grep postgres`
- Checked Unix socket file: `ls -l /var/run/postgresql/.s.PGSQL.5432`
- Attempted to drop the “discourse” database and user: `su postgres -c 'psql -c "DROP DATABASE IF EXISTS discourse;"'` and `su postgres -c 'psql -c "DROP USER IF EXISTS discourse;"'`
- Listed databases and users: `psql -c "\l"` and `psql -c "\du"`

**Errors Encountered:**

- `ERROR: database "discourse" already exists`
- `ERROR: role "discourse" already exists`
- `psql: error: FATAL: role "root" does not exist`

Despite these errors, the “discourse” database and user do not appear to exist when checked directly in PostgreSQL.  
There are other errors in the log but I believe these are the relevant ones at least for now.

I would greatly appreciate any guidance or suggestions on how to resolve these issues. Has anyone else encountered similar problems, or does anyone have insights into what might be going wrong?

Thank you in advance for your help,  
Andrea

---

<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: [December 28, 2023, 1:55am UTC](https://meta.discourse.org/t/discourse-setup-on-local-server-postgresql-and-setup-script-issues/289877/2 "2023-12-28T01:55:46Z")

</div>

> [@a\_bet](#):
>
> - I confirmed that PostgreSQL is running by checking the process list.
> - I verified that PostgreSQL is listening on the correct port (5432) and that the Unix socket file exists.

You don’t need to install postgres. In a [standard install](https://meta.discourse.org/t/142537?silent=true), Discourse has its own postgres in the container. I recommend that you un-install or remove postgres. Do you have reason to use a pre-existing postgres? Is anything else running on this machine?

I don’t think those are errors, but just debugging messages.

What did it say at the end of the script?

---

<div class="post-metadata">

### Author: ![a\_bet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/a_bet/32/350822_2.png) [@a\_bet](https://meta.discourse.org/u/a_bet)
#### Post date: [December 28, 2023, 9:58am UTC](https://meta.discourse.org/t/discourse-setup-on-local-server-postgresql-and-setup-script-issues/289877/3 "2023-12-28T09:58:27Z")

</div>

Hi @pfaffman,  
thanks for the reply.

No this machine is dedicated to discord, I intalled postgre after noticing those errors.

I wish I could attach the log but I still can’t.

Here’s the final part:

```plaintext
FAILED
--------------------
Pups::ExecError: cd /var/www/discourse && sudo -H -E -u discourse bash -c '
  set -o errexit
  if [$(git rev-parse --is-shallow-repository) == "true"]; then
      git remote set-branches --add origin main
      git remote set-branches origin tests-passed
      git fetch --depth 1 origin tests-passed
  else
      git fetch --tags --prune-tags --prune --force origin
  fi
' failed with return #<Process::Status: pid 146 exit 128>
Location of failure: /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
exec failed with the params {"cd"=>"$home", "hook"=>"code", "cmd"=>["sudo -H -E -u discourse git reset --hard", "sudo -H -E -u discourse git clean -f", "sudo -H -E -u discourse bash -c '\n set -o errexit\n if [ $(git rev-parse --is-shallow-repository) == \"true\" 
]; then\n git remote set-branches --add origin main\n git remote set-branches origin $version\n git fetch --depth 1 origin $version\n else\n git fetch --tags --prune-tags --prune --force origin\n fi\n'", "sudo -H -E -u discourse bash -c '\n set -o errexit\n if [[$(git symbolic-ref --short HEAD) == $version]] ; then\n git pull\n else\n git -c advice.detachedHead=false checkout $version\n fi\n'", "sudo -H -E -u discourse git config user.discourse-version $version", "mkdir -p tmp", "chown discourse:www-data tmp", "mkdir -p tmp/pids", "mkdir -p tmp/sockets", "touch tmp/.gitkeep", "mkdir -p /shared/log/rails", "bash -c \"touch -a /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr,sidekiq}.log\"", "bash -c \"ln -s /shared/log/rails/{production,production_errors,unicorn.stdout,unicorn.stderr,sidekiq}.log $home/log\"", "bash -c \"mkdir -p /shared/{uploads,backups}\"", "bash -c \"ln -s /shared/{uploads,backups} $home/public\"", "bash -c \"mkdir -p /shared/tmp/{backups,restores}\"", "bash -c \"ln -s /shared/tmp/{backups,restores} $home/tmp\"", "chown -R discourse:www-data /shared/log/rails /shared/uploads /shared/backups /shared/tmp", "[! -d public/plugins] || find public/plugins/ -maxdepth 1 -xtype l -delete"]}
bootstrap failed with exit code 128
**FAILED TO BOOTSTRAP** please scroll up and look for earlier error messages, there may be more than one.

```

I will now try to uninstall postgre.

Thanks,  
Andrea

---

<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: [December 28, 2023, 11:36am UTC](https://meta.discourse.org/t/discourse-setup-on-local-server-postgresql-and-setup-script-issues/289877/4 "2023-12-28T11:36:28Z")

</div>

> [@a\_bet](#):
>
> ```plaintext
> ' failed with return #<Process::Status: pid 146 exit 128>
> 
> ```

You’re out of memory. You need to add swap and/or more RAM.

What does

`free -h`

Give you?

---

<div class="post-metadata">

### Author: ![a\_bet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/a_bet/32/350822_2.png) [@a\_bet](https://meta.discourse.org/u/a_bet)
#### Post date: [December 28, 2023, 5:59pm UTC](https://meta.discourse.org/t/discourse-setup-on-local-server-postgresql-and-setup-script-issues/289877/5 "2023-12-28T17:59:04Z")

</div>

I have roughly 7GB available

```plaintext
              total used free shared buff/cache available
Mem: 7.8Gi 319Mi 599Mi 13Mi 6.9Gi 7.1Gi
Swap: 975Mi 2.0Mi 973Mi

```

The guide is suggesting ~2GB.

```plaintext
The default of 1 GB RAM works fine for small Discourse communities. We recommend 2 GB RAM for larger communities.

```

Am I missing something?

---

<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: [December 28, 2023, 6:11pm UTC](https://meta.discourse.org/t/discourse-setup-on-local-server-postgresql-and-setup-script-issues/289877/6 "2023-12-28T18:11:03Z")

</div>

Hmm. That is odd. There have been some strange issues with ram requirements reported lately. You might just try again a few times. Some reports say that it’s failing intermittently.

Edit: sorry. 127 is ram. 128 is unknown.

You’re doing a [standard install](https://meta.discourse.org/t/142537?silent=true) from scratch running discourse-setup? (you say so in OP)

Are you behind some kind of firewall that might keep the server from accessing github and other repositories?

---

<div class="post-metadata">

### Author: ![a\_bet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/a_bet/32/350822_2.png) [@a\_bet](https://meta.discourse.org/u/a_bet)
#### Post date: [December 28, 2023, 6:20pm UTC](https://meta.discourse.org/t/discourse-setup-on-local-server-postgresql-and-setup-script-issues/289877/7 "2023-12-28T18:20:05Z")

</div>

Yes correct, I am following the github guide.  
If the problem it is not postgre but the last message, here’s the point in the log where it fails

```plaintext
  set -o errexit
  if [$(git rev-parse --is-shallow-repository) == "true"]; then
      git remote set-branches --add origin main
      git remote set-branches origin tests-passed
      git fetch --depth 1 origin tests-passed
  else
      git fetch --tags --prune-tags --prune --force origin
  fi
'
fatal: unable to access 'https://github.com/discourse/discourse.git/': server certificate verification failed. CAfile: none CRLfile: 
none

```

Looks like I cannot connet to github properly, even though I am able to clone the repo from that machine.

---

<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: [December 28, 2023, 6:46pm UTC](https://meta.discourse.org/t/discourse-setup-on-local-server-postgresql-and-setup-script-issues/289877/8 "2023-12-28T18:46:15Z")

</div>

It’s a docker networking issue. How did you install docker? Consider uninstall and try some other way.

Do you have a firewall on the os or your network? I could also be a dns issue. It’s always dns, as they say.

---

<div class="post-metadata">

### Author: ![a\_bet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/a_bet/32/350822_2.png) [@a\_bet](https://meta.discourse.org/u/a_bet)
#### Post date: [December 29, 2023, 12:16pm UTC](https://meta.discourse.org/t/discourse-setup-on-local-server-postgresql-and-setup-script-issues/289877/9 "2023-12-29T12:16:57Z")

</div>

I know that we don’t have a firewall on the os atm, but for docker installation details I need to talk with IT.  
Do you have any idea of which DNS issue we might be encountering? Any sections of the log or debug messages that can help (I still can’t attach files)?

---

<div class="post-metadata">

### Author: ![a\_bet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/a_bet/32/350822_2.png) [@a\_bet](https://meta.discourse.org/u/a_bet)
#### Post date: [January 3, 2024, 1:28pm UTC](https://meta.discourse.org/t/discourse-setup-on-local-server-postgresql-and-setup-script-issues/289877/10 "2024-01-03T13:28:45Z")

</div>

@pfaffman figured out I had the details in my shell history as well.

```plaintext
   63 sudo apt install docker.io
   64 sudo apt remove containerd runc
   65 sudo apt remove containerd
   66 curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
   67 echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
   68 sudo apt update
   69 sudo apt install docker-ce
   70 sudo apt upgrade
   71 sudo apt install docker.io

```

---

<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: [January 3, 2024, 2:15pm UTC](https://meta.discourse.org/t/discourse-setup-on-local-server-postgresql-and-setup-script-issues/289877/11 "2024-01-03T14:15:20Z")

</div>

I don’t think you can install both `docker-ce` and `docker.io`. Maybe remove both of those and then install just one of them.

I usually use `https://get.docker.com/`. What I’d do is get a new VM and use just that.
