创建表空间
登录数据库 disql SYSDBA/SYSDBA --检查数据库角色(mode$等于Primary的是主库) select name,instance_name,status$,mode$ from v$instance; --检查数据库打开状态(status$等于Open表示数据库已打开) select name,status$ from v$database;
达梦数据库中创建表空间时需要手动指定数据文件名称。
--检查已有用户和表空间 select username,default_tablespace from dba_users; --检查数据文件 select file_id,file_name,status, tablespace_name,bytes/1024/1024 as MB from dba_data_files;
注意:创建表空间的时候指定数据文件的目录位置一定要与文件中目录位置一致 /dm8/data/DAMENG
--创建表空间,需要指定数据文件(size单位是MB) create tablespace exam datafile '/dm8/data/DAMENG/EXAM_20230609_123015.DBF' size 1024 autoextend on maxsize 10240;
创建用户和授权
--创建用户并指定默认表空间 create user exam identified by "ABC123!BB" limit failed_login_attemps unlimited default tablespace exam default index tablespace exam; --检查用户是否创建成功 select username,default_tablespace from dba_users;
用户创建成功
其中,limit failed_login_attemps unlimited
表示不限制登录失败次数,可以防止由于登录失败次数过多导致账户被锁
用户授权
--授权(vti和soi角色包含对系统表和视图的查询权限) grant resource,public,vti,soi to exam; grant create session,admin job to exam; grant select on dba_data_files to exam; --查看权限 select grantee,privilege from dba_sys_privs where grantee='EXAM'; select grantee,owner,table_name,privilege from dba_tab_privs where grantee='EXAM'; select * from dba_role_privs where grantee='EXAM';
表空间扩容
alter tablespace exam add datafile '/dm8/data/DAMENG/EXAM_20230609_123020.DBF' size 1024 autoextend on maxsize 10240;
SELECT * FROM V$SESSION 查看会话和锁的信息 SELECT * FROM V$SESSION_WAIT 查看等待的会话信息 SELECT * FROM V$LOCK 系统中所有锁 SELECT * FROM V$LOCKED_OBJECT 系统中DML锁
SELECT "DEVICE_TYPE" "存储介质类型" , "BACKUP_ID" "备份ID" ,"BACKUP_NAME" "备份名" , "BACKUP_PATH" "备份路径" , CASE WHEN "TYPE" ='0' THEN '基备份' WHEN "TYPE"='1' THEN '增量备份' WHEN "TYPE"='2' THEN '表备份' WHEN "TYPE"='3' THEN '归档备份' END "备份类型" , CASE WHEN "LEVEL" ='0' THEN '联机备份' WHEN "LEVEL"='1' THEN '脱机备份' END "是否脱机备份", CASE WHEN "RANGE#"='1' THEN '库备份' WHEN "RANGE#"='2' THEN '表空间备份' WHEN "RANGE#"='3' THEN '表级备份' WHEN "RANGE#"='4' THEN '归档备份' END "备份类型" , "BASE_NAME" "基备份名" , "BACKUP_TIME" "备份时间" , "BEGIN_LSN" "备份的起始 LSN值" , "END_LSN" "结束备份的 LSN值" , "BKP_NUM" "备份片个数" , CASE WHEN ( SELECT SF_BAKSET_CHECK(DEVICE_TYPE, BACKUP_PATH) ) ='1' THEN '有效' WHEN ( SELECT SF_BAKSET_CHECK(DEVICE_TYPE, BACKUP_PATH) ) =0 THEN '无效' END "备份校验", 'SELECT SF_BAKSET_CHECK(' ||DEVICE_TYPE ||',' ||BACKUP_PATH||');' "校验命令" FROM V$BACKUPSET WHERE BACKUP_TIME>(SYSDATE-7); 会校验每个备份集,占用IO,慎用 作业信息 SELECT A.ID "作业ID号" , A.NAME "作业名称" , CASE WHEN A."ENABLE"='1' THEN '启用' WHEN A."ENABLE"='0' THEN '不启用' END "是否被启用", A.USERNAME "创建者名称" , A.CREATETIME "创建时间" , A.MODIFYTIME "最后一次被修改的时间" , A.DESCRIBE "作业描述" , B.LAST_DATE ||' ' ||B.LAST_SEC "最后一次运行时间", B.NEXT_DATE ||' ' ||B.NEXT_SEC "下一次运行时间", B.WHAT "执行任务的PL/SQL块" FROM SYSJOB.SYSJOBS A, SYSJOB.USER_JOBS B WHERE A.ID=B.JOB;