Discourse für die Verwendung eines separaten PostgreSQL-Servers konfigurieren

Nehmen wir an, Sie verwenden AWS RDS oder einen bestehenden PostgreSQL-Server, der woanders verwaltet wird. Es ist recht einfach, Discourse dazu zu bringen, eine solche Einrichtung zu verwenden, ohne dass dem, was Discourse selbst ausführt, Superuser-Berechtigungen erteilt werden müssen. So geht’s.

Voraussetzungen

Discourse erfordert, dass die Hauptversion von PostgreSQL mit der übereinstimmt, die wir in unseren Docker-Images ausliefern; wenn Sie versuchen, mit einer neueren oder älteren Version zu arbeiten, könnte es funktionieren, aber wir garantieren es nicht, und wenn etwas in Zukunft kaputt geht, müssen Sie mit den beiden Teilen leben. Wir benötigen auch einige Erweiterungen, die im Paket postgresql-contrib (oder seinem Äquivalent) verteilt sind.

Generieren Sie zufällig ein Passwort für die Verbindung (20+ Zeichen). In dieser Anleitung verwenden wir s3kr1t als Platzhalter.

DB einrichten

Führen Sie als Datenbank-Superuser Folgendes aus:

CREATE USER discourse PASSWORD 's3kr1t';
CREATE DATABASE discourse OWNER discourse;
\c discourse
CREATE EXTENSION hstore;
CREATE EXTENSION pg_trgm;

Das ist alles, was getan werden muss, um die DB für die Verwendung durch Discourse vorzubereiten.

Discourse konfigurieren

Richten Sie Discourse wie gewohnt ein und bearbeiten Sie dann containers/app.yml wie folgt:

  1. Entfernen Sie die Zeile - "templates/postgres.template.yml" unter dem Schlüssel templates auf oberster Ebene (etwa am Anfang der Datei);

  2. Setzen Sie unter dem Schlüssel env auf oberster Ebene Folgendes:

     DISCOURSE_DB_USERNAME: discourse
     DISCOURSE_DB_PASSWORD: s3kr1t
     DISCOURSE_DB_HOST: <IP oder Hostname>
     DISCOURSE_DB_NAME: discourse
    
  3. Sie müssen auch Folgendes festlegen, wenn Ihre Datenbank nicht den Standardport (5432) verwendet:

    DISCOURSE_DB_PORT: <Port>
    DISCOURSE_DB_BACKUP_PORT: <Port>
    
  4. Bauen Sie mit ./launcher rebuild app neu auf, und Sie sollten einsatzbereit sein.

39 „Gefällt mir“
Install the docker version with a remote postgresql
Using a PGSQL database outside of Docker?
Installation on AWS
Is there a way to install Discourse without the provided scripts?
Error when attempting install
Installation Help required
Database Replication
pgSQL root access - without? (docker)
I want to keep PostgreSQL database on separate server [standard docker install]
Simplified Discourse install?
Running Discourse with pg_bouncer and a separate DB
Improve my DO droplet setup
Switching to another Redis instance?
Using Discourse with external PostgreSQL and Redis
How to provide HA
How do you scale discourse horizontally?
Can I install Discourse with my own Redis and Postgres?
Running discourse with Postgres running in docker
Moving postgres db to central db server: build error
Search no longer works after 3.1.0.beta1 update
Move from standalone container to separate web and data containers
Move from standalone container to separate web and data containers
How to resolve Pups exec errors during Discourse bootstrap
Can Discourse Support a Shared Forum for Two Websites with Distinct Styling?
Can Discourse Support a Shared Forum for Two Websites with Distinct Styling?
Not using volumes (or automatically using S3) when hosting with Docker
Move from standalone container to separate web and data containers
Which versions of AWS Aurora Postgres are supported?
Why is "rebuild" so tightly coupled to container run status?
Move from standalone container to separate web and data containers
Can I install Discourse with my own Redis and Postgres?
Error while connecting database from aws postgresql 10.1
Relation "selected" does not exist with external Postgres
Error executing 'postInstallation': Purging temp files
Discourse Database Question/Support
Separate psql server / migrate
Improving Instance Performance (Megatopics, Database Size and Extreme Load)
pgSQL root access - without? (docker)
Multiple Daily Backups
Rebuilding gives db:migrate error due to broken plugin
Can I use a later version of Postgres than Discourse?
Trust level freeze
Multiple backup schedules
Error setting up with separate Redis
Migrate quickly to separate web and data containers
External postgres setup not working
Discourse Image Builder for Gitlab CI/CD Pipelines
Any other locations where database connection IP / hostname set other than DISCOURSE_DB_HOST in app.yml?
Move from standalone container to separate web and data containers

There is an additional setting, DISCOURSE_DB_PORT, which can, naturally, configure the TCP port number. @mpalmer please update the post?

Thanks

This isn’t supposed to be a comprehensive description of every possible way you can configure your database connection, rather it’s a quick howto to make things a bit easier.

2 „Gefällt mir“

Is there somewhere more authoritative for this documentation? I even tried (unsuccessfully) to track down the source code for this…!

Thanks

2 „Gefällt mir“

The discourse_docker repo is where all that lives.

2 „Gefällt mir“

Thanks for the pointer, I’m embarrassed to admit I’ve gone through almost an entire setup without realising the wealth of documentation on that page.

That said, the only reference to DISCOURSE_DB_PORT is in web.template.yml: https://github.com/discourse/discourse_docker/search?utf8=✓&q=DISCOURSE_DB_PORT&type=

3 „Gefällt mir“

Yes, it could probably stand to be promoted into the default “web_only” template, with a suitably explanatory comment. PRs welcome!

3 „Gefällt mir“

Hi, first thanks for this guide. I try to setup external postgresql on the same machine, where docker installed. Do I need to bind port of my external postgresql 5432 to docker? Could anybody assist how to do it, using Discourse configuration file?

Your question doesn’t make any sense. You don’t bind external listening ports to Docker.

1 „Gefällt mir“

I follow the instruction a the top. First I set up an ordinary docker, it works. Then I want to switch the application to external postgres. When I rebuild the app, I get an error

Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?

My server has not a FQDN yet, I use 127.0.0.1 as a DB host. The database is listening on 127.0.0.1:5432, I am able to connect with psql. Where am I wrong? I tried to play with pg_hba.conf but no success, of course.

Hi guys, possible of my personal server configuration or what else… But I found a solution by running a docker in hosted mode (not bridged as default):

/var/discourse/launcher rebuild app --docker-args --net=host --skip-mac-address

After that the discourse engine could connect to external postgres database, run at 127.0.0.1:5432. Default bridged mode does not allow docker to access ports listening at the host without tricks.

Hope this might help somebody.

1 „Gefällt mir“

When I run ./launcher rebuild app, I get this error PG::ConnectionBad: timeout expired during the bundle exec rake db:migrate. Has anyone comes across this issue? I can successfully access the database with a postgres client.

1 „Gefällt mir“

I have not tried this yet.
Here it is suggested to remove web.template.yml but i see bunch of other stuff happening in discourse_docker/templates/web.template.yml at master · discourse/discourse_docker · GitHub

What about that ?

No it doesn’t. 

5 „Gefällt mir“

Can you take the same approach for Redis?

remove “templates/redis.template.yml” & add a line in the app.yml file for DISCOURSE_REDIS_HOST

Thanks in advance

Todd

Is there an obvious benefit that I’m maybe missing?

(I assume running redis on a separate machine will just add unwanted latency if nothing else)

Just that its managed & 1 less thing to worry about

You don’t have to worry about redis that ships with discourse. I haven’t seen it failing on me in the last 1 year of self hosting discourse.

2 „Gefällt mir“

Thanks @itsbhanusharma,

Do you know what the process would be even if I did?

This article, albeit a little old says to add

DISCOURSE_REDIS_HOST

which is the same format as the article you so kindly mentioned, so that all makes sense.

Just not sure where to put it (maybe underneath other changes made to the app.yml file or maybe in the "templates/redis.template.yml")

and also

what if any lines or files need to be deleted

Thanks

Todd

That variable should go into the file where you declared postgres variables. Just be warned that exposing redis for a production environment is lethal. (Because of poor security practices of redis itself)