新装数据库常规操作
新安装数据库,导完数据后的常规操作,能避免后期使用可能发生的问题
数据库日志路径查询
select name,value from v$diag_info;
确保数据库对象完整
以 TESTUSER 用户为例
从新库建个dblink连接老库
CREATE PUBLIC DATABASE LINK OLDORCL CONNECT TO TESTUSER IDENTIFIED BY xxxx USING 'ORCL';
新库的对象数
select object_type,count(1) from dba_objects where owner='TESTUSER' group by object_type order by object_type;
旧库的对象数
select object_type,count(1) from dba_objects@OLDORCL where owner='TESTUSER' group by object_type order by object_type;
看漏了哪些索引(其他类型的对象也得检查)
select OBJECT_NAME from dba_objects@OLDORCL where owner='TESTUSER' and object_type='INDEX'
minus
select OBJECT_NAME from dba_objects where owner='TESTUSER' and object_type='INDEX';
在旧库生成创建对象的SQL
set line 1000
set linesize 256
set pagesize 9999
set long 999999
set heading off
select dbms_metadata.get_DDL('INDEX','IDX_SUBS_SUBSCRIBER_ACCTID','TESTUSER') from dual ;
统计信息更新
避免统计信息不准确,导致生成SQL的执行计划错误,造成全表扫描等消耗资源的问题
对用户进行统计信息更新
exec dbms_stats.gather_schema_stats(ownname => 'TESTUSER',estimate_percent => dbms_stats.auto_sample_size);
对某个表进行统计信息更新
EXEC DBMS_STATS.GATHER_TABLE_STATS(OWNNAME=>'TESTUSER',TABNAME=>'TESTTABLE',ESTIMATE_PERCENT=>10);
增加redo表空间
安装完数据库后默认的redo表空间偏小,调大redo表空间,能减少IO次数,通过批量写数据提高性能
查看redo的组和大小
select * from v$log ;
查看redo的数据文件
select * from v$logfile ;
增加日志日志组(路径更加实际情况调整)
ALTER DATABASE ADD LOGFILE GROUP 4 ('/data/oracle/oradata/ORCL/redo04.log') SIZE 8G;
ALTER DATABASE ADD LOGFILE GROUP 5 ('/data/oracle/oradata/ORCL/redo05.log') SIZE 8G;
ALTER DATABASE ADD LOGFILE GROUP 6 ('/data/oracle/oradata/ORCL/redo06.log') SIZE 8G;
切换日志组
alter system switch logfile;
查看redo的组
select * from v$log ;
例子
ALTER DATABASE ADD LOGFILE GROUP 4 ('/orasysdata/redo04.log') SIZE 16G;
ALTER DATABASE ADD LOGFILE GROUP 5 ('/orasysdata/redo05.log') SIZE 16G;
ALTER DATABASE ADD LOGFILE GROUP 6 ('/orasysdata/redo06.log') SIZE 16G;
ALTER DATABASE DROP LOGFILE GROUP 1;
ALTER DATABASE DROP LOGFILE GROUP 2;
ALTER DATABASE DROP LOGFILE GROUP 3;
ALTER DATABASE ADD LOGFILE GROUP 1 ('/orasysdata/redo01.log') SIZE 16G;
ALTER DATABASE ADD LOGFILE GROUP 2 ('/orasysdata/redo02.log') SIZE 16G;
ALTER DATABASE ADD LOGFILE GROUP 3 ('/orasysdata/redo03.log') SIZE 16G;
创建普通表空间
create tablespace DATA_SPACE datafile '/oracle/datafile/DATA_SPACE_01.dbf' size 24G;
alter tablespace DATA_SPACE add datafile '/oracle/datafile/DATA_SPACE_02.dbf' size 24G;
temp 表空间
说明
temp临时表空间,用于排序和存储临时表
字典
select * from dba_temp_files;
select * from v$tempfile;
操作例子
alter tablespace TEMP add tempfile '/orasysdata/temp01.dbf' size 16G;
alter tablespace TEMP add tempfile '/orasysdata/temp02.dbf' size 16G;
alter tablespace TEMP add tempfile '/orasysdata/temp03.dbf' size 16G;
alter tablespace TEMP add tempfile '/orasysdata/temp04.dbf' size 16G;
alter tablespace TEMP drop tempfile '/oracle/app/oracle/oradata/ORCL/temp01.dbf';
undo表空间
说明
用于回滚、闪回查询等
字典
dba_data_files
例子
alter tablespace UNDOTBS1 add datafile '/oracle/app/oracle/oradata/ORCL/undotbs02.dbf' size 16G reuse autoextend on next 400m maxsize unlimited;
关审计
默认情况审计是开着的,会消耗cpu,随之时间推移会占用大量的系统表空间,一直到耗尽后报错
show parameter audit_trail
VALUE 是 DB 表示开着的
alter system set audit_sys_operations=FALSE scope=spfile;
alter system set audit_trail=none scope=spfile;
重启数据库
清理旧审计数据:
truncate table aud$;
密码策略
不安全,但对测试环境来说很实用
查看用户的PROFILE,一般是DEFAULT
SELECT username,PROFILE FROM dba_users where username='TESTUSER';
密码永不过期
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
可无限次输错密码
ALTER PROFILE DEFAULT LIMIT FAILED_LOGIN_ATTEMPTS UNLIMITED;
加大连接数
查连接数配置
show parameter processes
show parameter sessions
查目录已经有多少连接
select count(1) from v$process;
select count(1) from v$session;
设置连接数
alter system set processes=2000 scope=spfile;
alter system set sessions=5000 scope=spfile;
重启数据库
impdp导数前建好dblink,因为物化视图依赖它
在新数据库的tnsname.org里加上ORCL的配置
CREATE PUBLIC DATABASE LINK ORCL_LINK CONNECT TO TESTUSER IDENTIFIED BY TESTUSER USING 'ORCL';
支持低版本客户端
在 $ORACLE_HOME/network/admin/sqlnet.ora 里添加以下内容:
SQLNET.ALLOWED_LOGON_VERSION_CLIENT=8
SQLNET.ALLOWED_LOGON_VERSION_SERVER=8
查询表空间使用情况
SELECT UPPER(F.TABLESPACE_NAME) "表空间名",
D.TOT_GROOTTE_MB "表空间大小(M)",
D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)",
TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100, 2),'990.99') "使用比",
F.TOTAL_BYTES "空闲空间(M)",
F.MAX_BYTES "最大块(M)"
FROM (SELECT TABLESPACE_NAME,
ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES,
ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES
FROM SYS.DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) F,
(SELECT DD.TABLESPACE_NAME,
ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB
FROM SYS.DBA_DATA_FILES DD
GROUP BY DD.TABLESPACE_NAME) D
WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME
ORDER BY 4 DESC;
查询表空间文件位置
select * from dba_data_files;
扩充表空间
alter tablespace TABLESPACE_NAME add datafile '/oracle/app/oracle/oradata/CRCL/tablespace_name02.dbf' size 31G;
- 点赞
- 收藏
- 关注作者
评论(0)