Accessing Database while discourse not running

AI-generated summary

The discussion Accessing Database while discourse not running provides a solution for accessing the Discourse database when the container is not running. Alexander_Wright warns that these instructions may break the installation if not used carefully. The technique involves using a Docker image of Postgres to access the Discourse volume, and requires the user to have knowledge of Postgres command line operations and Discourse installation in /var/discourse. The steps include pulling the Postgres image, starting a container, entering the container, and running the db client using psql. It is crucial to change ‘mysecretpassword’ to a more secure value and to not run this process while Discourse is running. Once finished, the container should be stopped and removed, and Docker may need to be restarted before restarting Discourse.

Danger!!

This may well break your installation, but it may get you out of a hole.
Use these instructions with great care.

If you can’t get the discourse container to run with ./launcher rebuild app for any reason and need to access the database to resolve the problem, do try these instructions.

The technique uses a Docker image of Postgres to access the volume of your installed Discourse. Do not run this while Discourse is running!

This assumes that discourse is installed in /var/discourse, and that you know how to operate Postgres via the command line.

Change ‘mysecretpassword’ to a more secure value.

# Pull the correct image for your version of Discourse.
docker pull postgres:15
        
# Start the container and direct it to the local database files.
docker run --name postgres_container -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 -v /var/discourse/shared/standalone/postgres_data:/var/lib/postgresql/data postgres:15
        
 # Enter the container
 docker exec -it postgres_container /bin/bash
        
 # Once in the container:
 su postgres
        
 # run the db client
 psql
        
 # Trash the database as you see fit.

# When finished:
docker stop postgres_container
docker rm postgres_container
docker rmi postgres:15

You may need to restart docker before attempting to restart discourse.

service restart docker.
3 Likes