达梦数据库初级维护(dm8)

我的环境是银河麒麟V10操作系统x86,数据库软件是dm8.
1.数据库软件安装
1.1 创建安装用户组
#groupadd dinstall

1.2 创建安装用户
#useradd -g dinstall -m -d /home/dmdba -s /bin/bash dmdba

#useradd -g dinstall dmdba

1.3 初始化用户密码
#passwd dmdba

1.4 修改系统限制
#vi /etc/security/limits.conf

dmdba soft nofile 65536
dmdba hard nofile 65536

2.数据库创建
2.1 创建安装目录和赋权
mkdir /dm8
chown dmdba.dinstall /dm8

2.2 挂载镜像
#mount /dev/sr0 /mnt

2.3 安装软件
su – dmdba
cd /mnt
$ ./DMInstall.bin -i
请选择安装语言(C/c:中文 E/e:英文) [C/c]:c
解压安装程序……….
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 15472
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65536
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 15472
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

可打开文件数过少,建议至少设置为65536或更多。

欢迎使用达梦数据库安装程序

是否输入Key文件路径(Y/y:是 N/n:否) [Y/y]:n

是否设置时区(Y/y:是 N/n:否) [Y/y]:y
设置时区:
[ 1]: GTM-12=日界线西
[ 2]: GTM-11=萨摩亚群岛
[ 3]: GTM-10=夏威夷
[ 4]: GTM-09=阿拉斯加
[ 5]: GTM-08=太平洋时间(美国和加拿大)
[ 6]: GTM-07=亚利桑那
[ 7]: GTM-06=中部时间(美国和加拿大)
[ 8]: GTM-05=东部部时间(美国和加拿大)
[ 9]: GTM-04=大西洋时间(美国和加拿大)
[10]: GTM-03=巴西利亚
[11]: GTM-02=中大西洋
[12]: GTM-01=亚速尔群岛
[13]: GTM=格林威治标准时间
[14]: GTM+01=萨拉热窝
[15]: GTM+02=开罗
[16]: GTM+03=莫斯科
[17]: GTM+04=阿布扎比
[18]: GTM+05=伊斯兰堡
[19]: GTM+06=达卡
[20]: GTM+07=曼谷,河内
[21]: GTM+08=中国标准时间
[22]: GTM+09=汉城
[23]: GTM+10=关岛
[24]: GTM+11=所罗门群岛
[25]: GTM+12=斐济
[26]: GTM+13=努库阿勒法
[27]: GTM+14=基里巴斯
请选择设置时区 [21]:21

安装类型:
1 典型安装
2 服务器
3 客户端
4 自定义
请选择安装类型的数字序号 [1 典型安装]:1
所需空间: 1043M

请选择安装目录 [/home/dmdba/dmdbms]:/dm8
可用空间: 20G
是否确认安装路径(/dm8)(Y/y:是 N/n:否)  [Y/y]:y

安装前小结
安装位置: /dm8
所需空间: 1043M
可用空间: 20G
版本信息:
有效日期:
安装类型: 典型安装
是否确认安装(Y/y:是 N/n:否):y
2022-03-27 22:15:32
[INFO] 安装达梦数据库…
2022-03-27 22:15:32
[INFO] 安装 基础 模块…
2022-03-27 22:15:35
[INFO] 安装 服务器 模块…
2022-03-27 22:15:35
[INFO] 安装 客户端 模块…
2022-03-27 22:15:37
[INFO] 安装 驱动 模块…
2022-03-27 22:15:37
[INFO] 安装 手册 模块…
2022-03-27 22:15:38
[INFO] 安装 服务 模块…
2022-03-27 22:15:39
[INFO] 移动ant日志文件。
2022-03-27 22:15:41
[INFO] 安装达梦数据库完成。

请以root系统用户执行命令:
/dm8/script/root/root_installer.sh

安装结束
$su –
#/dm8/script/root/root_installer.sh

2.4 创建DMTEST库
$cd /dm8/bin
$./dminit path=/dm8/data db_name=DMTEST instance_name=DMTESTSVR port_num=5238 sysdba_pwd=admin@9000 LOG_SIZE=128

2.5 注册数据库
#cd /dm8/script/root
#./dm_service_installer.sh -t dmserver -p DMTESTSVR -dm_ini /dm8/data/DMTEST/dm.ini

2.6 数据库状态转换
SQL> alter database mount;
SQL> alter database open;
SQL> alter database suspend;
SQL> alter database open;
SQL> select status$ from v$instance;

2.7 数据库启动
dmdba用户前台启动
$cd /dm8/bin
$./dmserver /dm8/data/DAMENG/dm.ini

version info: enterprise
Use normal os_malloc instead of HugeTLB
Use normal os_malloc instead of HugeTLB
DM Database Server x64 V8 1-1-156-20.12.25-132258-ENT  startup…
Database mode = 0, oguid = 0
Warning: Only 1 physical CPUs can be used due to the license restriction!
other_thread 0 is assigned to #0 logical cpu
other_thread 1 is assigned to #1 logical cpu
other_thread 2 is assigned to #0 logical cpu
other_thread 3 is assigned to #1 logical cpu
other_thread 4 is assigned to #0 logical cpu
other_thread 5 is assigned to #1 logical cpu
other_thread 6 is assigned to #0 logical cpu
other_thread 7 is assigned to #1 logical cpu
file lsn: 43248
ndct db load finished
ndct fill fast pool finished
other_thread 8 is assigned to #0 logical cpu
other_thread 9 is assigned to #1 logical cpu
iid page’s trxid[6016]
NEXT TRX ID = 6017
pseg_collect_mgr_items, total collect 0 active_trxs, 0 cmt_trxs, 0 pre_cmt_trxs, 0 active_pages, 0 cmt_pages, 0 pre_cmt_pages, 0 mgr pages, 0 mgr recs!
total 0 active crash trx, pseg_crash_trx_rollback sys_only(0) begin …
pseg_crash_trx_rollback end, total 0 active crash trx, include 0 empty_trxs, 0 empty_pages which only need to delete mgr recs.
pseg_crash_trx_rollback end
pseg recv finished
other_thread 10 is assigned to #0 logical cpu
nsvr_startup end.
other_thread 11 is assigned to #1 logical cpu
other_thread 12 is assigned to #0 logical cpu
other_thread 13 is assigned to #1 logical cpu
other_thread 14 is assigned to #0 logical cpu
other_thread 15 is assigned to #1 logical cpu
other_thread 16 is assigned to #0 logical cpu
other_thread 17 is assigned to #1 logical cpu
other_thread 18 is assigned to #0 logical cpu
other_thread 19 is assigned to #1 logical cpu
other_thread 20 is assigned to #0 logical cpu
other_thread 21 is assigned to #1 logical cpu
other_thread 22 is assigned to #0 logical cpu
other_thread 23 is assigned to #1 logical cpu
other_thread 24 is assigned to #0 logical cpu
other_thread 25 is assigned to #1 logical cpu
other_thread 26 is assigned to #0 logical cpu
other_thread 27 is assigned to #1 logical cpu
other_thread 28 is assigned to #0 logical cpu
aud sys init success.
aud rt sys init success.
systables desc init success.
ndct_db_load_info success.
nsvr_process_before_open begin.
nsvr_process_before_open success.
other_thread 29 is assigned to #1 logical cpu
other_thread 30 is assigned to #0 logical cpu
total 0 active crash trx, pseg_crash_trx_rollback sys_only(0) begin …
pseg_crash_trx_rollback end, total 0 active crash trx, include 0 empty_trxs, 0 empty_pages which only need to delete mgr recs.
pseg_crash_trx_rollback end
SYSTEM IS READY.

关闭输入exit即可

exit

Server is stopping…
listener closed  and all sessions disconnected
purge undo records in usegs…OK
full check point starting…
generate force checkpoint, rlog free space[536716800], used space[145920]
ckpt_lsn, ckpt_fil, ckpt_off are set as (44504, 0, 9660416)
checkpoint: 0 pages flushed.
checkpoint finished, rlog free space, used space is (536851968, 10752)
full check point end.
shutdown audit subsystem…OK
shutdown schedule subsystem…OK
shutdown timer successfully.
pre-shutdown MAL subsystem…OK
shutdown worker threads subsystem…OK
shutdown local parallel threads pool successfully.
shutdown replication subsystem…OK
shutdown sequence cache subsystem…OK
wait for mtsk link worker to exit..OK
shutdown mpp session subsystem…OK
wait for rapply is all over… OK
rapply worker threads exit successfully.
pre ending task & worker threads…OK
shutdown dblink subsystem…OK
shutdown session subsystem…OK
shutdown rollback segments purging subsystem…OK
shutdown rps subsystem…OK
shutdown transaction subsystem…OK
shutdown locking subsystem…OK
shutdown dbms_lock subsystem…OK
ending tsk and worker threads…OK
ckpt2_exec_immediately begin.
ckpt_lsn, ckpt_fil, ckpt_off are set as (44504, 0, 9671168)
checkpoint: 0 pages flushed.
checkpoint finished, rlog free space, used space is (536842240, 20480)
ckpt_lsn, ckpt_fil, ckpt_off are set as (44735, 0, 9691648)
checkpoint: 0 pages flushed.
checkpoint finished, rlog free space, used space is (536862720, 0)
ckpt_lsn, ckpt_fil, ckpt_off are set as (44735, 0, 9691648)
checkpoint: 0 pages flushed.
checkpoint finished, rlog free space, used space is (536862720, 0)
shutdown archive subsystem…OK
shutdown redo log subsystem…OK
shutdown MAL subsystem…OK
shutdown message compress subsystem successfully.
shutdown task subsystem…OK
shutdown trace subsystem…OK
shutdown svr_log subsystem…OK
shutdown plan cache subsystem…OK
shutdown file subsystem…OK
shutdown database dictionary subsystem…OK
shutdown mac cache subsystem…OK
shutdown dynamic login cache subsystem…OK
shutdown ifun/bifun/sfun/afun cache subsystem…OK
shutdown crypt subsystem…OK
shutdown pipe subsystem…OK
shutdown compress component…OK
shutdown slave redo subsystem…OK
shutdown kernel buffer subsystem…OK
shutdown SQL capture subsystem…OK
shutdown control file system…OK
shutdown dtype subsystem…OK
shutdown huge buffer and memory pools…OK
close lsnr socket
DM Database Server shutdown successfully.

root用户启动

#systemctl start DmServiceDMSERVER.service
#systemctl status DmServiceDMSERVER.service

3.表空间管理
3.1 视图
dba_tablespaces
v$tablespace

3.2 表空间说明
SQL> select TABLESPACE_NAME,STATUS from dba_tablespaces;

System表空间: 数据字典和全局的系统数据。
ROLL表空间:存放了数据库运行过程中产生的回滚记录。
TEMP表空间:临时表空间。
MAIN表空间:数据库默认的表空间,创建数据对象时,如果不指定存储位置,默认存放到该表空间。

3.3 查询所有表空间信息
SQL> Select name from v$tablespace union select name from v$huge_tablespace;

3.4 创建表空间
DM 表空间数据文件的大小范围,最小值不能低于页大小的 4096 倍,最大值不能高于页大小的 2 的 31 次方-1;

示例1:表空间初始大小50M,每次扩展1M,最大1000M
SQL> create tablespace xyong datafile ‘/dm8/data/DAMENG/tbs01.dbf’ size 50 autoextend on next 1 maxsize 1000;

示例2:表空间初始50M,表空间由2个数据文件组成,分别存储到不同的磁盘上,每次扩展1m,每个数据文件最大1000M.
SQL> create tablespace xyong2 datafile ‘/dm8/data/DAMENG/tbs02.dbf’ size 50 autoextend on next 1 maxsize 1000,’/dm8/data/DAMENG/tbs03.dbf’ size 50 autoextend on next 1 maxsize 1000;

3.5 维护表空间
3.5.1 增加数据文件
SQL> alter tablespace xyong add datafile ‘/dm8/data/DAMENG/tbs04.dbf’ size 50 autoextend on next 1 maxsize 1000;

3.5.2 修改表空间不自动扩展
SQL> alter tablespace xyong datafile ‘tbs01.dbf’ AUTOEXTEND off;

3.5.3 修改表空间大小
SQL> alter tablespace xyong resize datafile ‘tbs01.dbf’ to 60;

3.5.4 表空间迁移
SQL> alter tablespace xyong offline;
SQL> alter tablespace xyong RENAME DATAFILE ‘tbs01.dbf’to ‘/dm8/data/DAMENG/tbs01_qy.dbf’;
SQL> alter tablespace xyong online;

3.6 重做日志文件
3.6.1 视图
v$rlogfile
v$rlog
SQL> select * from v$rlogfile;

3.6.2 添加日志文件
SQL> alter database add logfile ‘/dm8/data/DAMENG/dmdb01.log’ size 256;

3.6.3 修改日志文件大小
SQL> alter database resize logfile ‘/dm8/data/DAMENG/dmdb02.log’ to 512;

3.6.4 修改联机日志需要数据库切换到mount状态

SQL> alter database add logfile ‘DAMENG03.log’ SIZE 128;
SQL> alter database mount;
SQL> alter DATABASE RENAME LOGFILE ‘DAMENG03.log’ TO ‘/dm8/data/DAMENG/DAMENG04.log’;
SQL> alter database open;

3.6.5 自定义表空间页可以重命名。
SQL> alter TABLESPACE xyong RENAME TO xyong1;

3.6.6 删除表和表空间
SQL> create table t_test01 (id int, name varchar(200)) tablespace xyong1;
SQL> select * from t_test01;
SQL> drop tablespace xyong1;(已使用的表空间无法删除)
SQL> drop table t_test01;
SQL> drop tablespace xyong1;

4.用户管理
4.1 视图 
dba_users

4.2 内置用户
sys — 达梦数据库的内置管理用户,不能登录数据库,数据库使用的大部分的数据字典和动态性能视图
Sysdba — 数据库的管理员
Sysauditor — 审计用户
Syssso — 安全用户
sysdbo — 数据操作员(安全版有,四权分立)

4.3 命名规则
字母开头,a-z,0-9,$#_

4.4 口令策略
用户密码最长为48个字节,创建用户语句使用 password policy 子句来指定口令策略(DM.INI PWD_POLICY).
系统支持的口令策略:
   0 无策略
   1 禁止与用户名相同
   2 口令长度不小于9
   4 至少包含一个大写字母(A-Z)
  8 至少包含一个数字(0-9)
 16 至少包含一个标点符号(英文状态输入,除”和空格外)
口令可以单独使用,也可以组合使用,比如需要应策略1和2,则设置口令策略为:3
密码尝试登录次数 FAILED_LOGIN_ATTEMPS
密码失败锁定时间 PASSWORD_LOCK_TIME
密码过期时间 PASSWORD_LIFE_TIME

4.5 用户权限
系统权限: create drop alter 能够对数据库做什么操作。
对象权限(表,视图,过程等等): select delete update insert
角色: dba、public等

4.6 查看用户权限:
SQL> select grantee,granted_role from dba_role_privs where grantee=’USER1′;

行号 GRANTEE GRANTED_ROLE
———- ——- ————
1 USER1 PUBLIC

4.7 查看角色拥有的权限
SQL> select grantee,privilege from dba_sys_privs where grantee=’PUBLIC’;
行号 GRANTEE PRIVILEGE 
———- ——- —————-
1 PUBLIC INSERT TABLE
2 PUBLIC UPDATE TABLE
3 PUBLIC DELETE TABLE
4 PUBLIC SELECT TABLE
5 PUBLIC REFERENCES TABLE
6 PUBLIC GRANT TABLE
…..

4.8 示例

1:为数据库设置一个用户,该用户可以创建自己的表,有属于自己的独立表空间,用户密码要求每120天变更一次。
SQL> create tablespace xyong3 datafile ‘/dm8/data/DAMENG/tbs05.dbf’ size 50;
SQL> create user xyong identified by xyong1017 limit password_life_time 120 default tablespace xyong3;

2:创建一个用户,该用户每120天变更一次密码,密码尝试连接3次失败,账户锁定3分钟,用户还可以查询dmhr.employee表
SQL> create user xyong2 identified by xyong1017 limit password_life_time 120, FAILED_LOGIN_ATTEMPS 3 ,PASSWORD_LOCK_TIME 3 default tablespace xyong3;
SQL> grant select on dmhr.employee to xyong2;

3:批录入人员,权限是固定的,只有录入CITY表的权限
角色:一类权限的集合
SQL> create role role1;
SQL> grant insert on dmhr.city to role1;
SQL> grant references any table to role1;
SQL> grant role1 to xyong2;

4.9 用户维护

1)撤销权限
SQL> revoke select on dmhr.employee from xyong2;

2)解锁用户
SQL> alter user xyong2 account unlock;

3)修改密码
SQL> alter user xyong2 identified by xyong1990;

4)删除用户
SQL> drop user xyong2;

5)删除用户(级联删除)
SQL> drop user xyong2 cascade;(4、5步骤只能执行一个)

5.表管理
5.1 达梦数据库支持的表
索引组织表(默认的表)、堆表、临时表、分区表、外部表等。

5.2 创建表时包含的内容
命名:字母开头 a-z,0-9,$#_
数据类型:int char varchar date clob blob number等等。
存储位置:自已的规划的表空间。
约束(5大约束): 非空约束,唯一约束,主键,检查,外键
注释:comment
遵循3范式

5.3 示例
1)要求
表名:STUDENT
学号(id char(10)), 
姓名(sname varchar(20) not null),
性别 (sex char(1))
年龄(age int)
电话(tel varchar(15) not null)
家庭住址:(address varchar(50))
表空间:STU
约束:主键列—学号 非空—姓名,电话
备注:学员信息表

2)SQL语句
创建用户:
SQL> create user xyong2 identified by xyong1017 limit password_life_time 120, FAILED_LOGIN_ATTEMPS 3 ,PASSWORD_LOCK_TIME 3 default tablespace xyong3;
创建表

create table xyong2.STUDENT

ID CHAR(10) not null ,
SNAME VARCHAR(20) not null ,
SEX CHAR(1),
AGE INT,
TEL VARCHAR(15) not null ,
ADDRESS VARCHAR(50),
primary key(ID)
) storage (on xyong3);

5.4 查看表结构

SQL> select * from dba_tab_columns t where t.owner=’XYONG2′;

5.5 查看表所属表空间
SQL> select table_name,tablespace_name from dba_tables where table_name=’STUDENT’;
行号     TABLE_NAME TABLESPACE_NAME
———- ———- —————
1          STUDENT    XYONG3

5.6 查看表有哪些约束
SQL> select table_name,constraint_name,constraint_type from dba_constraints where table_name=’STUDENT’;
行号     TABLE_NAME CONSTRAINT_NAME CONSTRAINT_TYPE
———- ———- ————— —————
1          STUDENT    CONS134218783   P

5.7 创建表时指定约束
1)非空约束
SQL> create table xyong2.t1(id int);
SQL> alter table xyong2.t1 modify id int not null;
或者:
SQL> create table xyong2.t2(id int not null);

2)唯一约束
SQL> create table xyong2.t3(id int unique);

3)主键约束
SQL> create table xyong2.t4(id int primary key);

4)检查约束
SQL> create table xyong2.t5(id int check(id>=5));

5)外键约束
SQL> create table xyong2.t6(id int primary key ,sid int foreign key references xyong2.t4(id));
说明:作为外键约束的列必须是另外一个表的主键

5.8 表的注释
SQL> comment on column xyong2.t1.id is ‘编号’;

5.9 维护表
1)重命名
SQL> alter table xyong2.t1 rename to t7;

2)增加删除列
SQL> alter table xyong2.t7 add name varchar(10);
SQL> alter table xyong2.t7 drop name;

3)启用禁用约束
SQL> select table_name,constraint_name,constraint_type from dba_constraints where table_name=’T4′;
行号 TABLE_NAME CONSTRAINT_NAME CONSTRAINT_TYPE
———- ———- ————— —————
1 T4 CONS134218785 P

SQL> alter table xyong2.T4 disable constraint CONS134218785;
SQL> alter table xyong2.T4 enable constraint CONS134218785;

6.数据录入

6.1 导入数据到表中
1)编写1.sql脚本:
insert into xyong2.t2(id) values(1);
insert into xyong2.t2(id) values(2);
insert into xyong2.t2(id) values(3);
insert into xyong2.t2(id) values(4);
SQL> start /dm8/a.sql
SQL> commit;
2)学员信息录入
SQL> select * from XYONG2.STUDENT 
SQL> INSERT INTO XYONG2.STUDENT(ID,SNAME,TEL) values(1,1,12345678999) 
SQL> COMMIT;

3)也可以用图形界面的DTS工具去做。

7.创建视图
7.1 视图分类
简单视图,复杂视图,物化视图
注:简单视图和复杂视图不占磁盘空间
物化视图占磁盘空间

7.2 创建视图
create view () as select () from () where ();

SQL> create view v1 as select * from xyong2.t1;
SQL> select * from v1;

行号 ID 
———- ———–
1 1
2 2
3 3
4 4

7.3 查看视图
SQL> select view_name,text from dba_views where view_name=’V1′;

行号 VIEW_NAME TEXT 
———- ——— ———————————
1 V1 SELECT xyong2.T1.ID FROM xyong2.T1

7.4 修改视图
SQL> create or replace view v1 as select * from xyong2.t2;
SQL> select * from v1;

8.创建索引

8.1 达梦支持的索引
二级索引、位图索引、唯一索引、复合索引、函数索引、分区索引等。
默认的表是索引组织表,是利用rowid创建一个默认的索引,所以创建的索引称为二级索引。

8.2 查看表的索引
SQL> select table_name,index_name from dba_indexes where table_name=’T2′;
行号 TABLE_NAME INDEX_NAME 
———- ———- ————-
1 T2 INDEX33555479

8.3 索引的作用
加快表的查询,对数据库做DML操作的时候,数据库会自动维护索引。索引是一棵倒置的树,使用索引,就是对这棵索引树做遍历。

8.4 建立索引的规则

1)适合建立索引的情况
经常查询的列
接条件列
谓词经常出现的列(where)
查询是返回表的一小部分数据

2)不适合做索引的情况:
列上有大量的null
列上的数据有限(例如性别)

8.5 创建索引
规划索引表空间
表的数据是无序的,索引的数据是有序的

示例:在Emp中的employee_id 建立索引。
1)建立表
SQL> create table xyong2.emp as select * from dmhr.employee;
2)建立索引表空间
SQL> create tablespace tbs_idx1 datafile ‘/dm8/data/DAMENG/tbs_idx101.dbf’ size 50;
3)建立索引:
SQL> create index ind_emp on xyong2.emp(employee_id) tablespace tbs_idx1;
4)查询索引:
SQL> select table_name,index_name from dba_indexes where table_name=’EMP’;

行号     TABLE_NAME INDEX_NAME
———- ———- ————-
1          EMP        INDEX33555486
2          EMP        IND_EMP

8.6 重建索引
SQL> alter index xyong2.IND_EMP rebuild;

9.参数修改
9.1 开启数据库归档模式
SQL> alter database mount;
SQL> alter database archivelog;
SQL> alter database add archivelog ‘type=local,dest=/dm8/archivelog,file_size=256,space_limit=10240’;
SQL> alter database open;
SQL> select arch_mode from v$database;
9.2 关闭归档
SQL> alter database mount; 
SQL> alter database noarchivelog; 
SQL> alter database delete archivelog ‘type=local,dest=/dm8/archivelog’;
SQL> select arch_mode from v$database;

10.备份还原
10.1 备份分类
物理备份、逻辑备份

10.2 物理备份
1)工具简介
冷备:(dmap服务打开的状态下,数据库是关闭的)
热备:(dmap服务一定是打开的,数据库也是打开的,数据库要开归档)
导入导出:dexp dimp
集群:数据守护(dw),dsc(rac)

2)物理备份过程(冷备)
开启数据库归档模式
SQL> alter database mount;
SQL> alter database archivelog;
SQL> alter database add archivelog ‘type=local,dest=/dm8/archivelog,file_size=256,space_limit=10240’;
SQL> alter database open;
SQL> select arch_mode from v$database;

3)停止数据库服务
#  systemctl stop DmServiceDMSERVER.service

4):使用dmrman备份
说明:dmrman 命令必须在命令所在的bin目录下执行才行
$cd /dm8/bin
$ ./dmrman
RMAN> backup database ‘/dm8/data/DAMENG/dm.ini’;
根据提示信息找到备份文件位置

3) 使用命令行备份(热备)
使用命令行备份,同样需要开归档,但是不需要停数据库服务
#mkdir /dm8/data/backup
SQL> backup database full backupset ‘/dm8/data/backup/full_bak’;
增量备份
SQL> insert into xyong2.t1 values(xyong2.s1.nextval);
SQL> select checkpoint(1);
SQL> backup database increment backupset ‘/dm8/data/backup/incr_bak’;

10.3 还原数据
1)选择实验用户和实验表空间
SQL> select username,default_tablespace from dba_users where username=’xyong2′;

行号 USERNAME DEFAULT_TABLESPACE
———- ——– ——————
1 XYONG2 TBS3

2)模拟表空间文件损坏
#mv tbs03.dbf tbs03.dbf.bak

3)重启服务
#systemctl stop DmServiceDMSERVER.service
#systemctl start DmServiceDMSERVER.service

4)手动打开数据库
SQL> alter database open;

5)查看表空间状态
SQL> select TABLESPACE_NAME,STATUS from dba_tablespaces where tablespace_name=’TBS3′;

行号 TABLESPACE_NAME STATUS 
———- ————— ———–
1 TBS3 1

6)恢复数据
SQL> restore tablespace tbs3 from backupset ‘/dm8/data/backup/full_bak’;

7)online表空间
SQL> alter tablespace tbs3 online;

8)查看表空间状态
SQL> select TABLESPACE_NAME,STATUS from dba_tablespaces where tablespace_name=’TBS3′;

行号 TABLESPACE_NAME STATUS 
———- ————— ———–
1 TBS3 0

9)查询数据
SQL> select * from user2.t1;
行号 ID 
———- ———–
1 1
2 2
3 3
4 4
10.4 逻辑导入导出
1)工具简介
Dexp 逻辑导出 dimp 逻辑导入
Dexp和dimp是DM自带的工具,分为四种级别:
数据库级,用户级、模式级和表级。四种级别独立互斥,不能同时存在。四种级别所提供的功能:
数据库级(full):导出或导入整个数据库中的访问对象。
用户级(owner):导出或导入一个或多个用户所拥有的所有对象。
模式级(schemas):导出或导入一个或多个模式下的所有对象。
表级(table):导出或导入一个或多个指定的表或表分区。

2)实验过程
第一步:备份xyong2下的数据

$cd /dm8/bin
$./dexp sysdba/SYSDBA file=/dm8/data/backup/xyong2.dmp log=/dm8/data/backup/xyong2.log owner=xyong2

第二步:恢复数据到xyong1下

$cd /dm8/bin
$./dimp sysdba/SYSDBA file=/dm8/data/backup/xyong2.dmp log=/dm8/data/backup/xyong1.log fromuser=xyong2 touser=xyong1

第三步:数据确认

SQL> select * from user1.t1;

LINEID id 
———- ———–
1 1
2 2
3 3
4 4

12.ODBC配置
配置ODBC
1)安装(root用户)
#tar -xvf unixODBC-2.3.0.tar.gz
#cd unixODBC-2.3.0
# ./configure –enable-gui=no
#make
#make install
# odbc_config –version
2.3.0
#odbc_config –odbcini
/usr/local/etc/odbc.ini
#odbcinst -j
unixODBC 2.3.0
DRIVERS…………: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size…….: 8
SQLLEN Size……..: 8
SQLSETPOSIROW Size.: 8

2)修改配置文件
#cd /usr/local/etc
#vi odbc.ini
[dm7]
Desription=DM ODBC DSND
Driver = DM7 ODBC DRIVER
SERVER = localhost
UID = SYSDBA
PWD = Abcd.1234
TCP_PORT = 5236

#vi odbcinst.ini 
[DM7 ODBC DRIVER]
Description = ODBC DRIVER FOR DM7
Driver = /dm8/bin/libdodbc.so

3)修改文件权限
#chmod 775 odbc.ini 
#chmod 775 odbcinst.ini

4)测试
#su – dmdba
#isql dm8 
+—————————————+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+—————————————+

文章知识点与官方知识档案匹配,可进一步学习相关知识MySQL入门技能树数据库组成32114 人正在系统学习中

来源:letttttttttt

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年2月26日
下一篇 2022年2月26日

相关推荐