網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
一篇文章教會(huì)你使用gs_restore導(dǎo)入數(shù)據(jù)_數(shù)據(jù)庫(kù)其它
作者:大話數(shù)據(jù)庫(kù) ? 更新時(shí)間: 2022-10-31 編程語(yǔ)言背景信息
gs_restore是openGauss提供的針對(duì)gs_dump導(dǎo)出數(shù)據(jù)的導(dǎo)入工具。通過(guò)此工具可將由gs_dump生成的導(dǎo)出文件進(jìn)行導(dǎo)入。
gs_restore工具由操作系統(tǒng)用戶omm執(zhí)行。
主要功能包含:
- 導(dǎo)入到數(shù)據(jù)庫(kù)
如果連接參數(shù)中指定了數(shù)據(jù)庫(kù),則數(shù)據(jù)將被導(dǎo)入到指定的數(shù)據(jù)庫(kù)中。其中,并行導(dǎo)入必須指定連接的密碼。導(dǎo)入時(shí)生成列會(huì)自動(dòng)更新,并像普通列一樣保存。
- 導(dǎo)入到腳本文件
如果未指定導(dǎo)入數(shù)據(jù)庫(kù),則創(chuàng)建包含重建數(shù)據(jù)庫(kù)所必須的SQL語(yǔ)句腳本并寫(xiě)入到文件或者標(biāo)準(zhǔn)輸出。等效于直接使用gs_dump導(dǎo)出為純文本格式。
命令格式
gs_restore [OPTION]... FILE
說(shuō)明:
- FILE沒(méi)有短選項(xiàng)或長(zhǎng)選項(xiàng)。用來(lái)指定歸檔文件所處的位置。
- 作為前提條件,需輸入dbname或-l選項(xiàng)。不允許用戶同時(shí)輸入dbname和-l選項(xiàng)。
- gs_restore默認(rèn)是以追加的方式進(jìn)行數(shù)據(jù)導(dǎo)入。為避免多次導(dǎo)入造成數(shù)據(jù)異常,在進(jìn)行導(dǎo)入時(shí),建議使用“-c” 參數(shù),在重新創(chuàng)建數(shù)據(jù)庫(kù)對(duì)象前,清理(刪除)已存在于將要還原的數(shù)據(jù)庫(kù)中的數(shù)據(jù)庫(kù)對(duì)象。
- 日志打印無(wú)開(kāi)關(guān),若需隱藏日志,請(qǐng)將日志重定向到日志文件。若恢復(fù)表數(shù)據(jù)時(shí),數(shù)據(jù)量很大,會(huì)分批恢復(fù),因此會(huì)多次出現(xiàn)“表數(shù)據(jù)已完成導(dǎo)入”的日志。
表 1?常用參數(shù)說(shuō)明
參數(shù) |
參數(shù)說(shuō)明 |
舉例 |
---|---|---|
-U |
連接數(shù)據(jù)庫(kù)的用戶名。 |
-U jack |
-W |
指定用戶連接的密碼。
|
-W abcd@123 |
-d |
連接數(shù)據(jù)庫(kù)dbname,并直接將數(shù)據(jù)導(dǎo)入到該數(shù)據(jù)庫(kù)中。 |
-d backupdb |
-p |
指定服務(wù)器所偵聽(tīng)的TCP端口或本地Unix域套接字后綴,以確保連接。 |
-p?8000 |
-e |
當(dāng)發(fā)送SQL語(yǔ)句到數(shù)據(jù)庫(kù)時(shí)如果出現(xiàn)錯(cuò)誤,則退出。默認(rèn)狀態(tài)下會(huì)忽略錯(cuò)誤任務(wù)并繼續(xù)執(zhí)行導(dǎo)入,且在導(dǎo)入后會(huì)顯示一系列錯(cuò)誤信息。 |
- |
-c |
在重新創(chuàng)建數(shù)據(jù)庫(kù)對(duì)象前,清理(刪除)已存在于將要導(dǎo)入的數(shù)據(jù)庫(kù)中的數(shù)據(jù)庫(kù)對(duì)象。 |
- |
-s |
只導(dǎo)入模式定義,不導(dǎo)入數(shù)據(jù)。當(dāng)前的序列值也不會(huì)被導(dǎo)入。 |
- |
示例
特例:執(zhí)行g(shù)sql程序,使用如下選項(xiàng)導(dǎo)入由gs_dump/gs_dumpall生成導(dǎo)出文件夾(純文本格式)的MPPDB_backup.sql文件到postgres數(shù)據(jù)庫(kù)。
gsql -d postgres -p 15400 -W Bigdata@123 -f /home/omm/test/MPPDB_backup.sql
SET
SET
SET
SET
SET
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
CREATE INDEX
CREATE INDEX
CREATE INDEX
SET
CREATE INDEX
REVOKE
REVOKE
GRANT
GRANT
total time: 30476 ms
gs_restore用來(lái)導(dǎo)入由gs_dump生成的導(dǎo)出文件。
示例1:執(zhí)行g(shù)s_restore,將導(dǎo)出的MPPDB_backup.dmp文件(自定義歸檔格式)導(dǎo)入到postgres數(shù)據(jù)庫(kù)。
gs_restore -W Bigdata@123 backup/MPPDB_backup.dmp -p 15400 -d postgres
gs_restore: restore operation successful
gs_restore: total time: 13053 ms
示例2:執(zhí)行g(shù)s_restore,將導(dǎo)出的MPPDB_backup.tar文件(tar格式)導(dǎo)入到postgres數(shù)據(jù)庫(kù)。
gs_restore backup/MPPDB_backup.tar -p 15400 -d postgres
gs_restore[2017-07-21 19:16:26]: restore operation successful
gs_restore[2017-07-21 19:16:26]: total time: 21203 ms
示例3:執(zhí)行g(shù)s_restore,將導(dǎo)出的MPPDB_backup文件(目錄格式)導(dǎo)入到postgres數(shù)據(jù)庫(kù)。
gs_restore backup/MPPDB_backup -p 15400 -d postgres
gs_restore[2017-07-21 19:16:26]: restore operation successful
gs_restore[2017-07-21 19:16:26]: total time: 21003 ms
示例4:執(zhí)行g(shù)s_restore,使用自定義歸檔格式的MPPDB_backup.dmp文件來(lái)進(jìn)行如下導(dǎo)入操作。 導(dǎo)入PUBLIC模式下所有對(duì)象的定義和數(shù)據(jù)。在導(dǎo)入時(shí)會(huì)先刪除已經(jīng)存在的對(duì)象,如果原對(duì)象存在跨模式的依賴則需手工強(qiáng)制干預(yù)。
gs_restore backup/MPPDB_backup.dmp -p 15400 -d postgres -e -c -n PUBLIC
gs_restore: [archiver (db)] Error while PROCESSING TOC:
gs_restore: [archiver (db)] Error from TOC entry 313; 1259 337399 TABLE table1 gaussdba
gs_restore: [archiver (db)] could not execute query: ERROR: cannot drop table table1 because other objects depend on it
DETAIL: view t1.v1 depends on table table1
HINT: Use DROP ... CASCADE to drop the dependent objects too.
Command was: DROP TABLE public.table1;
手工刪除依賴,導(dǎo)入完成后再重新創(chuàng)建。
gs_restore backup/MPPDB_backup.dmp -p 15400 -d postgres -e -c -n PUBLIC
gs_restore[2017-07-21 19:16:26]: restore operation successful
gs_restore[2017-07-21 19:16:26]: total time: 2203 ms
示例5:執(zhí)行g(shù)s_restore,使用自定義歸檔格式的MPPDB_backup.dmp文件來(lái)進(jìn)行如下導(dǎo)入操作。只導(dǎo)入PUBLIC模式下表table1的定義。
gs_restore backup/MPPDB_backup.dmp -p 15400 -d postgres -e -c -s -n PUBLIC -t table1
gs_restore[2017-07-21 19:16:26]: restore operation successful
gs_restore[2017-07-21 19:16:26]: total time: 21000 ms
示例6:執(zhí)行g(shù)s_restore,使用自定義歸檔格式的MPPDB_backup.dmp文件來(lái)進(jìn)行如下導(dǎo)入操作。只導(dǎo)入PUBLIC模式下表table1的數(shù)據(jù)。
gs_restore backup/MPPDB_backup.dmp -p 15400 -d postgres -e -a -n PUBLIC -t table1
gs_restore[2017-07-21 19:16:26]: restore operation successful
gs_restore[2017-07-21 19:16:26]: total time: 20203 ms
總結(jié)
原文鏈接:https://blog.csdn.net/starlooksky/article/details/125045916
相關(guān)推薦
- 2022-04-22 docker拉取常用開(kāi)發(fā)工具
- 2022-01-06 ruoyi中生成的代碼表單,如果添加上傳功能-模板下載功能
- 2022-09-23 基于React路由跳轉(zhuǎn)的幾種方式_React
- 2023-05-22 解決The?Network?Adapter?could?not?establish?the?conn
- 2022-05-18 python操作jira添加模塊的方法_python
- 2022-09-29 Python?pkg_resources模塊動(dòng)態(tài)加載插件實(shí)例分析_python
- 2022-05-11 Python實(shí)現(xiàn)圖書(shū)管理系統(tǒng)設(shè)計(jì)_python
- 2022-03-19 c語(yǔ)言執(zhí)行Hello?World背后經(jīng)歷的步驟_C 語(yǔ)言
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支