Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| postgresql [2023/11/15 14:23] – [Restore on DEV] admin | postgresql [2026/03/08 18:07] (current) – admin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== PostgreSQL ====== | ====== PostgreSQL ====== | ||
| - | ===== Password fix ===== | ||
| - | <code sql> | ||
| - | SELECT | ||
| - | rolname, rolpassword ~ ' | ||
| - | FROM pg_authid | ||
| - | WHERE rolcanlogin; | ||
| - | </ | ||
| - | < | ||
| - | \password postgres | ||
| - | </ | ||
| - | |||
| ===== DEV refresh ===== | ===== DEV refresh ===== | ||
| ==== Backup fuelwatcher on PROD ==== | ==== Backup fuelwatcher on PROD ==== | ||
| <code bash> | <code bash> | ||
| - | docker exec -it FW_PostgreSQL | + | docker exec -it FT_PostgreSQL |
| cd / | cd / | ||
| - | pg_dump -d fuelwatcher > fuelwatcher_all_`date +%Y-%m-%dT%H-%M-%S`.backup | + | pg_dump -d fuelwatcher > fuelwatcher_RPi64_`date +%Y-%m-%dT%H-%M-%S`.backup |
| </ | </ | ||
| Login to root: | Login to root: | ||
| <code bash> | <code bash> | ||
| sudo su - | sudo su - | ||
| - | rsync -av / | + | rsync -av / |
| </ | </ | ||
| ==== Restore on DEV ==== | ==== Restore on DEV ==== | ||
| - | Copy //daily// backup from PROD to DEV using Beyond Compare config **Developed/backups (KARGATH | + | Copy //daily// backup from PROD to DEV using Beyond Compare config **Docker/backups (WSL < |
| Login: | Login: | ||
| <code bash> | <code bash> | ||
| - | docker exec -it dev-container_devcontainer_db_1 | + | docker exec -it FT_PostgreSQL |
| su - postgres | su - postgres | ||
| Line 39: | Line 28: | ||
| DROP DATABASE fuelwatcher; | DROP DATABASE fuelwatcher; | ||
| - | CREATE DATABASE | + | CREATE DATABASE |
| WITH | WITH | ||
| OWNER = postgres | OWNER = postgres | ||
| Line 51: | Line 40: | ||
| < | < | ||
| cd / | cd / | ||
| - | pg_dump -d fuelwatcher | + | pg_dump -d fueltracker |
| - | psql -d fuelwatcher < fuelwatcher_all_2021-08-01T05-23-25.backup | + | psql -d fuelwatcher < fueltracker_RPi64_2021-08-01T05-23-25.backup |
| </ | </ | ||
| Line 58: | Line 47: | ||
| <code bash> | <code bash> | ||
| pg_dumpall > dev-container_devcontainer_db_1_all_`date +%Y-%m-%dT%H-%M-%S`.backup | pg_dumpall > dev-container_devcontainer_db_1_all_`date +%Y-%m-%dT%H-%M-%S`.backup | ||
| - | cd /workspace/fuelwatcher/ | + | cd /workspace/FuelTracker/ |
| - | cd /workspace/fuelwatcher/ | + | cd /workspace/FuelTracker/ |
| </ | </ | ||
| ===== Data Dictionary export ===== | ===== Data Dictionary export ===== | ||
| For comparison between PROD and DEV. Perform on both: | For comparison between PROD and DEV. Perform on both: | ||
| <code bash> | <code bash> | ||
| - | pg_dump -Cs fuelwatcher | + | pg_dump -Cs fueltracker |
| + | </ | ||
| + | ===== Version upgrade ===== | ||
| + | Test (gunzipped) restore of daily PROD backup to test PostgreSQL server (new version). | ||
| + | < | ||
| + | docker exec -it TEST_PostgreSQL /bin/bash | ||
| + | |||
| + | cd / | ||
| + | psql -U postgres -f FW_PostgreSQL_all_2023-11-28T00-00-01.bak | ||
| + | </ | ||
| + | |||
| + | Stop both PostgreSQL servers. | ||
| + | |||
| + | Move PROD directory aside and clone test data files into place (perms are important). | ||
| + | < | ||
| + | mv _data data_bak | ||
| + | rsync -av ../ | ||
| + | </ | ||
| + | |||
| + | Move backups back to proper location | ||
| + | < | ||
| + | mv data_bak/ | ||
| + | </ | ||
| + | |||
| + | ===== Password fix ===== | ||
| + | <code sql> | ||
| + | SELECT | ||
| + | rolname, rolpassword ~ ' | ||
| + | FROM pg_authid | ||
| + | WHERE rolcanlogin; | ||
| + | </ | ||
| + | < | ||
| + | \password postgres | ||
| </ | </ | ||
| ===== References ===== | ===== References ===== | ||
| - | How to Upgrade Your PostgreSQL Passwords to SCRAM - https://blog.crunchydata.com/blog/how-to-upgrade-postgresql-passwords-to-scram | + | [[https://www.postgresqltutorial.com/postgresql-administration/ |
| - | Postgres dump database schema with or without data - https:// | + | [[https:// |
| + | |||
| + | [[https:// | ||
| [[https:// | [[https:// | ||
| + | |||
| + | [[https:// | ||