記一次 Centos7 Postgresql v11 數據庫備份、還原

一、數據庫安裝

根據自身環境需要選擇安裝

1、yum 指定目錄安裝

https://blog.csdn.net/llwy1428/article/details/105143053

2、yum 直接安裝

https://blog.csdn.net/llwy1428/article/details/102486414

3、編譯安裝

https://blog.csdn.net/llwy1428/article/details/95444151

4、PostgreSql 基本操作

https://blog.csdn.net/llwy1428/article/details/102598732

5、Centos7 yum 安裝、配置 PgAdmin4

https://blog.csdn.net/llwy1428/article/details/102486511

6、Centos7 PostgreSql 數據庫安裝擴展

https://blog.csdn.net/llwy1428/article/details/105167524

7、Centos7 PostgreSql 數據庫使用FDW擴展

https://blog.csdn.net/llwy1428/article/details/106291669

8、Centos7 postgresql v11 安裝時序數據庫 TimescaleDB

https://blog.csdn.net/llwy1428/article/details/106357900

二、數據庫備份

1、備份本機數據庫

把數據庫 dbfrom 備份到 /tmp 路徑下 命名爲 sysdb.backup 文件

/usr/pgsql-11/bin/pg_dump --file "/tmp/sysdb.backup" --host "localhost" --port "5432" --username "postgres" --dbname "dbfrom" --verbose --role "postgres" --format=c --blobs --encoding "UTF8"

2、備份遠程數據庫

vim ~/.pgpass
寫入內容:
目標數據庫IP:5432:目標數據庫:postgres:目標數據庫密碼

執行備份命令

/usr/pgsql-11/bin/pg_dump --file "/tmp/sysdb.backup" --host "目標數據庫IP" --port "5432" --username "postgres" --dbname "目標數據庫" --verbose --role "postgres" --format=c --blobs --encoding "UTF8"

三、數據庫還原

chmod 755 /tmp/sysdb.backup

切換用戶

su - postgres
psql

創建數據庫

CREATE DATABASE dbto;

 切換至 postgres 用戶下,執行還原命令

su - postgres
pg_restore --username "postgres" --no-password --role "postgres" --dbname "dbto" --verbose /tmp/sysdb.backup

 

 

 

 

 

Postgresql v11 數據庫備份、還原操作完畢!

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章