关闭防火墙或开放对应端口
systemctl stop firewalld.service
firewall-cmd --list-ports
firewall-cmd --add-port=5236/tcp --zone=public --permanent
firewall-cmd -–reload
df -h
配置tmp目录
mount -o remount,size=2G /tmp
groupadd dinstall
useradd -g dinstall -m -d /home/dmdba -s /bin/bash dmdba
passwd dmdba
更改文件夹权限
chown dmdba:dinstall /dm8
达梦的参数信息可以查看 v p a r a m e t e r 和 v parameter 和 v parameter和vdm_ini
-- 修改参数
--也可以使用tool下的console图形界面修改,可搜索,有详细参数说明
alter system set ‘参数名’=参数值 spfile|memory|both;
ALTER SESSION SET name = value;
--查询参数
SELECT * FROM V$PARAMETER WHERE NAME LIKE '%COMPATIBLE_MODE%';
函数修改
-- 查询内置函数
select name, id from v$ifun t where t.name like 'SP_SET_PARA%';
select * from v$ifun_arg t where t.id=584;
Scope 范围参数值:0:memory;1:both;2:spfile;
sp_set_para_value(2,'COMPATIBLE_MODE',0);
控制文件内容:数据库名、数据库模式、OGUID 等、启动次数、启动时间、表空间信息(名
称、状态等)、数据库文件、数据文件扩展属性;
思考什么情况下会修改控制文件?
加表空间、修改表空间状态,加数据文件,修改数据文件的扩展属性等。
select * from DBA_TABLESPACES;
select * from v$tablespace;
select * from v$datafile;
select * from DBA_DATA_FILES;
创建表空间:
create tablespace tbs DATAFILE 'TBS01.DBF' SIZE 32;
修改数据库文件扩展属性
alter tablespace tbs datafile 'TBS01.DBF' AUTOEXTEND off;
添加数据文件
alter tablespace tbs add datafile 'TBS02.DBF' SIZE 32 AUTOEXTEND off;
修改数据文件大小
alter tablespace tbs Resize DATAFILE 'TBS01.DBF' to 128;
重命名表空间
alter tablespace tbs RENAME TO dmtbs;
alter tablespace tbs datafile '/dm8/data/TBS/TBS01.DBF' AUTOEXTEND on NEXT 4
MAXSIZE 10240;
alter tablespace tbs offline;
alter tablespace tbs RENAME DATAFILE 'TBS01.DBF' TO '/dm8/data/TBS/TBS01.DBF';
alter tablespace tbs RENAME DATAFILE 'TBS02.DBF' TO '/dm8/data/TBS/TBS02.DBF';
alter tablespace tbs online;
单位为M
Alter database add logfile ‘XXX’ size xx;–添加联机日志
Alter database resize logfile ‘XXX’ to xx; --修改联机日志大小
Alter database rename logfile ‘XXX’ to xx; --迁移联机日志
达梦的联机日志不支持手工切换,修改需要数据库在mount状态
select arch_mode from SYS."V$DATABASE";
select * from SYS."V$DM_ARCH_INI";
select * from v$arch_file;
alter database mount;
alter database ARCHIVELOG;
alter database add ARCHIVELOG 'type=local, dest=/dm8/arch,
file_size=64,space_limit=10240';
alter database open;
alter database mount;
alter database noARCHIVELOG;
alter database delete ARCHIVELOG 'type=local, dest=/dm8/arch,
file_size=64,space_limit=10240';
alter database open;
达梦归档日志文件由数据自动切换,也支持手工切换。
alter system SWITCH LOGFILE;
alter SYSTEM ARCHIVE LOG CURRENT;
alter DATABASE ARCHIVELOG CURRENT;
select * from v$ifun t where t.name like upper('sf_archive%');
SF_ARCHIVELOG_DELETE_BEFORE_LSN(3316220);
SF_ARCHIVELOG_DELETE_BEFORE_TIME(sysdate -10);
select * from SYS."V$PARAMETER" t where name ='PWD_POLICY';
alter system set 'PWD_POLICY' =31 BOTH;
select * from dba_users;
create user dmtest IDENTIFIED by Dameng123 PASSWORD_POLICY 15;
alter user DMTEST IDENTIFIED by "Dameng@123";
51
alter user dmtest DEFAULT TABLESPACE DMTBS DEFAULT INDEX TABLESPACE
TBSIDX;
用户资源限制:
alter user dmtest LIMIT FAILED_LOGIN_ATTEMPS 5 PASSWORD_LOCK_TIME 10;
select b.USERNAME, a.* from sysusers a, dba_users b where a.id= b.user_id;
新版本支持使用PROFILE(兼容oracle的方式管理用户资源):
select * from DBA_PROFILES;
create PROFILE profile1 LIMIT FAILED_LOGIN_ATTEMPS 5 PASSWORD_LOCK_TIME 5
SESSION_PER_USER 3;
alter user DMTEST PROFILE profile1;
用户:使用者在数据库系统中的身份
权限:数据库系统可以授予操作者的最小权力单位
角色:一组权限的集合
权限分类:系统权限和对象权限。
grant create table to dmtest;
grant update on dmhr.department to dmtest;
grant select on dmhr.department to dmtest;
grant select on dmhr.department to dmtest WITH GRANT OPTION;
revoke select on dmhr.department from dmtest;
revoke select on dmhr.department from dmtest CASCADE;
-- 撤销登录
revoke create SESSION from dmtest;
-- 当前登录用户权限
SELECT * FROM SESSION_PRIVS;
角色是一组权限的组合,使用角色的目的是使权限管理更加方便
系统默认的角色有:
DBA:几乎具有所有 DDL 和 DML 权限,但没有审计和强制访问控制权限。
RESOURCE:具有本模式下对象的 DDL 操作权限和 DML 操作权限。
PUBLIC:具有用户模式下表或视图的 DML 数据操作权限,及 user 开头的数据字典的权限。
VTI:具有 V$开头动态视图的查询权限
SOI: 有 SYS 开头系统数据字典的权限。
角色可以禁用,默认是启用状态,使用 SP_SET_ROLE 函数禁用。
create role r1;
grant create table to r1;
grant select (employee_id, employee_name) on dmhr.employee to r1;
grant r1 to dmtest;
revoke create table from r1;
revoke select on dmhr.employee from r1;
create table dmtest.t_testpid
(pid int,
pname varchar(20) not null ,
sex bit,
logdate date DEFAULT sysdate,
logtime time DEFAULT sysdate,
logdatetime datetime DEFAULT sysdate) tablespace DMTBS;
alter table dmtest.t_testpid add email VARCHAR(50);
alter table dmtest.t_testpid modify pname VARCHAR(50) not NULL;
insert into dmtest.t_testpid(pid, pname) values (1, 'aa');
alter table dmtest.t_testpid add email VARCHAR(50);
alter table dmtest.t_testpid modify pname VARCHAR(50) not NULL;
insert into dmtest.t_testpid(pid, pname) values (1, 'aa');
-- 从现有表创建,默认不带约束信息,由参数 CTAB_SEL_WITH_CONS指定
create table dmtest.t_emp as select * from dmhr.EMPLOYEE;
grant select on dmhr.EMPLOYEE to dmtest;
create table dmtest.t_emp as select * from dmhr.EMPLOYEE;
create table dmtest.t_emp01 as select * from dmhr.EMPLOYEE where 1=0;
create table dmtest.t_emp02 like dmhr.EMPLOYEE;
alter table t_testpid add CONSTRAINT pk_testpid PRIMARY KEY(pid);
alter table t_testpid add CONSTRAINT uk_testpid_pname UNIQUE(pname);
alter table t_testpid add CONSTRAINT uk_testpid_email UNIQUE(email,sex);
insert into dmtest.t_testpid(pid, pname, email, sex) values (2, 'bb', 'a',1);
58
insert into dmtest.t_testpid(pid, pname, email, sex) values (3, 'cc', 'a',0);
commit;
alter table "DMTEST"."T_TESTCHILD" add constraint "FK_TESTCHILD_PID"
foreign key("PID") references "DMTEST"."T_TESTPID"("PID");
alter table t_testpid add CONSTRAINT ck_testpid_logdatetime
CHECK(logdatetime >= '2020-01-01')
explain select * from t_test t where name like 'red%' order by name;
create index ix_test_name on t_test(name);
drop index ix_test_name;
--索引监控
alter index ix_test_name MONITORING USAGE;
alter index ix_test_name noMONITORING USAGE;
select * from SYS."V$OBJECT_USAGE";
select * from user_indexes;
select * from user_ind_columns;
--收集表的统计信息:
dbms_stats.gather_table_stats('SYSDBA','T_TEST01');
dbms_stats.table_stats_show('SYSDBA','T_TEST01');
联机备份需要数据库开启归档。
backup database;
backup database INCREMENT;
backup database to DMFULLBAK01 BACKUPSET '/dm8/backup/full/DMFULLBAK01';
select * from SYS."V$BACKUPSET";
select * from SYS."V$IFUN" t where t.name like '%BAKSET%';
SF_BAKSET_BACKUP_DIR_ADD('DISK','/dm8/backup/full/');
SF_BAKSET_BACKUP_DIR_ADD('DISK','/dm8/backup/incr/');
backup tablespace dmtbs;
backup tablespace dmtbs INCREMENT to DMTBSINCR01 BACKUPSET
'/dm8/backup/incr/DMTBSINCR01';
backup table dmtest.T_EMP;
backup ARCHIVE LOG all;
脱机备份可以使用dmrman、console图形工具
-- dmrman中
backup database '/dm8/data/DAMENG/dm.ini' to DMFULLBAK03 backupset '/dm8/backup/full/DMFULLBAK03';
show backupset '/dm8/backup/full/DMFULLBAK03';
remove backupset '/dm8/backup/full/DMFULLBAK03';
check backupset '/dm8/backup/full/DMFULLBAK03';
restore database '/dm8/data/DAMENG/dm.ini' tablespace dmtbs from backupset '/dm8/backup/full/DMFULLBAK03';
recover database '/dm8/data/DAMENG/dm.ini' tablespace dmtbs;
restore database '/dm8/data/DAMENG/dm.ini' from backupset '/dm8/backup/full/DMFULLBAK03';
recover database '/dm8/data/DAMENG/dm.ini' with archivedir '/dm8/arch';
recover database '/dm8/data/DAMENG/dm.ini' update db_magic;
### 逻辑备份
数据库迁移、历史数据归档、重新组织表、物理备份的辅助
逻辑导出包含四个级别:
Full=y 全库导出
Owner=XX 按用户导出
Schemas=XX 按模式导出
Tables=XX 导出指定的表
使用bin目录下的dimp、dexp工具
```shell
dimp help
全库导出:
dexp userid=sysdba/Dameng123:5238 directory=/dm8/backup/dexp file=full.dmp log=full.log
full=y
按用户导出:
按模式导出:
dexp userid=sysdba/Dameng123:5238 directory=/dm8/backup/dexp file=dmtest.dmp
log=dmtest.log schemas=DMTEST
按表导出:
[dmdba@KylinDCA04 dexp]$ dexp userid=sysdba/Dameng123:5238
directory=/dm8/backup/dexp file=dmtest_emp.dmp log=dmtest_emp.log tables=DMTEST.T_EMP
全库导入:
dimp userid=sysdba/Dameng123 directory=/dm8/backup/dexp file=full.dmp log=impfull.log
full=y
将 DMTEST 模式下 T_EMP 表导入到 HRTEST 用户下:
[dmdba@KylinDCA04 dexp]$ dimp userid=hrtest/Dameng123@127.0.0.1:5238
directory=/dm8/backup/dexp file=dmtest_emp.dmp log=dmtest_emp.log tables=DMTEST.T_EMP
remap_schema=DMTEST:HRTEST
manager图形化界面创建作业
select * from SYSJOB.SYSJOBS;
select * from SYSJOB.SYSJOBHISTORIES2;
select * from v$rlog; -- 6249919
select * from SYS."V$ARCH_FILE"; --6253052
dbms_job.run(1663922733);
DM8 JDBC 编程注意事项
// 定义 DM JDBC 驱动串
String jdbcString = “dm.jdbc.driver.DmDriver”;
// 定义 DM URL 连接串
String urlString = “jdbc:dm://localhost:5236”;
# root用户下
tar -xzvf unixODBC-2.3.0.tar.gz
./configure
make
make install
cd /usr/local/etc/
vim odbcinst.ini
vim odbc.ini
[DM8 ODBC DRIVER]
Description = ODBC DRIVER FOR DM8
Driver = /dm8/bin/libdodbc.so
[DM8]
Description = DM ODBC DSN
Driver = DM8 ODBC DRIVER
SERVER = localhost
UID = SYSDBA
PWD = Dameng123
TCP_PORT = 5238
# 切换dmdba用户
isql dm8 -v