How to access the discourse database?

Hi all,

This is probably a stupid question but how can I access the database?
Is there something equivalent to phpadmin (or another GUI) that I can use to view and edit the database of discourse? If not, then what is the best way to access/view/edit it?

「いいね!」 3

Install the Data Explorer Plugin and have at it.

If you want to do postgres command line stuff, you’ll need to enter the container to do that using the Docker enter command.

「いいね!」 5

Hi, Docker enter, but what’s next?

I tried psql but got psql: FATAL: role "root" does not exist

「いいね!」 1

postgres runs under the postgres user, per:

You want to sudo postgres psql discourse to hit the right user and database…

「いいね!」 4

I see , thank you! @sam

In case anyone else is confused the actual command you need to run inside the container is:

sudo -u postgres psql discourse

i.e. ‘Run psql discourse as the postgres user.’

「いいね!」 25

sudo -u postgres psql discourse

This lists the 156 tables:

discourse=# \dt

But basic queries return nothing:

discourse=# select * from users limit 1
discourse-#

This is a working site, so I’m sure there is data. What am I doing wrong?

「いいね!」 1

上記のマークと同じ問題です

  1. 可能であれば data-explorer プラグインを使用してください。これには、追加の安全性チェックとスキーマエクスプローラーが付属しています。
  2. psql コンソールでは、コマンドを ; セミコロンで終える必要があります。
「いいね!」 8

このプロセスについて詳しく教えていただけますか?私はコンテナの初心者で、コンテナが巨大なブラックボックスになるのではなく、Postgres DB を実際に触って遊んでみたいと思っています :slight_smile:

「いいね!」 1

@Divert さん、あなたのために用意しましたよ:

標準サポート構成の OOTB(標準設定)シングルコンテナモードを使用しているものと仮定します:

cd /var/discourse
./launcher enter app
su discourse
psql discourse

すべてが正常に動作していれば、discourse ユーザーとして discourse DB に接続され、PostgreSQL および SQL コマンドを実行できる状態になります。

次に、DB 内のすべてのテーブルを一覧表示したい場合は、以下のようにします:

\dt

「setting」という単語を含むすべてのテーブルを一覧表示したい場合は、以下のようにします:

\dt *setting* 

興味のあるテーブル(例えば users テーブル)が見つかったら、以下のようにテーブル構造を検証できます:

\d users

(例えば、効率的な方法ではありませんが)最初の 10 人のユーザー(id の降順で、10 件のみ)を検証したい場合は、以下のようにします:

SELECT * FROM users ORDER BY id desc LIMIT 10;

とにかく、お分かりいただけたと思います。SQL に慣れている方なら、これは朝飯前です。

ここでは誰もが、本番環境ではなくステージング環境で試すことをお勧めします(何かを壊しても、再構築して最初からやり直せるため)ので、楽しんでください!

本番システムで実際のユーザーを扱う前に、技術に十分慣れるまで(少なくとも基礎をマスターするまで)は遊ばないでください。また、必ず事前に完全なバックアップを取ってください :slight_smile:

@Divert さん、楽しんでください


注: DB でのこのような「遊び」や「自己学習」は、meta の support トピックの対象外です。つまり、基本的には自己責任となります。お楽しみください!

「いいね!」 18

@neounix この回答を本当にありがとうございます。ご尽力いただき、心から感謝しています。 :smile:

「いいね!」 6

Docker での自己ホストインストール版 Discourse データベースに、PSequel(Mac 用)のような SQL クライアントで接続する方法はありますか?

Docker を使用する以外に、私はそれに慣れていない(そして DB を破損したくない)のですが、Discourse でアクセスできるデータベースの名前を表示するために、Data Explorer プラグインを通じて実行できる SQL コマンドはありますか?