日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

PostgreSQL 数据库备份

發(fā)布時間:2025/3/20 数据库 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PostgreSQL 数据库备份 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

PostgreSQL 數(shù)據(jù)庫備份 pg_dump

一、備份還原

  注意:命令在pg_dump目錄下進行

1、備份test數(shù)據(jù)庫

pg_dump -h 127.0.0.1 -p 5432 -U username -c -f db_back.sql test

2、還原數(shù)據(jù)到test2數(shù)據(jù)庫

psql -U postgres -f /db_back.sql test2

?

二、命令詳解

  • 基本命令
pg_dump [OPTION]... [DBNAME]

  注:數(shù)據(jù)庫名放最后,不指定默認是系統(tǒng)變量PGDATABASE指定的數(shù)據(jù)庫。

?

  • ?詳解  

General options:(一般選項)
? -f, --file=FILENAME ? ? ? ? ?output file or directory name導出后保存的文件名
? -F, --format=c|d|t|p? ? ? ? ? ? output file format (custom, directory, tar,導出文件的格式??plain text (default))
? -j, --jobs=NUM? ? ? ? ? ? ? ? ? use this many parallel jobs to dump并行數(shù)
? -v, --verbose ? ? ? ? ? ? ? ? ? verbose mode 詳細模式
? -V, --version ? ? ? ? ? ? ? ? ? output version information, then exit輸出版本信息, 然后退出
? -Z, --compress=0-9? ? ? ? ? compression level for compressed formats被壓縮格式的壓縮級別
? --lock-wait-timeout=TIMEOUT ?fail after waiting TIMEOUT for a table lock在等待表鎖超時后操作失敗
? -?, --help ? ? ? ? ? ? ? ? ? show this help, then exit顯示此幫助信息, 然后退出

Options controlling the output content:(控制輸出的選項)
? -a, --data-only ? ? ? ? ? ? ?dump only the data, not the schema只導出數(shù)據(jù),不包括模式
? -b, --blobs ? ? ? ? ? ? ? ? ?include large objects in dump在轉(zhuǎn)儲中包括大對象
? -c, --clean ? ? ? ? ? ? ? ? ?clean (drop) database objects before recreating在重新創(chuàng)建之前,先清除(刪除)數(shù)據(jù)庫對象
? -C, --create ? ? ? ? ? ? ? ? include commands to create database in dump在轉(zhuǎn)儲中包括命令,以便創(chuàng)建數(shù)據(jù)庫(包括建庫語句,無需在導入之前先建數(shù)據(jù)庫)
? -E, --encoding=ENCODING ? ? ?dump the data in encoding ENCODING轉(zhuǎn)儲以ENCODING形式編碼的數(shù)據(jù)
? -n, --schema=SCHEMA ? ? ? ? ?dump the named schema(s) only只轉(zhuǎn)儲指定名稱的模式
? -N, --exclude-schema=SCHEMA ?do NOT dump the named schema(s)不轉(zhuǎn)儲已命名的模式
? -o, --oids ? ? ? ? ? ? ? ? ? include OIDs in dump在轉(zhuǎn)儲中包括 OID
? -O, --no-owner ? ? ? ? ? ? ? skip restoration of object ownership in在明文格式中, 忽略恢復對象所屬者??plain-text format
? -s, --schema-only ? ? ? ? ? ?dump only the schema, no data只轉(zhuǎn)儲模式, 不包括數(shù)據(jù)(不導出數(shù)據(jù))
? -S, --superuser=NAME ? ? ? ? superuser user name to use in plain-text format在轉(zhuǎn)儲中, 指定的超級用戶名
? -t, --table=TABLE ? ? ? ? ? ?dump the named table(s) only只轉(zhuǎn)儲指定名稱的表
? -T, --exclude-table=TABLE ? ?do NOT dump the named table(s)只轉(zhuǎn)儲指定名稱的表
? -x, --no-privileges ? ? ? ? ?do not dump privileges (grant/revoke)不要轉(zhuǎn)儲權(quán)限 (grant/revoke)
? --binary-upgrade ? ? ? ? ? ? for use by upgrade utilities only只能由升級工具使用
? --column-inserts ? ? ? ? ? ? dump data as INSERT commands with column names以帶有列名的INSERT命令形式轉(zhuǎn)儲數(shù)據(jù)
? --disable-dollar-quoting ? ? disable dollar quoting, use SQL standard quoting取消美元 (符號) 引號, 使用 SQL 標準引號
? --disable-triggers ? ? ? ? ? disable triggers during data-only restore在只恢復數(shù)據(jù)的過程中禁用觸發(fā)器
? --exclude-table-data=TABLE ? do NOT dump data for the named table(s)以INSERT命令,而不是COPY命令的形式轉(zhuǎn)儲數(shù)據(jù)
? --inserts ? ? ? ? ? ? ? ? ? ?dump data as INSERT commands, rather than COPY
? --no-security-labels ? ? ? ? do not dump security label assignments
? --no-synchronized-snapshots ?do not use synchronized snapshots in parallel jobs
? --no-tablespaces ? ? ? ? ? ? do not dump tablespace assignments不轉(zhuǎn)儲表空間分配信息
? --no-unlogged-table-data ? ? do not dump unlogged table data
? --quote-all-identifiers ? ? ?quote all identifiers, even if not key words
? --section=SECTION ? ? ? ? ? ?dump named section (pre-data, data, or post-data)
? --serializable-deferrable ? ?wait until the dump can run without anomalies
? --use-set-session-authorization
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?use SET SESSION AUTHORIZATION commands instead of
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ALTER OWNER commands to set ownership

Connection options:(控制連接的選項)
? -d, --dbname=DBNAME ? ? ?database to dump 數(shù)據(jù)庫名
? -h, --host=HOSTNAME ? ? ?database server host or socket directory數(shù)據(jù)庫服務器的主機名或套接字目錄
? -p, --port=PORT ? ? ? ? ?database server port number數(shù)據(jù)庫服務器的端口號
? -U, --username=NAME ? ? ?connect as specified database user以指定的數(shù)據(jù)庫用戶聯(lián)接
? -w, --no-password ? ? ? ?never prompt for password永遠不提示輸入口令
? -W, --password ? ? ? ? ? force password prompt (should happen automatically)強制口令提示 (自動)
? --role=ROLENAME ? ? ? ? ?do SET ROLE before dump

?

一: 純文件格式的腳本:?
示例:
1. 只導出postgres數(shù)據(jù)庫的數(shù)據(jù),不包括模式 -s
? ??

pg_dump -U postgres -f /postgres.sql -s postgres(數(shù)據(jù)庫名)

2. 導出postgres數(shù)據(jù)庫(包括數(shù)據(jù))

? ?

pg_dump -U postgres -f /postgres.sql postgres(數(shù)據(jù)庫名)

?

3. 導出postgres數(shù)據(jù)庫中表test01的數(shù)據(jù)
? ??

create database "test01" with owner="postgres" encoding='utf-8';(單引號,雙引號不能錯) pg_dump -U postgres -f /postgres.sql -t test01 postgres(數(shù)據(jù)庫名)

4. 導出postgres數(shù)據(jù)庫中表test01的數(shù)據(jù),以insert語句的形式

? ?

pg_dump -U postgres -f /postgres.sql -t test01 --column-inserts postgres(數(shù)據(jù)庫名)

?


5. 恢復數(shù)據(jù)到bk01數(shù)據(jù)庫
? ?

psql -U postgres -f /postgres.sql bk01

?


二、 使用歸檔文件格式:
pg_restore
使用pg_restore純文本恢復純文本格式的腳本,無法恢復
[root@localhost postgres-9.3.5]# pg_restore -U postgres -d bk01 ?/mnt/hgfs/window\&ubuntu\ shared\ folder/vendemo.sql?
pg_restore: [archiver] input file appears to be a text format dump. Please use psql.

pg_restore和歸檔文件格式一起使用重建數(shù)據(jù)庫。

1. 先備份:?
? ?pg_dump -U postgres -F t -f /vendemo.tar vendemo ?備份下來有800多k
?. 恢復:
? ?pg_restore -U postgres -d bk01 /vendemo.tar?
2. 先備份:?
? ?pg_dump -U postgres -F c -f /vendemo.tar vendemo ?備份下來有300多k
?. 恢復:
? ?pg_restore -U postgres -d bk01 /vendemo.tar?

三、 壓縮備份與恢復:
處理大數(shù)據(jù)庫:
1. 使用壓縮的轉(zhuǎn)儲. 使用你熟悉的壓縮程序,比如說 gzip。
?. 先備份:
? ?pg_dump -U postgres vendemo | gzip > /vendemo.gz 備份下來只有30多k
?. 恢復:
? ?gunzip -c /vendemo.gz | psql -U postgres bk02
?或者
? ?cat /vendemo.gz | gunzip | psql -U postgres bk02
2. 使用 split。. split 命令允許你 你用下面的方法把輸出分解成操作系統(tǒng)可以接受的大小。 比如,讓每個塊大小為 1 兆字節(jié):?
?. 先備份:
? ?pg_dump -U postgres -d vendemo | split -b 100k - /vend/vend
? ?導出來的樣子是 ? vendaa 100k
? ?vendab 100k
? ?vendac 100k
? ?vendad 16k
?. 恢復:
? cat /vend/vend* | psql -U postgres bk02

轉(zhuǎn)載于:https://www.cnblogs.com/BillyYoung/p/11057854.html

總結(jié)

以上是生活随笔為你收集整理的PostgreSQL 数据库备份的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久久看片网 | www.夜夜爱| 91九色蝌蚪91por成人 | 四季av一区二区 | 美女av一区二区 | 国产精品呻吟 | 能看毛片的网站 | 九色porny原创自拍 | 中文不卡视频 | 农村老妇性真猛 | 亚洲天堂网站 | 中文字幕久久久 | 在线观看亚洲精品视频 | 色播日韩| www.精品一区 | 一级片大片 | 欧美14sex性hd摘花 | 欧美一区二区三区视频在线观看 | 欧美精品午夜 | 国产精品一二 | 日本一区二区三区免费看 | 国产乱人乱偷精品视频 | 成人精品免费 | 免费在线观看日韩av | 丰满人妻中伦妇伦精品app | 欧美性生活 | avwww.| 大肉大捧一进一出好爽mba | 日韩欧美亚洲视频 | 亚洲免费视频观看 | 婷婷激情网站 | 久久毛片网 | 草莓视频成人在线 | 成人免费毛片观看 | 在线观看视频色 | 亚洲色图35p| 麻豆视频在线免费观看 | 99精品在线观看 | 快播久久 | 88国产精品视频一区二区三区 | 六月丁香啪啪 | 精品国产av一区二区 | 成人午夜网址 | 欧美激情午夜 | 无码av免费精品一区二区三区 | av大帝| 亚洲AV无码阿娇国产精品 | 欧美午夜精品久久久 | 黄色三级网络 | 日韩中文字幕亚洲 | 一区二区三区高清在线观看 | 国产97在线观看 | 欧美在线免费观看视频 | 欧美激情一区二区三区在线 | 欧美一区二区三区观看 | 久久久国产精品一区 | 午夜免费激情视频 | 小说肉肉视频 | 亚洲伦理网 | 国产精华一区二区三区 | 可以在线观看的av网站 | 97影音| 黑人和白人做爰 | 久久久久久人妻一区二区三区 | 97在线精品视频 | 亚洲网站视频 | 公侵犯人妻一区二区 | 91视频免费看 | 久久久久麻豆 | 黄色18网站 | 国产在线精品视频 | 国产伦精品一区二区三区照片91 | 日韩第一页在线 | 中国黄色一级视频 | 久久香焦 | 亚洲欧美第一 | 欧美性生活一区二区三区 | 亚洲天堂偷拍 | 欧美乱码精品 | 激情午夜网 | 影音先锋中文字幕在线播放 | 久久精品国产一区二区电影 | 欧美一区二区影院 | 欧美bdsm调教视频 | 波多野结衣有码 | 超碰av人人 | 澳门久久 | 日韩va中文| 日本免费一区二区三区四区 | 国产99在线播放 | 极品蜜桃臀肥臀-x88av | 激情内射人妻1区2区3区 | 午夜久久久久久久久久久 | 色哟哟国产精品色哟哟 | 成年人网站在线免费观看 | 最新av免费在线观看 | 稀缺呦国内精品呦 | 伊人久久综合视频 | 依人综合 |