Setting up PostgreSQL

Run PostgreSQL#

docker run --name d2s-postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres -d -v $(pwd)/workspace/input:/data postgres:10.4

Shared on your machine at workspace/input

Password is postgres

Connect to Postgres and load scripts#

Connect to postgres#

docker exec -it d2s-postgres psql -U postgres

Load SQL script#

docker exec -it d2s-postgres psql -U postgres db < /data/load_database.sql

Or execute it directly in the container if the previous command fails:

docker exec -it d2s-postgres bash
psql -U postgres db < /data/load_database.sql

Explore database#

Using tools can be helpful to explore the content of your database.


Dbeaver is a Eclipse based tool to explore database, it allows to generate diagrams to get an overview of the tables and relations.

Not available as web UI nor Docker image. Can be installed locally:

sudo snap install dbeaver-ce

Unfortunately the diagrams can be a challenge to export. They manage to face Java Heap Space error when generating a png from a ER diagram on 16G machine. How they manage to fail such a simple task is impressing.


The official UI for Postgres databases. Does not include user-friendly features such as ER diagram generation. But available as web UI in a docker image:

d2s start pgadmin

Login with / password

Or directly using docker:

docker run -p 80:80 --net d2s-core_network \
-e '' \
-d dpage/pgadmin4

PSQL commands#

Manage databases#

-- List databases
-- Connect database
\c db
-- Create database

Manage schemas#

-- List schemas
-- Choose a schema
SET search_path TO schema_name;

Manage tables#

List tables#


Select from table#

SELECT * FROM table_name LIMIT 10;
Last updated on by Vincent Emonet