Postgresql 中數據庫的備份

Postgresql中數據庫的備份有多種形式:

1、利用圖形化界面進行備份

2、利用命令進行備份

利用圖形化界面備份簡單易操作,但不穩定。可以利用命令進行備份.

Examples

To dump a database called mydb into a SQL-script file:

$ pg_dump mydb > db.sql

 

To reload such a script into a (freshly created) database named newdb:

$ psql -d newdb -f db.sql

 

To dump a database into a custom-format archive file:

$ pg_dump -Fc mydb > db.dump

 

To reload an archive file into a (freshly created) database named newdb:

$ pg_restore -d newdb db.dump

 

To dump a single table named mytab:

$ pg_dump -t mytab mydb > db.sql

 

To dump all tables whose names start with emp in the detroit schema, except for the table named employee_log:

$ pg_dump -t 'detroit.emp*' -T detroit.employee_log mydb > db.sql

 

To dump all schemas whose names start with east or west and end in gsm, excluding any schemas whose names contain the word test:

$ pg_dump -n 'east*gsm' -n 'west*gsm' -N '*test*' mydb > db.sql

 

The same, using regular expression notation to consolidate the switches:

$ pg_dump -n '(east|west)*gsm' -N '*test*' mydb > db.sql

 

To dump all database objects except for tables whose names begin with ts_:

$ pg_dump -T 'ts_*' mydb > db.sql

 

To specify an upper-case or mixed-case name in -t and related switches, you need to double-quote the name; else it will be folded to lower case (see Patterns). But double quotes are special to the shell, so in turn they must be quoted. Thus, to dump a single table with a mixed-case name, you need something like

$ pg_dump -t '"MixedCaseName"' mydb > mytab.sql

以上命令在執行的過程中需要加上常用連接數據庫的命令

例如:利用自定義格式進行備份

pg_dump  -h localhost -U wyh -d  -Fc databasename  >d:/databasename.dump

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章