How to access the discourse database?

Here ya go, just for you @Divert :

Assuming you are in OOTB single container mode in the standard supported setup:

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

Now, if all was running properly, you are in the DB as the discourse user connected to the discourse DB ready to issue PostgreSQL and SQL commands.

Then, if you want to list all the tables in the DB, you can:

\dt

If you want to list all tables with the word “setting”, then you can:

\dt *setting* 

If you find a table of interest, say the users table, you can examine the table structure, like so:

\d users

If you wish (for example, and not an efficient example at that) to examine the first 10 users (ordered by id descending, only 10); you can just:

SELECT * FROM users ORDER BY id desc LIMIT 10;

Anyway, you get the idea. If you are good at SQL, it’s a piece-of-cake.

Everyone here will recommend you play around on a staging setup (where if you break things you can just rebuild and start over) and have fun!

Don’t play around on a production system with real users, until you are very comfortable with the tech (maybe have mastered the basics at least) and always make full backups first :slight_smile:

Have fun @Divert


Note: This kind of “playing around” or “self learning” in the DB is not the topic of support at meta, so. you are basically on your own. Enjoy!

17 Likes