在linux中Postgresql數據庫如何恢復數據庫?執行sql腳本文件呢?具體步驟如下:
一、恢復數據庫備份文件
1、將數據庫備份文件xxx.backup用連接工具拷貝到/opt下,這個不固定,位置隨意放;
2、在linux中打開終端,切換到postgres用戶,命令是
su - postgres (創建postgresql數據庫時創建的用戶),
然后cd到你安裝的postgresql的bin目錄下,我的安裝在/opt下, 命令是
cd /opt/postgres/9.3/bin
打開之后輸入命令
./psql
輸入你的數據庫密碼,進入postgres數據庫;
3、先創建好你的數據庫,命令
create database xxx;
4、然后為xxx數據庫恢復數據庫備份文件,命令是
./pg_restore -U postgres -W -d xxx(你的數據庫) -v "/opt/xxx.backup"(你的備份文件位置)
備份:pg_dump -h localhost -p 5432 -U tradesns -W -F c -b -v -f "/home/tradeworkwangbin/us2010.backup" us2010 恢復:pg_restore -h 127.0.0.1 -p 5432 -U postgres -W -d zjyj_gxversion -v "/opt/zjyj_gxversion_0410.backup"
5,linux上執行x數據庫恢復數據庫備份命令報沒有權限問題用戶“postgres”的密碼認證失敗。(password authentication failed for user "postgres")的修改:
解決方法:
修改一下pg_hba.conf 配置文件
把配置文件的indent都修改為trust
二、在postgres中執行sql腳本文件
1、在linux中打開終端,切換到postgres用戶,然后cd到你安裝的postgresql的bin目錄下(同上),
cd /opt/postgres/9.3/bin
2、將你的xxx.sql文件拷貝至/opt/下,然后執行的命令如下
./psql -s xxx(xxx是你要執行的數據庫) -f /opt/xxx.sql
三、科普下
1、數據庫備份,命令如下:
./pg_dump -h localhost -p 5432 -U postgres -W -F c -b -v -f "/opt/xxx.backup" xxx
2.在數據庫安裝目錄bin下,./psql 進入數據庫,輸入密碼,\c xxx(數據庫名稱) 進入指定數據庫
\i 文件路徑