Discourse setup on local server: PostgreSQL and setup script issues

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

I followed the official guide for installing Discourse on a cloud server (discourse/docs/INSTALL-cloud.md at main · discourse/discourse · GitHub), 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,

You don’t need to install postgres. In a standard install, 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?

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:

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
      git fetch --tags --prune-tags --prune --force origin
' 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.


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

What does

free -h

Give you?

1 Like

I have roughly 7GB available

              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.

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

Am I missing something?

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 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?

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

  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
      git fetch --tags --prune-tags --prune --force origin
fatal: unable to access 'https://github.com/discourse/discourse.git/': server certificate verification failed. CAfile: none CRLfile: 

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

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.

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)?

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

   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

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.