hello, world. | notes.carranza.engineer

2021 PostgreSQL Training Notes

tags: database,postgresql,notes

Notes

Prep

The items in this section are only available to GitLab team members.

Let’s Get Set Up!

How about a container with Postgres all ready to go?

docker run --name postgres_training \
-e POSTGRES_PASSWORD=mysecretpassword \
-d postgres:13

Use the credentials in pass:

docker run --name postgres_training -e POSTGRES_PASSWORD=$(pass postgres/container/user) -td postgres:13

Cool!

# docker exec -it postgres_training psql -U postgres
psql (11.13 (Debian 11.13-1.pgdg90+1))
Type "help" for help.

postgres=# \c
You are now connected to database "postgres" as user "postgres".

Introducing lsb-core alone will require interactive set up to specify timezone info. Our friend DEBIAN_FRONTEND comes in handy, try this instead:

docker run --name ubuntutty  -e DEBIAN_FRONTEND=noninteractive    -td ubuntu:20.04
docker exec -it ubuntutty /bin/bash
apt-get -y update
apt-get -y install gnupg less lsb-core lsb-release sudo vim wget

I recommend doing the above before class starts to avoid being annoyed.

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

Clean Up

Clean up after yourself!

docker stop postgres_training
docker container ls -a
docker container rm $(docker container ls -a | grep postgres_training | cut -d" " -f1)
docker image ls
docker image rm <image_id>

Get the container ID you want to clean up docker container ls -a | grep postgres_training | cut -d" " -f1

Tools

External tools that might be helpful when poking at Postgres.

Links