mirror of
https://github.com/chubin/cheat.sheets
synced 2024-11-19 03:25:44 +00:00
22 lines
771 B
Plaintext
22 lines
771 B
Plaintext
# PostgreSQL database administration
|
|
|
|
# check connection to a database on host `localhost` and port `5432`
|
|
pg_isready -h localhost -p 5432
|
|
|
|
# backup database named `anitya`, add CREATE statement
|
|
sudo -u postgres pg_dump -C anitya > anitya.dump
|
|
|
|
# restore database
|
|
sudo -u postgres pqsql -f anitya.dump
|
|
|
|
# create a database
|
|
sudo -u postgres psql -h localhost -p 5432 -U postgres -c "CREATE DATABASE kaizen;"
|
|
|
|
# delete a database
|
|
sudo -u postgres psql -h localhost -p 5432 -U postgres -c "DROP DATABASE kaizen;"
|
|
|
|
# Run a postgres docker container with persistent volume
|
|
docker pull postgres
|
|
mkdir -p ~/docker/volumes/postgres
|
|
docker run --rm --name pg-docker -e POSTGRES_PASSWORD=postgres -d -p 5432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data postgres
|