– 以sysdba身份登陆PL/SQL
– 查询目前连接数
show parameter processes;
– 修改processes
alter system set processes=500 scope=spfile;
– 修改processes
alter system set sessions=555 scope=spfile;
– 重启Oracle服务或重启Oracle服务器
– 然后reboot数据库,使其生效
SQL> conn sys/密码 as sysdba
已连接。
SQL> show parameter memory
NAME TYPE VALUE
hi_shared_memory_address integer 0
memory_max_target big integer 6524M
memory_target big integer 6524M
shared_memory_address integer 0
alter system set memory_target = 8208M scope=spfile
alter system set memory_max_target =8192M scope=spfile;
以下不建议配置,有可能会导致不能启动数据库
alter system set sga_target=8192M scope=spfile;
alter system set sga_max_size=8192M scope=spfile;
改回:
alter system set memory_target = 1800M scope=spfile;
alter system set memory_max_target =1800M scope=spfile;
alter system set sga_target=1200M scope=spfile;
alter system set sga_max_size=1200M scope=spfile;
错误的修改了ORACLE 11g的memory参数之后,导致DB启动不起来
SQL> startup
ORA-00838: Specified value of MEMORY_TARGET is too small, needs to be at least 2080M
SQL> show parameter memory
NAME TYPE VALUE
hi_shared_memory_address integer 0
memory_max_target big integer 1584M
memory_target big integer 1584M
shared_memory_address integer 0
SQL> alter system set memory_target = 512M scope=spfile
SQL> alter system set memory_max_target =1024Mscope=spfile
解决方法如下:
SQL> CREATE PFILE FROM SPFILE;
MANUALLY EDIT PFILE & CORRECT MEMORY_TARGET VALUE
SQL> CREATE SPFILE FROM PFILE;
SQL> STARTUP
其中生成的PFILE (init.ora) 位于 $ORACLE_HOME/dbs folder. 修改这个 init.ora 文件。
或者在操作时,指定文件位置,如
create pfile=’’ from spfile ;
startup pfile=/dbs/init.ora
1,查看系统当前连接会话数
select s.value,s.sid,a.username
from
v
s
e
s
s
t
a
t
S
,
v
sesstat S,v
sesstatS,vstatname N,v$session A
where
n.statistic#=s.statistic# and
name=‘session pga memory’
and s.sid=a.sid
order by s.value;
2,等待最多的用户
SELECT s.SID, s.username, SUM (a.wait_time + a.time_waited) total_wait_time
FROM v
a
c
t
i
v
e
s
e
s
s
i
o
n
h
i
s
t
o
r
y
a
,
v
active_session_history a, v
activesessionhistorya,vsession s
WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE
GROUP BY s.SID, s.username
ORDER BY total_wait_time DESC;
3,查看死锁信息
SELECT (SELECT username
FROM v
s
e
s
s
i
o
n
W
H
E
R
E
S
I
D
=
a
.
S
I
D
)
b
l
o
c
k
e
r
,
a
.
S
I
D
,
′
i
s
b
l
o
c
k
i
n
g
′
,
(
S
E
L
E
C
T
u
s
e
r
n
a
m
e
F
R
O
M
v
session WHERE SID = a.SID) blocker, a.SID, 'is blocking', (SELECT username FROM v
sessionWHERESID=a.SID)blocker,a.SID,′isblocking′,(SELECTusernameFROMvsession
WHERE SID = b.SID) blockee, b.SID
FROM v
l
o
c
k
a
,
v
lock a, v
locka,vlock b
WHERE a.BLOCK = 1 AND b.request > 0 AND a.id1 = b.id1 AND a.id2 = b.id2;
4,找使用CPU多的用户session
select a.sid,spid,status,substr(a.program,1,40) prog, a.terminal,osuser,value/60/100 value
from v
s
e
s
s
i
o
n
a
,
v
session a,v
sessiona,vprocess b,v$sesstat c
where c.statistic#=12 and
c.sid=a.sid and
a.paddr=b.addr
order by value desc;
5,监控当前数据库谁在运行什么SQL语句
select osuser, username, sql_text
from v
s
e
s
s
i
o
n
a
,
v
session a, v
sessiona,vsqltext b
where a.sql_address =b.address order by address, piece;
6,查询表空间的使用情况
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 1;
7,查询表空间总容量
select tablespace_name, sum(bytes) / 1024 / 1024 as MB
from dba_data_files
group by tablespace_name;
8,查看表空间下的所有表
select table_name from all_tables where TABLESPACE_NAME=‘TS_SJXT’ //表空间要大写
9,查看表所在的表空间
select * from user_tables where table_name= ‘ORBIT_IMAGE’ / /表名要大写
在Oralce中我发现有add_months函数,加天数N可以用如下方法实现,select sysdate+N from dual
sysdate+1 加一天
sysdate+1/24 加1小时
sysdate+1/(2460) 加1分钟
sysdate+1/(2460*60) 加1秒钟
类推至毫秒0.001秒
加法
select sysdate,add_months(sysdate,12) from dual; --加1年
select sysdate,add_months(sysdate,1) from dual; --加1月
select sysdate,to_char(sysdate+7,‘yyyy-mm-dd HH24:MI:SS’) from dual; --加1星期
select sysdate,to_char(sysdate+1,‘yyyy-mm-dd HH24:MI:SS’) from dual; --加1天
select sysdate,to_char(sysdate+1/24,‘yyyy-mm-dd HH24:MI:SS’) from dual; --加1小时
select sysdate,to_char(sysdate+1/24/60,‘yyyy-mm-dd HH24:MI:SS’) from dual; --加1分钟
select sysdate,to_char(sysdate+1/24/60/60,‘yyyy-mm-dd HH24:MI:SS’) from dual; --加1秒
减法
select sysdate,add_months(sysdate,-12) from dual; --减1年
select sysdate,add_months(sysdate,-1) from dual; --减1月
select sysdate,to_char(sysdate-7,‘yyyy-mm-dd HH24:MI:SS’) from dual; --减1星期
select sysdate,to_char(sysdate-1,‘yyyy-mm-dd HH24:MI:SS’) from dual; --减1天
select sysdate,to_char(sysdate-1/24,‘yyyy-mm-dd HH24:MI:SS’) from dual; --减1小时
select sysdate,to_char(sysdate-1/24/60,‘yyyy-mm-dd HH24:MI:SS’) from dual; --减1分钟
select sysdate,to_char(sysdate-1/24/60/60,‘yyyy-mm-dd HH24:MI:SS’) from dual; --减1秒