天天看點

linux postgresql 恢複資料庫,PostgreSQL資料庫備份和恢複

一、備份

1、cmd到PostgreSQL安裝目錄bin下

2、備份指令

pg_dump -h 192.168.100.23 -U postgres postgres > D:\postgres.bak

3、指令解釋

如上指令,

pg_dump 是備份資料庫指令;

10.194.227.231是資料庫的ip位址;

postgres 是資料庫的使用者名;

postgres 是資料庫名;

> 意思是導出到指定目錄;

4、圖文并茂

備份

linux postgresql 恢複資料庫,PostgreSQL資料庫備份和恢複
linux postgresql 恢複資料庫,PostgreSQL資料庫備份和恢複

二、恢複

1、備份指令

psql -h localhost -U postgres -d test < D:\postgres.bak

2、指令解釋

如上指令,

psql 是恢複資料庫指令;

localhost是要恢複的資料庫的ip位址;

postgres 是資料庫的使用者名;

test 是資料庫名;

> 意思是導出到指定目錄;

3、圖文并茂

(1)資料導入并解決亂碼問題

linux postgresql 恢複資料庫,PostgreSQL資料庫備份和恢複

打開cmd視窗,直接輸入chcp 65001即可;

linux postgresql 恢複資料庫,PostgreSQL資料庫備份和恢複

(2)導入資料

linux postgresql 恢複資料庫,PostgreSQL資料庫備份和恢複

三、Linux中PostgreSQL資料庫備份和恢複

在linux裡依然有效。有一個值得注意的是:如果直接進入PostgreSQL的安裝目錄bin下,執行指令,可能會出現 找不到pg_dump,psql的現象,我們在可以這樣:

1、備份

/opt/PostgreSQL/9.5/bin/pg_dump -h 164.82.233.54 -U postgres databasename > databasename.bak

2、恢複

/opt/PostgreSQL/9.5/bin/psql -h localhost -U postgres -d databasename < databasename.bak