Skip to content

How to query the database? #458

Description

@chhenning

For everyone who has the same issues as me.

1. Connect to the database server via pgadmin

Once the docker-compose up -d finished. pgadmin is available on localhost:5050. After logging in make sure to use the following to connect to the PostgreSQL server:

host: db
port: 5432
username: postgres
password: changethis

Please note NOT to use localhost:5432 to connect to the database server.

2. Query user table

Make sure to put the table name in quotes!

select * from "user";

If you just do select * from user; you wont see your username and that is it.

3. Connect to the database server via psql

We need to expose the db port to the host system (aka your laptop). In the docker-compose.yml do this:

services:
  db:
    ports:
      - '5432:5432'

If you don't do this you will see the following error:

psql: error: connection to server at "localhost" (::1), port 5432 failed: Connection refused
	Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
	Is the server running on that host and accepting TCP/IP connections?

After the change, you can connect now via:

psql postgresql://postgres:changethis@localhost:5432/app

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions