配置文件
oracle参数配置文件路径
/database/oracle/product/rdbms/11.2.0/dbs
# 要确定服务器中环境变量的$ORACLE_HOME
用户的操作
只查询用户
select username from dba_users;
查看所有表
select table_name from dba_tables;
查看表在哪个用户下
select owner,table_name from dba_tables where table_name=‘表名’
强制删除用户
alter user paasadmin account lock;
select sid,serial# from v$session where username='paasadmin';#以paasadmin为例
shut immediate
startup
drop user paasadmin cascade
删除表空间
drop tablespace PAAS_INDEX including contents and datafiles;
修改oracle数据库的内存
修改sga和shared_pool,修改之前必须备份数据库spfile配置文件
alter system set memory_max_target='8000m' scope=spfile;
alter system set memory_target='4000m' scope=spfile;
alter system set sga_target='2500m' scope=spfile;
alter system set shared_pool_size='2000m' scope=spfile;
修改用户密码
alter user BESDBA identified by 密码 account unlock;
表的删除操作
drop tablespace TBS_PROVISION_DEF including datafiles; 删除空表
drop tablespace TBS_PROVISION_I01 including contents and datafiles; 删除有数据的表
实例检查脚本
#!/bin/bash
sqlplus / as sysdba << EOF
@/home/oracle/lcj.sh
EOF
set serveroutput on;
declare
db_status varchar2(20);
a varchar2(30) :='OPEN';
begin
select status into db_status
from v$instance;
if(db_status = a)
then
dbms_output.put_line('192.168.126.117:OPEN');
else dbms_output.put_line('192.168.126.117:ERROR');
end if;
end;
查看表空间
select tablespace_name,file_name,bytes/1024/1024 M from dba_data_files where tablespace_name='TBS_BPM_DAT';
表空间的操作
创建表空间
create tablespace IMUSE01
datafile '/export/home/oracle/oradata/mdspdata/imuse01_dat1'
size 100M;
增加表空间的大小
如将表空间IMUSE01增加100M:
alter tablespace IMUSE01
add datafile '/export/home/oracle/oradata/mdspdata/imuse01_dat2'
size 100M;
修改表空间的大小
如将表空间IMUSE01改为1000M:
alter database
datafile '/export/home/oracle/oradata/mdspdata/imuse01_dat1'
resize 1000M;
删除表空间
drop tablespace imuse01 cascade;
drop tablespace ZAIN_MIDDLE_DATA including contents and datafiles cascade constraints;
查看用户表
select * from user_tables;
查看表空间的名称及大小
select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size
from dba_tablespaces t, dba_data_files d
where t.tablespace_name = d.tablespace_name
group by t.tablespace_name;
查看表空间物理文件的名称及大小
select tablespace_name, file_id, file_name,
round(bytes/(1024*1024),0) total_space
from dba_data_files
order by tablespace_name;
表空间使用率
按照M统计
SELECT D.TABLESPACE_NAME "Name", D.STATUS "Status",
TO_CHAR((A.BYTES / 1024 / 1024), '999,990.9') "Size (M)",
TO_CHAR(((A.BYTES - DECODE(F.BYTES, NULL, 0, F.BYTES)) / 1024 /
1024),'9999,990.9') "Used (M)", TO_CHAR((DECODE(F.BYTES, NULL, 0, F.BYTES)
/ 1024 / 1024),'9999,990.9') "Free (M)" ,TO_CHAR(F.BYTES/A.BYTES*100,'9999,990.9') "FREE%"
FROM SYS.DBA_TABLESPACES D, SYS.SM$TS_AVAIL A, SYS.SM$TS_FREE F
WHERE D.TABLESPACE_NAME = A.TABLESPACE_NAME
AND F.TABLESPACE_NAME (+) = D.TABLESPACE_NAME order by 6 ;
按照G统计:
SELECT A.TABLESPACE_NAME "表空间名称",
100 - ROUND((NVL(B.BYTES_FREE, 0) / A.BYTES_ALLOC) * 100, 2) || '%' "使用率(%)",
ROUND(NVL(B.BYTES_FREE, 0) / 1024 / 1024 / 1024, 2) "空闲(G)",
ROUND(A.BYTES_ALLOC / 1024 / 1024 / 1024, 2) "容量(G)",
ROUND((A.BYTES_ALLOC - NVL(B.BYTES_FREE, 0)) / 1024 / 1024 / 1024, 2) "使用(G)",
ROUND((NVL(B.BYTES_FREE, 0) / A.BYTES_ALLOC) * 100, 2) "空闲率(%)",
TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') "采样时间"
FROM (SELECT F.TABLESPACE_NAME, SUM(F.BYTES) BYTES_ALLOC
FROM DBA_DATA_FILES F
GROUP BY TABLESPACE_NAME) A,
(SELECT F.TABLESPACE_NAME, SUM(F.BYTES) BYTES_FREE
FROM DBA_FREE_SPACE F
GROUP BY TABLESPACE_NAME) B
WHERE A.TABLESPACE_NAME = B.TABLESPACE_NAME(+);
SELECT A.TABLESPACE_NAME "TABLESPACE",
100 - ROUND((NVL(B.BYTES_FREE, 0) / A.BYTES_ALLOC) * 100, 2) || '%' "USAGE PERCENTS(%)",
ROUND(NVL(B.BYTES_FREE, 0) / 1024 / 1024 / 1024, 2) "FREE SPACE(G)",
ROUND(A.BYTES_ALLOC / 1024 / 1024 / 1024, 2) "TOTAL SPACE(G)",
ROUND((A.BYTES_ALLOC - NVL(B.BYTES_FREE, 0)) / 1024 / 1024 / 1024, 2) "USAGE SPACE(G)",
ROUND((NVL(B.BYTES_FREE, 0) / A.BYTES_ALLOC) * 100, 2) "FREE PERCENTS(%)",
TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') "CHECK TIME"
FROM (SELECT F.TABLESPACE_NAME, SUM(F.BYTES) BYTES_ALLOC
FROM DBA_DATA_FILES F
GROUP BY TABLESPACE_NAME) A,
(SELECT F.TABLESPACE_NAME, SUM(F.BYTES) BYTES_FREE
FROM DBA_FREE_SPACE F
GROUP BY TABLESPACE_NAME) B
WHERE A.TABLESPACE_NAME = B.TABLESPACE_NAME(+);
一些命令
1.给某个表添加主键: alter table t_check_wk add( constraint acount_no primary key(acount_no))
2.删除某个表的主键:alter table t_temp_wk drop constraint ACOUNT_NO
3.重命名某个字段:ALTER TABLE 表名 RENAME COLUMN 原字段名 TO 新字段名 ;
4.添加字段的语法:alter table tablename add (column datatype [default value][null/not null],….);
5.修改字段的语法:alter table tablename modify (column datatype [default value][null/not null],….);
6.删除字段的语法:alter table tablename drop (column);
7.重命名表名:ALTER TABLE table_name RENAME TO new_table_name;
8.创建带主键的表:create table student ( studentid int primary key not null, studentname varchar(8), age int);
添加list的BE_ID分区:
alter table MM_WK_TASK_WORKBENCH add partition P_L_11 values(11) tablespace D_CUST_01;
添加range-list的BE_ID子分区:
alter table SUBS.INF_GRP_APNIPLIST_HIS_CZ modify partition P_R_201604 add subpartition P_R_201604_L_11 values(11) tablespace D_LOG_01 NOCOMPRESS;
从max分区中拆月分区
ALTER TABLE OM_BATCH_TASKDETAIL SPLIT PARTITION P_R_PMAX at (TO_DATE(' 2016-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) INTO (PARTITION P_R_201611, PARTITION P_R_PMAX)
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
alter profile default limit failed_login_attempts unlimited;