Backup to Script:
首先切換到postgres用戶:
liqingfeng@liqingfeng:~$ su postgres
口令: 輸入密碼
postgres@liqingfeng:/home/liqingfeng$
然后輸入backup命令:
pg_dump -U[username] -d -f[way of script file] [database name]
例如:pg_dump -Upostgres -d -f/home/liqingfeng/test.sql testdb
這樣數據庫testdb將以sql腳本形式backup到/home/liqingfeng/test.sql中。
Restore from Script:
還是首先要切換到postgres用戶下,輸入命令:
psql -U[username] -d[database name] -f[way to an existing script file]
例如:
psql -Upostgres -dtestdb -f/home/liqingfeng/test.sql
首先切換到postgres用戶:
liqingfeng@liqingfeng:~$ su postgres
口令: 輸入密碼
postgres@liqingfeng:/home/liqingfeng$
然后輸入backup命令:
pg_dump -U[username] -d -f[way of script file] [database name]
例如:pg_dump -Upostgres -d -f/home/liqingfeng/test.sql testdb
這樣數據庫testdb將以sql腳本形式backup到/home/liqingfeng/test.sql中。
Restore from Script:
還是首先要切換到postgres用戶下,輸入命令:
psql -U[username] -d[database name] -f[way to an existing script file]
例如:
psql -Upostgres -dtestdb -f/home/liqingfeng/test.sql