-
Notifications
You must be signed in to change notification settings - Fork 0
Postgres
If you make changes to the database startup scripts, note that you will need to remove the db-data
volume (and all the data previously stored in the db) for the new scripts to be run. You can do this with docker-compose down -v
, which will remove all the containers and volumes. You then run yarn start --build
(i.e. docker-compose up --build
) so Docker rebuilds the image, copying the updated versions of the scripts into it (otherwise it will still use the old version of the image with the old version of the scripts).
Inspect the db using psql
within the container.
This runs psql
in the postgres
container, connecting to the appdb
database using the user postgres
.
Note that you need the container running.
docker-compose exec postgres psql appdb -U postgres
Inspect postgres container via bash
docker-compose exec postgres bash
Connecting via port and psql externally.
psql postgres://postgres@localhost:5433/appdb
Useful commands:
\d - show tables
\d __tablename__ - table definition
Example:
appdb=# \d
List of relations
Schema | Name | Type | Owner
--------+----------------+----------+----------
public | entries | table | postgres
public | entries_id_seq | sequence | postgres
public | list | table | postgres
public | list_id_seq | sequence | postgres
public | media | table | postgres
public | media_id_seq | sequence | postgres
public | users | table | postgres
public | users_id_seq | sequence | postgres
(8 rows)
appdb=# SELECT * FROM entries;
id | media_id | user_id | status | rating | last_update | started | finished
----+----------+---------+----------+--------+-------------+------------+------------
1 | 1 | 1 | progress | | | 2016 | 2018
2 | 2 | 1 | complete | | | 2017-10-01 | 2017-10-01
3 | 1 | 2 | progress | | | 2017-10-01 | 2017-10-01
4 | 2 | 3 | complete | | | 2017-10 | 2017-10-01
(4 rows)
Remember to end queries with a semicolon.