DEV Community

Jakub T
Jakub T

Posted on

Throwaway postgres

I don't like to install too many services on my machine as after a while I end up with lots of services - Postgres, Redis, Mongo, Memcache, Elasticsearch that have lots of data from different POC projects.

So whenever I need to test something quickly I just prefer to run it in a docker container:

docker run --name postgres -d -p 5432:5432 -e POSTGRES_PASSWORD=kuba -e POSTGRES_DB=db -e POSTGRES_USER=kuba postgres:12

Or with docker compose:

version: '3'
        image: postgres:12
            - POSTGRES_USER=kuba
            - POSTGRES_PASSWORD=kuba
            - POSTGRES_DB=db
            - "5432:5432"

And we can quickly run the Postgres DB:

$ docker-compose up
Starting sql_postgres_1 ... done
Attaching to sql_postgres_1
postgres_1  |
postgres_1  | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres_1  |
postgres_1  | 2020-05-09 08:13:45.246 UTC [1] LOG:  starting PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres_1  | 2020-05-09 08:13:45.247 UTC [1] LOG:  listening on IPv4 address "", port 5432
postgres_1  | 2020-05-09 08:13:45.247 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres_1  | 2020-05-09 08:13:45.249 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1  | 2020-05-09 08:13:45.262 UTC [25] LOG:  database system was shut down at 2020-05-09 08:12:41 UTC
postgres_1  | 2020-05-09 08:13:45.266 UTC [1] LOG:  database system is ready to accept connections

And we have a throwaway db running:

$ psql postgres://kuba:kuba@localhost:5432/db
Null display is "NULL".
Pager is always used.
Timing is on.
psql (12.2)
Type "help" for help.

kuba@localhost:5432 db#

Discussion (0)