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

**URL:** https://meta.discourse.org/t/is-it-possible-to-login-into-the-postgres-database-inside-the-docker-image/35167
**Category:** Self-hosting
**Created:** [November 2, 2015, 12:48am UTC](https://meta.discourse.org/t/is-it-possible-to-login-into-the-postgres-database-inside-the-docker-image/35167 "2015-11-02T00:48:52Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![badr](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/badr/32/105209_2.png) [@badr](https://meta.discourse.org/u/badr)
#### Post date: [November 2, 2015, 12:48am UTC](https://meta.discourse.org/t/is-it-possible-to-login-into-the-postgres-database-inside-the-docker-image/35167/1 "2015-11-02T00:48:52Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![watchmanmonitor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/watchmanmonitor/32/430970_2.png) [@watchmanmonitor](https://meta.discourse.org/u/watchmanmonitor)
#### Post date: [November 2, 2015, 1:43am UTC](https://meta.discourse.org/t/is-it-possible-to-login-into-the-postgres-database-inside-the-docker-image/35167/2 "2015-11-02T01:43:28Z")

</div>

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

---

<div class="post-metadata">

### Author: ![badr](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/badr/32/105209_2.png) [@badr](https://meta.discourse.org/u/badr)
#### Post date: [November 2, 2015, 7:28am UTC](https://meta.discourse.org/t/is-it-possible-to-login-into-the-postgres-database-inside-the-docker-image/35167/3 "2015-11-02T07:28:15Z")

</div>

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

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [November 2, 2015, 8:04am UTC](https://meta.discourse.org/t/is-it-possible-to-login-into-the-postgres-database-inside-the-docker-image/35167/4 "2015-11-02T08:04:17Z")

</div>

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

```plaintext
./launcher enter app
su postgres -c "psql discourse"

```

> [@badr](#):
>
> Where can I find the username and password for the PostGres DB Discourse is using.

> <https://github.com/discourse/discourse_docker/blob/8bd5ef16bc86262675ffb54c3d79c2985b5e2d7d/templates/postgres.template.yml#L201-L208>

---

<div class="post-metadata">

### Author: ![badr](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/badr/32/105209_2.png) [@badr](https://meta.discourse.org/u/badr)
#### Post date: [November 14, 2015, 7:16pm UTC](https://meta.discourse.org/t/is-it-possible-to-login-into-the-postgres-database-inside-the-docker-image/35167/5 "2015-11-14T19:16:53Z")

</div>

THANKS!

This is exactly what I was looking for…

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [July 13, 2016, 8:14am UTC](https://meta.discourse.org/t/is-it-possible-to-login-into-the-postgres-database-inside-the-docker-image/35167/6 "2016-07-13T08:14:39Z")

</div>

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 😉 note that all SQL **must** terminate with semicolon `;`

Also, [some queries to identify largest tables](https://wiki.postgresql.org/wiki/Disk_Usage).

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [January 26, 2023, 4:29am UTC](https://meta.discourse.org/t/is-it-possible-to-login-into-the-postgres-database-inside-the-docker-image/35167/10 "2023-01-26T04:29:27Z")

</div>

> [@tgxworld](#):
>
> ```plaintext
> ./launcher enter app
> su postgres -c "psql discourse"
> 
> ```

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

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

```

ah wait, rebooting helped and this worked:

```plaintext
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`
