天天看點

記一次 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 資料庫備份、還原操作完畢!