Skip to content

PostgreSQL commands

Daisho Komiyama edited this page Dec 26, 2022 · 28 revisions

Starting with a docker

docker pull postgres:15

Run PostgreSQL container

docker run -e POSTGRES_PASSWORD=<your_password> --name=<your_container_name> --rm -d -p 5432:5432 postgres:15

-e = environment variable (i.e., POSTGRES_PASSWORD)
-d = detaches (runs in the background)
-p = exposes to port

Connect to PostgreSQL sessiondo

docker exec -u postgres -it <your_container_name> psql

-u = user
psql = a name of the command that we're running inside of the container, which is the Postgres client, psql is the client to run queries against the database

List databases

\l

Exit from the session

\q
Clone this wiki locally