Is it possible to login into the postgres database inside the docker image?

Hello,

I need to integrate a product on my discourse by adding some tables to the discourse db in postgres. Where can I find the username and password for the PostGres DB Discourse is using.

I also wanted to ask if I change the postgres password like its suggested here:

 ./launcher enter app
su - postgres
psql
ALTER ROLE postgres WITH PASSWORD 'your-new-password';

will that break discourse or will discourse work with that new password…

1 Like

Any reason not to make yourself a new service account w different name & password?

1 Like

Because in order to do that I need to log into Postgres and I don’t know the account information Discourse uses for that.

If you’re following the standard Docker install and did not change the postgres template, try

./launcher enter app
su postgres -c "psql discourse"
12 Likes

THANKS!

This is exactly what I was looking for…

2 Likes

Amplifying on this, some basic postgres commands once you have the postgres command line in the container:

list all databases
\l

select a database
\c dbname

list tables in the current database
\dt

list columns in the users table
\d+ users

number of rows in the users table
select count(*) from users;

display value of configuration variables
show shared_buffers;

exit from the postgres console
\q

If you know SQL I am sure you can take it from here :wink: note that all SQL must terminate with semicolon ;

Also, some queries to identify largest tables.

14 Likes

Do we have updated instructions here? When I try that now I get

root@endoffice-b:/var/discourse# su postgres -c "psql discourse"
No passwd entry for user 'postgres'

ah wait, rebooting helped and this worked:

root@endoffice-b:/var/discourse# ./launcher enter app
x86_64 arch detected.
WARNING: containers/app.yml file is world-readable. You can secure this file by running: chmod o-rwx containers/app.yml
root@endoffice-b-app:/var/www/discourse# su postgres -c 'psql discourse'
psql (13.7 (Debian 13.7-1.pgdg110+1))
Type "help" for help.

Basically I needed to start the Docker container:

./launcher start app

3 Likes