在 Windows 環境用排程進行 PostgreSQL database 的備份與維護
1) 建立一個目錄 %APPDATA%\postgresql在我的環境中為 C:\Documents and Settings\bestlong\Application Data\postgresql
2) 建立一個檔案 %APPDATA%\postgresql\pgpass.conf
可使用文字編輯程式如 Notepad
3) 輸入必要的設定在 %APPDATA%\postgresql\pgpass.conf
內容如下行
localhost:*:myDBname:myUserName:myPassword
4) 建立批次檔來執行備份或維護作業, 指令如下:
"C:\Program Files\PostgreSQL\8.0\bin\psql" -h localhost -d myDBname -U myUserName -f Name-Of-File-With-Maintenance-Commands
"C:\Program Files\PostgreSQL\8.0\bin\pg_dump" -f Name-Of-My-Dump-File -Fc -Z 9 -h localhost -U myUserName myDBname
5) Use the task scheduler to run your newly created batch file whenever you'd like it to run
I actually run my batch file every night. My DB has no activity during the night, so I run my maintenance then.
Name-Of-File-With-Maintenance-Commands contains SQL to refresh a materialized view and do a vacuum full analyze 可參考官方文件
Client Interfaces
- libpq - C Library
-- The Password File
頁:
[1]