Postgres debug cheatsheet - rivernews/iriversland2-kubernetes GitHub Wiki
-
Launch psql
psql -U admin default_database
-
List all database
\ls
or\l
-
Switch to connecting another database
\c <db_name>
-
List all tables
\dt
-
Create / delete database
DROP DATABASE <db_name>;
don't forget the comma at the end,CREAT DATABASE <db_name>;
. -
Quit:
\q
docker run -d \
--name my-postgres \
-e POSTGRES_DB=prod_09152020 \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-v $(pwd)/postgres_data:/var/lib/postgresql/data \
-p 5432:5432 \
postgres:9.5
Run all at once: ./manage.py migrate && echo "delete from auth_permission; delete from django_content_type;" | python manage.py dbshell && ./manage.py loaddata <json_path>
- Backup the data in existing DB, if you haven't done so:
manage.py dumpdata > out.json
- Change DB config, switch to new one
- Run Django
./manage.py migrate
- Trim django management data table
echo "delete from auth_permission; delete from django_content_type;" | python manage.py dbshell
- Now load the json backup file
manage.py loaddata out.json
- Enjoy!