gbase 导出_GBase 8s数据库常用操作指南
戳上面的藍(lán)字關(guān)注我們哦!
GBase 8s產(chǎn)品是南大通用自主研發(fā)的一款安全型數(shù)據(jù)庫管理系統(tǒng),功能強(qiáng)大、高效穩(wěn)定、簡單易用,具備高性能、高可用、高安全特性。下面是匯總的GBase 8s常用操作命令:數(shù)據(jù)庫日常管理命令、SQL操作、數(shù)據(jù)裝載與卸載、備份與恢復(fù)操作等。1數(shù)據(jù)庫日常管理命令
簡介
GBase 8s數(shù)據(jù)庫日常管理包括數(shù)據(jù)庫模式的切換,以及服務(wù)器的監(jiān)控。監(jiān)控主要分為兩個方面,一方面是系統(tǒng)級別的監(jiān)控,主要包括對系統(tǒng)cpu的監(jiān)控,以及內(nèi)存的占用情況;另一方面是數(shù)據(jù)庫級別的監(jiān)控,包括對磁盤空間大小的監(jiān)控,對邏輯日志物理日志的監(jiān)控,對數(shù)據(jù)表中數(shù)據(jù)量的監(jiān)控,以及表中索引層數(shù),順序掃描次數(shù)等等。我們可以通過命令或者sql語句的方式,完成對數(shù)據(jù)庫的監(jiān)控。
語法
1.啟動數(shù)據(jù)庫服務(wù):
oninit -vy
2.關(guān)閉數(shù)據(jù)庫服務(wù):
onmode -ky
3.監(jiān)控系統(tǒng)cpu和內(nèi)存使用情況:
top
?
4.查看數(shù)據(jù)庫版本和運行模式:
onstat -
5.監(jiān)控數(shù)據(jù)庫磁盤空間大小
onstat -d
6.監(jiān)控邏輯日志,物理日志信息
onstat -l
7.監(jiān)控GBase 8s占用系統(tǒng)內(nèi)存大小:
onstat -g seg
8.監(jiān)控實例整體運行情況
onstat -p
9.查看實例運行日志最后20行信息
onstat -m
10.查看數(shù)據(jù)庫進(jìn)程狀態(tài)
onstat -g glo
11.查看數(shù)據(jù)庫會話狀態(tài)
onstat -g ses
12.從離線模式向靜態(tài)模式轉(zhuǎn)換:
oninit -s
13.從離線模式向管理員模式轉(zhuǎn)換:
oninit -j
14.從管理員模式,靜態(tài)模式向在線模式轉(zhuǎn)換:
onmode -m
15.從在線模式向管理員模式轉(zhuǎn)換:
onmode -j
16.從在線模式向靜態(tài)模式轉(zhuǎn)換:
onmode -s;onmode -u
2SQL指南
語法簡介:
創(chuàng)建數(shù)據(jù)庫對象的語法都是使用CREATE +“數(shù)據(jù)庫對象類型”+“數(shù)據(jù)庫對象名”的方式開頭,然后再定義其中具體的細(xì)節(jié)。這類語法屬于DDL(Data Definition Language)數(shù)據(jù)庫定義語言。
在GBase 8s中,有四種日志類型的數(shù)據(jù)庫,分別是無日志模式,緩沖式日志模式,無緩沖式日志模式和ANSI模式。
無日志模式,數(shù)據(jù)庫性能好,但是不支持邏輯恢復(fù)操作;
緩沖式日志模式,既支持?jǐn)?shù)據(jù)庫邏輯恢復(fù)的功能,同時又能避免頻繁的I/O操作,是生產(chǎn)系統(tǒng)中常見的日志類型;
無緩沖式日志模式,會有頻繁的I/O操作,優(yōu)點是一旦數(shù)據(jù)庫宕機(jī),損失較小。
ANSI模式,是一種特殊的無緩沖式日志模式,要符合額外的ANSI規(guī)則。
1.創(chuàng)建庫語法
create database “數(shù)據(jù)庫名” in“dbspace名”
[ with buffered log | with log | with log mode ansi]
2.創(chuàng)建表語法
create [ tmp | row ] table“表名”(“列名””數(shù)據(jù)類型”“列級約束”, ... ... ,
[ 表級約束 ] ) [ in“表的存放路徑”]
3.修改表語法
alter table“表名”add“列名”“數(shù)據(jù)類型”| modify“列名”“數(shù)據(jù)類型”|drop column“列名”
4.刪除表語法
drop table“表名”
5.查詢數(shù)據(jù)語法
select ?[ all | distinct ] ?“列表達(dá)式”, ??...... ??from ?”表名“, ......
[ where ?”條件表達(dá)式“ ]
[ group by “列名”, ...... [ having ?”條件表達(dá)式“ ] ]
[ order by ”列名“ [ asc | desc ], ...... ] ;
6.插入數(shù)據(jù)語法
insert into “表名”[ ( 列1, 列2, 列3, ...... ) ] values ( 值1, 值2 , 值3 , ...... )
7.更新數(shù)據(jù)語法
update “表名”set 列1=值1, ...... [ where “條件表達(dá)式” ]
8.刪除數(shù)據(jù)語法
delete from “表名”[ where “條件表達(dá)式” ]
簡單示例:
創(chuàng)建緩沖式日志模式數(shù)據(jù)庫testdb,test表,以及insertdata存儲過程 :
切換到8s的linux操作用戶,并生效當(dāng)前實例對應(yīng)的環(huán)境變量文件:
su - gbasedbt
. .bash_profile
進(jìn)入sql編輯器dbaccess,執(zhí)行SQL語句:
dbaccess - -
>create database testdb in datadbs1 with buffered log;
-- 創(chuàng)建庫testdb
>create table test (id int , name char(20) );
-- 創(chuàng)建test表
>create procedure insertdata()
>define i int;
>for i in (1 to 100)
>insert into test values(i,'GBase 8s');
>end for;
>end procedure;
-- 創(chuàng)建insertdata()存儲過程,向test表中插入100條數(shù)據(jù)
>execute procedure insertdata();
-- 執(zhí)行insertdata()存儲過程
>select ?a.cf_original, DBINFO('dbname') dbname,user from
>sysmaster:sysconfig a where cf_name = 'testdb';-- 查看實例名,數(shù)據(jù)庫名,用戶名
>select ?name ?from sysmaster:sysdatabases;-- 查看實例中所有數(shù)據(jù)庫名
>select ?dbsname,tabname from sysmaster:systabnames where
>dbsname='testdb';-- 查看數(shù)據(jù)庫中所有表名
3數(shù)據(jù)裝載與卸載指南語法簡介:
GBase 8s中根據(jù)裝載卸載粒度的不同,有不同的裝載卸載工具。
1.load/unload:裝卸載粒度表級,SQL命令,輸出結(jié)果為明文.
unload to‘filename’ ?[DELIMITER ‘delimiter’] select Statement;
load from‘filename’ [DELIMITER ‘delimiter’] insert into
Table Name | Synonym Name| View Name [(column)];
2.onunload/onload 工具:裝卸載粒度為數(shù)據(jù)庫級或表級,輸出結(jié)果為二進(jìn)制文件。
onunload [-l] [-t ] [:[.]
onload [-l] [-t ] ?[-d ] [:[.]
3.dbload 工具:裝載粒度為表級,功能比load方式強(qiáng)大,使用起來也相對復(fù)雜。
dbload [-d dbname] [-c cfilname] [-l logfile] [-e errnum] [-n nnum]
4.dbexport/dbimport 工具:裝卸載粒度為數(shù)據(jù)庫級,輸出結(jié)果為明文。
dbexport [-ss] [{ -o | -t }]
dbimport [-d ] ?[-l [{ buffered }] [-ansi]] [-ci] [-nv] [-D][{ -i
簡單實例
(1)通過unload將test表數(shù)據(jù)卸載到test.db文件,用豎線做列的分隔符
>unload to tmp/test.db select * from test;
通過load將test.db中的數(shù)據(jù)裝載到test表中
>load from tmp/test.db insert into test;
(2)通過dbload工具將test.db中的數(shù)據(jù)裝載到test表中
先建立命令文件:例如/tmp/test.ctl ?在文件中 寫入以下命令
vi tmp/test.ctl(添加如下兩行內(nèi)容)
FILE tmp/test.db delimiter "|" 2;
insert into test;
(/tmp/test.ctl 是數(shù)據(jù)文件,2代表兩個字段)
然后用dbload命令導(dǎo)入數(shù)據(jù):
dbload -d testdb -c tmp/test.ctl -l error.log
(3)使用dbexport/dbimport遷移數(shù)據(jù)庫
使用dbexport將testdb數(shù)據(jù)庫導(dǎo)出 -ss生成服務(wù)器特定的語法
dbexport testdb -ss
刪除testdb數(shù)據(jù)庫
dbaccess - -
>drop database testdb;
使用dbimport重新導(dǎo)入testdb數(shù)據(jù)庫,數(shù)據(jù)庫創(chuàng)建在datadbs1數(shù)據(jù)庫空間中。導(dǎo)入過程使用緩沖日志模式
dbimport testdb -d datadbs1?-l buffered
4備份與恢復(fù)操作指南語法簡介
GBase 8s數(shù)據(jù)庫中,備份與恢復(fù)分為三個級別,分別是0級備份,1級備份,以及2級備份。0級備份指的是備份數(shù)據(jù)庫中所有的數(shù)據(jù);1級備份是在0級備份基礎(chǔ)上,備份被修改過的數(shù)據(jù)頁;2級備份是在1級備份基礎(chǔ)上,備份被修改過的數(shù)據(jù)頁。主要的備份命令有兩個,分別是ontape和onbar 。其中,onbar命令功能強(qiáng)大,可以恢復(fù)到具體時間點,可以選擇具體存儲空間,可以并行執(zhí)行備份操作,但是相對配置比較復(fù)雜。ontape命令簡單易用,雖然沒有onbar功能強(qiáng)大,但是使用ontape命令在備份的同時,可以更改數(shù)據(jù)庫日志模式,這也是比較實用的功能。
1.ontape語法:
ontape ?-a [-d]//備份邏輯日志
ontape -s [[-L archive_level]] [-A database_list] [-B database_list]
[-N database_list] [-U database_list] [-t tape_device_path ]
//備份數(shù)據(jù)庫
ontape -p//恢復(fù)數(shù)據(jù)庫
2.onbar 語法:
onbar -b -l [-c | -C | -s] [-O]//備份邏輯日志
onbar -b ?[-L ] [-w | -f | ] [-O]//備份數(shù)據(jù)庫
onbar -r -l [ -t "" | -n ]//恢復(fù)邏輯日志
onbar -r ?[-t "" | -n ] [-f | ]//恢復(fù)數(shù)據(jù)庫
簡單示例
(1)使用ontape命令執(zhí)行零級數(shù)據(jù)庫備份
ontape -s -L 0
通過onstat -m命令查看日志中備份信息。
通過onstat -g arc命令查看數(shù)據(jù)庫近期備份情況。
(2)使用ontape命令恢復(fù)數(shù)據(jù)庫
關(guān)閉實例:
onmode -ky
執(zhí)行ontape命令
ontape -r//從離線模式到靜態(tài)模式
onmode -m//轉(zhuǎn)換到在線模式
總結(jié)
以上是生活随笔為你收集整理的gbase 导出_GBase 8s数据库常用操作指南的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Atlassian代码评审Fisheye
- 下一篇: 忽然出现的wsappx占用了几乎所有内存