# psql 連接數據庫
psql -U auth_db -h 127.0.0.1 -p 5432
## 備份數據庫
### 用 postgres賬號 備份 zzb_db數據庫到 zzb_db.sql文件中
pg_dump -h 127.0.0.1 -p 5432 -U postgres -f zzb_db.sql zzb_db
pg_dump -h 127.0.0.1 -p 5432 -U postgres -f auth_db.sql auth_db
pg_dump -h 47.106.147.83 -p 5432 -U postgres -f auth_db.sql auth_db
### 備份表
### 用 zzb_db 賬號 備份 zzb_db數據庫中 表tp_tmp 到 tp_tmp.sql文件中
pg_dump -h 127.0.0.1 -p 5432 -U zzb_db -t tp_tmp -f tp_tmp.sql zzb_db
### 還原表
psql -h 127.0.0.1 -p 5432 -U zzb_db -f tp_tmp.sql zzb_db
## 刪除數據庫、創建用戶、授權
drop database zzb_db;
create user zzb_db superuser password '123456';
create database zzb_db owner zzb_db;
grant all on database zzb_db to zzb_db;
## 還原數據庫
psql -h 127.0.0.1 -U postgres -d zzb_db < ~/Desktop/db_20200313.bak
postgres 數據庫備份還原
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.