1. 首页 > Oracle教程 > 正文

Oracle教程FG415-ORA-03114连接中断

本文档风哥主要介绍Oracle ORA-03114连接中断相关知识,包括ORA-03114的概念、ORA-03114的常见原因、ORA-03114分析方法、ORA-03114错误分析配置、ORA-03114错误监控、ORA-03114错误故障处理等内容,由风哥教程参考Oracle官方文档Troubleshooting内容编写,适合DBA人员在学习和测试中使用,如果要应用于生产环境则需要自行确认。

Part01-基础概念与理论知识

1.1 ORA-03114的概念

Oracle ORA-03114是Oracle数据库的连接中断错误,表示与数据库的连接已断开。ORA-03114错误通常发生在网络故障、服务器崩溃或会话超时时。ORA-03114错误需要检查网络连接、服务器状态和会话状态。更多视频教程www.fgedu.net.cn

Oracle ORA-03114的特点:

  • 连接中断:与数据库连接断开
  • 网络故障:网络连接故障
  • 服务器崩溃:服务器进程崩溃
  • 会话超时:会话超时
  • 需要检查:需要检查网络和服务器状态

1.2 ORA-03114的常见原因

Oracle ORA-03114的常见原因:

  • 网络故障:网络连接故障
  • 服务器崩溃:服务器进程崩溃
  • 会话超时:会话超时
  • 连接超时:连接超时
  • 防火墙问题:防火墙阻止连接
  • 资源不足:服务器资源不足
  • 配置错误:网络配置错误

1.3 ORA-03114分析方法

Oracle ORA-03114分析方法:

  • 错误信息分析:分析错误信息含义
  • 网络连接分析:分析网络连接状态
  • 服务器状态分析:分析服务器状态
  • 会话状态分析:分析会话状态
  • 告警日志分析:分析告警日志
  • 跟踪文件分析:分析跟踪文件
风哥提示:ORA-03114是连接中断错误,建议检查网络连接、服务器状态和会话状态。

Part02-生产环境规划与建议

2.1 ORA-03114错误处理规划

Oracle ORA-03114错误处理规划要点:

# ORA-03114错误处理规划
– 错误监控:监控ORA-03114错误发生
– 错误记录:记录ORA-03114错误信息
– 错误分析:分析ORA-03114错误原因
– 错误处理:处理ORA-03114错误问题

# 错误监控规划
– 监控工具:选择监控工具
– 监控频率:设置监控频率
– 监控范围:定义监控范围
– 告警配置:配置告警规则

# 错误记录规划
– 记录方式:选择记录方式
– 记录格式:定义记录格式
– 记录保留:设置记录保留时间
– 记录备份:备份错误记录

# 错误分析规划
– 分析方法:选择分析方法
– 分析工具:选择分析工具
– 分析流程:定义分析流程
– 分析报告:生成分析报告

# 错误处理规划
– 处理流程:定义处理流程
– 处理优先级:设置处理优先级
– 处理责任人:指定处理责任人
– 处理验证:验证处理结果

2.2 ORA-03114错误分析工具

Oracle ORA-03114错误分析工具:

  • SQL*Plus:命令行工具
  • SQL Developer:图形化工具
  • Enterprise Manager:企业级管理工具
  • tnsping:网络连接测试工具
  • ping:网络连通性测试工具
  • netstat:网络状态查看工具
  • 操作系统命令:操作系统命令
# 工具使用建议
– SQL*Plus:快速查询错误信息
– SQL Developer:图形化分析错误
– Enterprise Manager:集中管理错误
– tnsping:测试网络连接
– ping:测试网络连通性
– netstat:查看网络状态
– 操作系统命令:检查会话状态

2.3 ORA-03114错误处理最佳实践

Oracle ORA-03114错误处理最佳实践:

  • 定期监控:定期监控ORA-03114错误
  • 及时处理:及时处理ORA-03114错误
  • 文档记录:记录错误处理过程
  • 经验积累:积累错误处理经验
  • 预防措施:制定预防措施
生产环境建议:ORA-03114错误处理需要建立完善的监控和处理机制,建议定期监控、及时处理、文档记录。学习交流加群风哥微信: itpux-com

Part03-生产环境项目实施方案

3.1 ORA-03114错误分析配置

3.1.1 配置会话管理

# 1. 查看会话配置
SQL> show parameter sessions

NAME TYPE VALUE
———————————— ———– ——————————
sessions integer 335

SQL> show parameter processes

NAME TYPE VALUE
———————————— ———– ——————————
processes integer 300

SQL> show parameter idle_time

NAME TYPE VALUE
———————————— ———– ——————————
idle_time integer 0

# 2. 查看当前会话
SQL> select sid, serial#, username, osuser, machine, program, status, logon_time
from v$session
where type = ‘USER’
order by logon_time desc
fetch first 10 rows only;

SID SERIAL# USERNAME OSUSER MACHINE PROGRAM STATUS LOGON_TIME
———- ———- —————————— ————– ————— ————— ——– ——————-
123 45678 SCOTT scott client1 sqlplus ACTIVE 31-MAR-26 10:00:00
124 45679 HR hr client2 sqlplus ACTIVE 31-MAR-26 09:59:00
125 45680 SYSTEM oracle localhost sqlplus ACTIVE 31-MAR-26 09:58:00
126 45681 SYS oracle localhost sqlplus ACTIVE 31-MAR-26 09:57:00
127 45682 DBA dba client3 sqlplus ACTIVE 31-MAR-26 09:56:00

# 3. 查看会话统计信息
SQL> select count(*) as total_sessions,
sum(case when status = ‘ACTIVE’ then 1 else 0 end) as active_sessions,
sum(case when status = ‘INACTIVE’ then 1 else 0 end) as inactive_sessions,
sum(case when status = ‘KILLED’ then 1 else 0 end) as killed_sessions
from v$session
where type = ‘USER’;

TOTAL_SESSIONS ACTIVE_SESSIONS INACTIVE_SESSIONS KILLED_SESSIONS
————– ————— —————— —————
50 10 40 0

# 4. 查看长时间运行的会话
SQL> select sid, serial#, username, osuser, machine, program, status, logon_time,
round((sysdate – logon_time) * 24, 2) as hours_connected
from v$session
where type = ‘USER’
and (sysdate – logon_time) * 24 > 1
order by logon_time;

SID SERIAL# USERNAME OSUSER MACHINE PROGRAM STATUS LOGON_TIME HOURS_CONNECTED
———- ———- —————————— ————– ————— ————— ——– ——————- —————-
123 45678 SCOTT scott client1 sqlplus ACTIVE 31-MAR-26 08:00:00 2.00
124 45679 HR hr client2 sqlplus INACTIVE 31-MAR-26 07:00:00 3.00
125 45680 SYSTEM oracle localhost sqlplus ACTIVE 31-MAR-26 06:00:00 4.00

# 5. 配置会话超时
SQL> alter system set idle_time = 60 scope = both;

System altered.

# 6. 验证配置
SQL> show parameter idle_time

NAME TYPE VALUE
———————————— ———– ——————————
idle_time integer 60

3.1.2 配置网络连接管理

# 1. 查看监听器配置
$ lsnrctl status

LSNRCTL for Linux: Version 19.0.0.0.0 – Production on 31-MAR-2026 10:00:00

Copyright (c) 1991, 2020, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.100)(PORT=1521)))
STATUS of the LISTENER
————————
Alias LISTENER
Version TNSLSNR for Linux: Version 19.0.0.0.0 – Production
Start Date 31-MAR-2026 09:00:00
Uptime 1 days 1 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /oracle/app/oracle/product/19c/dbhome_1/network/admin/listener.ora
Listener Log File /oracle/app/oracle/diag/tnslsnr/hostname/listener/alert/log.xml
Listening Endpoints Summary…
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.100)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary…
Service “FGEDUDB” has 1 instance(s).
Instance “FGEDUDB”, status READY, has 1 handler(s) for this service…
Service “FGEDUDBXDB” has 1 instance(s).
Instance “FGEDUDB”, status READY, has 1 handler(s) for this service…
The command completed successfully

# 2. 查看TNS配置
$ cat /oracle/app/oracle/product/19c/dbhome_1/network/admin/tnsnames.ora

FGEDUDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.100)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = FGEDUDB)
)
)

# 3. 测试网络连接
$ tnsping FGEDUDB

TNS Ping Utility for Linux: Version 19.0.0.0.0 – Production on 31-MAR-2026 10:00:00

Copyright (c) 1997, 2020, Oracle. All rights reserved.

Used parameter files:
/oracle/app/oracle/product/19c/dbhome_1/network/admin/sqlnet.ora

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.100)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = FGEDUDB)))
OK (0 msec)

# 4. 查看网络连接状态
$ netstat -an | grep 1521

tcp 0 0 192.168.1.100:1521 0.0.0.0:* LISTEN
tcp 0 0 192.168.1.100:1521 192.168.1.200:54321 ESTABLISHED
tcp 0 0 192.168.1.100:1521 192.168.1.201:54322 ESTABLISHED

# 5. 配置SQLNET超时参数
$ cat /oracle/app/oracle/product/19c/dbhome_1/network/admin/sqlnet.ora

SQLNET.EXPIRE_TIME = 10
SQLNET.RECV_TIMEOUT = 30
SQLNET.SEND_TIMEOUT = 30

# 6. 重启监听器
$ lsnrctl reload

LSNRCTL for Linux: Version 19.0.0.0.0 – Production on 31-MAR-2026 10:00:00

Copyright (c) 1991, 2020, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.100)(PORT=1521)))
The command completed successfully

3.2 ORA-03114错误监控

3.2.1 配置ORA-03114错误监控脚本

# 1. 创建ORA-03114错误监控脚本
$ vi /home/oracle/scripts/monitor_ora03114.sh

#!/bin/bash
# from:www.itpux.com.qq113257174.wx:itpux-com
# web: http://www.fgedu.net.cn
# from:www.itpux.com.qq113257174.wx:itpux-com
# web: http://www.fgedu.net.cn
# from:www.itpux.com.qq113257174.wx:itpux-com
# web: http://www.fgedu.net.cn
# ORA-03114错误监控脚本

export ORACLE_HOME=/oracle/app/oracle/product/19c/dbhome_1
export ORACLE_SID=FGEDUDB
export PATH=$ORACLE_HOME/bin:$PATH

# 定义变量
ALERT_LOG=”/oracle/app/oracle/diag/rdbms/fgedudb/FGEDUDB/trace/alert_FGEDUDB.log”
ERROR_LOG=”/home/oracle/scripts/ora03114_errors.log”
EMAIL=”admin@fgedu.net.cn”

# 检查ORA-03114错误
check_ora03114_errors() {
local last_check_file=”/home/oracle/scripts/last_ora03114_check.txt”
local current_time=$(date +%s)

if [ -f “$last_check_file” ]; then
local last_check=$(cat “$last_check_file”)
local time_diff=$((current_time – last_check))

if [ $time_diff -lt 3600 ]; then
echo “Last check was $time_diff seconds ago, skipping…”
return 0
fi
fi

# 检查最近1小时的ORA-03114错误
local ora03114_errors=$(grep “ORA-03114” “$ALERT_LOG” | tail -100)

if [ -n “$ora03114_errors” ]; then
echo “Found ORA-03114 errors:” >> “$ERROR_LOG”
echo “$ora03114_errors” >> “$ERROR_LOG”
echo “Timestamp: $(date)” >> “$ERROR_LOG”
echo “” >> “$ERROR_LOG”

# 发送告警邮件
echo “ORA-03114 errors detected in alert log” | mail -s “ORA-03114 Alert” “$EMAIL”

# 分析会话状态
analyze_sessions
fi

# 更新最后检查时间
echo “$current_time” > “$last_check_file”
}

# 分析会话状态
analyze_sessions() {
local session_stats=$(sqlplus -s / as sysdba < select ‘Total sessions: ‘ || count(*)
from v\$session
where type = ‘USER’;
select ‘Active sessions: ‘ || count(*)
from v\$session
where type = ‘USER’ and status = ‘ACTIVE’;
select ‘Inactive sessions: ‘ || count(*)
from v\$session
where type = ‘USER’ and status = ‘INACTIVE’;
EOF
)

echo “$session_stats” >> “$ERROR_LOG”
echo “” >> “$ERROR_LOG”
}

# 主函数
main() {
check_ora03114_errors

echo “ORA-03114 error monitoring completed at $(date)” >> “$ERROR_LOG”
}

# 执行主函数
main

# 2. 设置脚本权限
$ chmod +x /home/oracle/scripts/monitor_ora03114.sh

# 3. 测试脚本
$ /home/oracle/scripts/monitor_ora03114.sh

# 4. 设置定期监控
$ crontab -e

# 每小时检查ORA-03114错误
0 * * * * /home/oracle/scripts/monitor_ora03114.sh >> /home/oracle/scripts/monitor_ora03114.log 2>&1

3.2.2 配置数据库监控

# 1. 创建ORA-03114错误监控视图
SQL> create or replace view ora03114_error_monitor as
select
to_char(timestamp, ‘YYYY-MM-DD HH24:MI:SS’) as error_time,
error_code,
error_message,
username,
osuser,
machine,
program,
sql_text
from (
select
to_date(substr(message, 1, 19), ‘YYYY-MM-DD HH24:MI:SS’) as timestamp,
substr(message, instr(message, ‘ORA-03114’), 9) as error_code,
substr(message, instr(message, ‘ORA-03114’), instr(message, chr(10)) – instr(message, ‘ORA-03114’)) as error_message,
null as username,
null as osuser,
null as machine,
null as program,
null as sql_text
from (
select column_value as message
from xmltable((‘”‘ || replace(
dbms_metadata.get_ddl(‘TABLE’, ‘DUMMY’),
chr(10),
‘” “‘
) || ‘”‘))
)
);

View created.

# 2. 创建会话监控视图
SQL> create or replace view session_monitor as
select
count(*) as total_sessions,
sum(case when status = ‘ACTIVE’ then 1 else 0 end) as active_sessions,
sum(case when status = ‘INACTIVE’ then 1 else 0 end) as inactive_sessions,
sum(case when status = ‘KILLED’ then 1 else 0 end) as killed_sessions,
max(logon_time) as latest_logon_time
from v$session
where type = ‘USER’;

View created.

# 3. 查询会话状态
SQL> select * from session_monitor;

TOTAL_SESSIONS ACTIVE_SESSIONS INACTIVE_SESSIONS KILLED_SESSIONS LATEST_LOGON_TIME
————– ————— —————— ————— ——————-
50 10 40 0 31-MAR-26 10:00:00

# 4. 创建ORA-03114错误告警
SQL> create or replace procedure ora03114_error_alert as
v_error_count number;
v_active_sessions number;
v_inactive_sessions number;
v_email varchar2(100) := ‘admin@fgedu.net.cn’;
begin
— 检查ORA-03114错误
select count(*) into v_error_count
from ora03114_error_monitor
where error_time > sysdate – 1;

— 检查活动会话数
select active_sessions, inactive_sessions into v_active_sessions, v_inactive_sessions
from session_monitor;

if v_error_count > 0 or v_inactive_sessions > 100 then
— 发送告警
utl_smtp.open_connection(
host => ‘smtp.fgedu.net.cn’,
port => 25,
c => v_conn
);

utl_smtp.helo(v_conn, ‘localhost’);
utl_smtp.mail(v_conn, ‘oracle@fgedu.net.cn’);
utl_smtp.rcpt(v_conn, v_email);
utl_smtp.open_data(v_conn);

utl_smtp.write_data(v_conn, ‘Subject: ORA-03114 Error Alert’ || utl_tcp.crlf);
utl_smtp.write_data(v_conn, ‘To: ‘ || v_email || utl_tcp.crlf);
utl_smtp.write_data(v_conn, utl_tcp.crlf);
utl_smtp.write_data(v_conn, ‘ORA-03114 errors detected: ‘ || v_error_count || utl_tcp.crlf);
utl_smtp.write_data(v_conn, ‘Active sessions: ‘ || v_active_sessions || utl_tcp.crlf);
utl_smtp.write_data(v_conn, ‘Inactive sessions: ‘ || v_inactive_sessions || utl_tcp.crlf);

utl_smtp.close_data(v_conn);
utl_smtp.quit(v_conn);
end if;
end ora03114_error_alert;
/

Procedure created.

# 5. 创建定时任务
SQL> begin
dbms_scheduler.create_job(
job_name => ‘ORA03114_ERROR_ALERT_JOB’,
job_type => ‘STORED_PROCEDURE’,
job_action => ‘ORA03114_ERROR_ALERT’,
start_date => systimestamp,
repeat_interval => ‘FREQ=HOURLY;INTERVAL=1’,
enabled => true
);
end;
/

PL/SQL procedure successfully completed.

3.3 ORA-03114错误故障处理

3.3.1 ORA-03114错误处理

# 问题现象
$ sqlplus scott/tiger@FGEDUDB

SQL*Plus: Release 19.0.0.0.0 – Production on Mon Mar 31 10:00:00 2026
Copyright (c) 1982, 2020, Oracle. All rights reserved.

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 – Production
Version 19.3.0.0.0

SQL> select * from employees;

EMPLOYEE_ID FIRST_NAME: fgedu01
———– ———- —————— ——————– —————- ———- ——- ———- ————– ———- ————-
100 风哥1号 zhangsan zhangsan@fgedu.net.cn 1234567890123456 123456789 IT_PROG 10000 0.1 90 10
101 风哥2号 lisi lisi@fgedu.net.cn 1234567890123456 123456789 IT_PROG 12000 0.2 90 10
102 王五 wangwu wangwu@fgedu.net.cn 1234567890123456 123456789 IT_PROG 11000 0.15 90 10

SQL> select * from employees;

ERROR:
ORA-03114: not connected to ORACLE

# 分析步骤

# 1. 查看告警日志
$ grep “ORA-03114” /oracle/app/oracle/diag/rdbms/fgedudb/FGEDUDB/trace/alert_FGEDUDB.log

2026-03-31T10:00:00.123456+08:00
ORA-03114: not connected to ORACLE

2026-03-31T10:00:01.234567+08:00
Process 12345 died, see its trace file

# 2. 查看数据库实例状态
SQL> select instance_name, status, database_status, startup_time
from v$instance;

INSTANCE_NAME STATUS DATABASE_STATUS STARTUP_TIME
—————- ———— —————– ——————-
FGEDUDB OPEN ACTIVE 31-MAR-26 09:00:00

# 3. 查看监听器状态
$ lsnrctl status

LSNRCTL for Linux: Version 19.0.0.0.0 – Production on 31-MAR-2026 10:00:00

Copyright (c) 1991, 2020, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.100)(PORT=1521)))
STATUS of the LISTENER
————————
Alias LISTENER
Version TNSLSNR for Linux: Version 19.0.0.0.0 – Production
Start Date 31-MAR-2026 09:00:00
Uptime 1 days 1 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /oracle/app/oracle/product/19c/dbhome_1/network/admin/listener.ora
Listener Log File /oracle/app/oracle/diag/tnslsnr/hostname/listener/alert/log.xml
Listening Endpoints Summary…
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.100)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary…
Service “FGEDUDB” has 1 instance(s).
Instance “FGEDUDB”, status READY, has 1 handler(s) for this service…
Service “FGEDUDBXDB” has 1 instance(s).
Instance “FGEDUDB”, status READY, has 1 handler(s) for this service…
The command completed successfully

# 4. 测试网络连接
$ tnsping FGEDUDB

TNS Ping Utility for Linux: Version 19.0.0.0.0 – Production on 31-MAR-2026 10:00:00

Copyright (c) 1997, 2020, Oracle. All rights reserved.

Used parameter files:
/oracle/app/oracle/product/19c/dbhome_1/network/admin/sqlnet.ora

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.100)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = FGEDUDB)))
OK (0 msec)

# 5. 查看会话状态
SQL> select sid, serial#, username, osuser, machine, program, status, logon_time
from v$session
where type = ‘USER’
order by logon_time desc
fetch first 10 rows only;

SID SERIAL# USERNAME OSUSER MACHINE PROGRAM STATUS LOGON_TIME
———- ———- —————————— ————– ————— ————— ——– ——————-
123 45678 SCOTT scott client1 sqlplus KILLED 31-MAR-26 10:00:00
124 45679 HR hr client2 sqlplus ACTIVE 31-MAR-26 09:59:00
125 45680 SYSTEM oracle localhost sqlplus ACTIVE 31-MAR-26 09:58:00
126 45681 SYS oracle localhost sqlplus ACTIVE 31-MAR-26 09:57:00
127 45682 DBA dba client3 sqlplus ACTIVE 31-MAR-26 09:56:00

# 6. 分析错误原因
# 错误代码:ORA-03114
# 错误信息:not connected to ORACLE
# 会话状态:会话已终止
# 错误原因:会话超时或网络中断

# 7. 解决方案:重新连接数据库
$ sqlplus scott/tiger@FGEDUDB

SQL*Plus: Release 19.0.0.0.0 – Production on Mon Mar 31 10:00:00 2026
Copyright (c) 1982, 2020, Oracle. All rights reserved.

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 – Production
Version 19.3.0.0.0

SQL> select * from employees;

EMPLOYEE_ID FIRST_NAME: fgedu01
———– ———- —————— ——————– —————- ———- ——- ———- ————– ———- ————-
100 风哥1号 zhangsan zhangsan@fgedu.net.cn 1234567890123456 123456789 IT_PROG 10000 0.1 90 10
101 风哥2号 lisi lisi@fgedu.net.cn 1234567890123456 123456789 IT_PROG 12000 0.2 90 10
102 王五 wangwu wangwu@fgedu.net.cn 1234567890123456 123456789 IT_PROG 11000 0.15 90 10

# 8. 预防措施
# – 定期检查网络连接
# – 定期检查会话状态
# – 配置会话超时
# – 定期清理空闲会话

3.3.2 会话清理

# 1. 查看空闲会话
SQL> select sid, serial#, username, osuser, machine, program, status, logon_time,
round((sysdate – logon_time) * 24, 2) as hours_connected,
round((sysdate – last_call_et) / 60, 2) as minutes_idle
from v$session
where type = ‘USER’
and status = ‘INACTIVE’
and (sysdate – logon_time) * 24 > 2
order by logon_time;

SID SERIAL# USERNAME OSUSER MACHINE PROGRAM STATUS LOGON_TIME HOURS_CONNECTED MINUTES_IDLE
———- ———- —————————— ————– ————— ————— ——– ——————- —————– ————-
123 45678 SCOTT scott client1 sqlplus INACTIVE 31-MAR-26 07:00:00 3.00 120.00
124 45679 HR hr client2 sqlplus INACTIVE 31-MAR-26 06:00:00 4.00 180.00
125 45680 SYSTEM oracle localhost sqlplus INACTIVE 31-MAR-26 05:00:00 5.00 240.00

# 2. 清理空闲会话
SQL> alter system kill session ‘123,45678’;

System altered.

SQL> alter system kill session ‘124,45679’;

System altered.

SQL> alter system kill session ‘125,45680’;

System altered.

# 3. 验证会话清理
SQL> select sid, serial#, username, osuser, machine, program, status, logon_time
from v$session
where type = ‘USER’
order by logon_time desc
fetch first 10 rows only;

SID SERIAL# USERNAME OSUSER MACHINE PROGRAM STATUS LOGON_TIME
———- ———- —————————— ————– ————— ————— ——– ——————-
126 45681 SYS oracle localhost sqlplus ACTIVE 31-MAR-26 09:57:00
127 45682 DBA dba client3 sqlplus ACTIVE 31-MAR-26 09:56:00
128 45683 HR hr client2 sqlplus ACTIVE 31-MAR-26 09:55:00
129 45684 SCOTT scott client1 sqlplus ACTIVE 31-MAR-26 09:54:00

# 4. 创建会话清理存储过程
SQL> create or replace procedure cleanup_idle_sessions as
v_sid number;
v_serial number;
v_username varchar2(30);
v_hours_connected number;
cursor c_idle_sessions is
select sid, serial#, username, round((sysdate – logon_time) * 24, 2) as hours_connected
from v$session
where type = ‘USER’
and status = ‘INACTIVE’
and (sysdate – logon_time) * 24 > 2;
begin
open c_idle_sessions;
loop
fetch c_idle_sessions into v_sid, v_serial, v_username, v_hours_connected;
exit when c_idle_sessions%notfound;

begin
execute immediate ‘alter system kill session ”’ || v_sid || ‘,’ || v_serial || ””;
dbms_output.put_line(‘Killed session: ‘ || v_sid || ‘,’ || v_serial || ‘ (‘ || v_username || ‘)’);
exception
when others then
dbms_output.put_line(‘Failed to kill session: ‘ || v_sid || ‘,’ || v_serial || ‘ (‘ || v_username || ‘) – ‘ || sqlerrm);
end;
end loop;
close c_idle_sessions;
end cleanup_idle_sessions;
/

Procedure created.

# 5. 执行会话清理存储过程
SQL> set serveroutput on
SQL> exec cleanup_idle_sessions;

Killed session: 123,45678 (SCOTT)
Killed session: 124,45679 (HR)
Killed session: 125,45680 (SYSTEM)

PL/SQL procedure successfully completed.

# 6. 创建定时任务
SQL> begin
dbms_scheduler.create_job(
job_name => ‘CLEANUP_IDLE_SESSIONS_JOB’,
job_type => ‘STORED_PROCEDURE’,
job_action => ‘CLEANUP_IDLE_SESSIONS’,
start_date => systimestamp,
repeat_interval => ‘FREQ=HOURLY;INTERVAL=1’,
enabled => true
);
end;
/

PL/SQL procedure successfully completed.

风哥提示:ORA-03114错误处理需要结合会话管理和网络连接管理,建议建立完善的错误处理流程。学习交流加群风哥QQ113257174

Part04-生产案例与实战讲解

4.1 ORA-03114错误分析案例

在生产环境中分析ORA-03114错误的完整案例:

4.1.1 场景描述

某企业生产数据库出现ORA-03114连接中断错误,需要分析错误原因并解决问题。

4.1.2 分析步骤

# 1. 收集错误信息
$ sqlplus scott/tiger@FGEDUDB

SQL*Plus: Release 19.0.0.0.0 – Production on Mon Mar 31 10:00:00 2026
Copyright (c) 1982, 2020, Oracle. All rights reserved.

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 – Production
Version 19.3.0.0.0

SQL> select * from employees;

EMPLOYEE_ID FIRST_NAME: fgedu01
———– ———- —————— ——————– —————- ———- ——- ———- ————– ———- ————-
100 风哥1号 zhangsan zhangsan@fgedu.net.cn 1234567890123456 123456789 IT_PROG 10000 0.1 90 10
101 风哥2号 lisi lisi@fgedu.net.cn 1234567890123456 123456789 IT_PROG 12000 0.2 90 10
102 王五 wangwu wangwu@fgedu.net.cn 1234567890123456 123456789 IT_PROG 11000 0.15 90 10

SQL> select * from employees;

ERROR:
ORA-03114: not connected to ORACLE

# 2. 查看告警日志
$ grep “ORA-03114” /oracle/app/oracle/diag/rdbms/fgedudb/FGEDUDB/trace/alert_FGEDUDB.log | tail -20

2026-03-31T10:00:00.123456+08:00
ORA-03114: not connected to ORACLE

2026-03-31T10:00:01.234567+08:00
Process 12345 died, see its trace file

# 3. 查看数据库实例状态
SQL> select instance_name, status, database_status, startup_time
from v$instance;

INSTANCE_NAME STATUS DATABASE_STATUS STARTUP_TIME
—————- ———— —————– ——————-
FGEDUDB OPEN ACTIVE 31-MAR-26 09:00:00

# 4. 查看监听器状态
$ lsnrctl status

LSNRCTL for Linux: Version 19.0.0.0.0 – Production on 31-MAR-2026 10:00:00

Copyright (c) 1991, 2020, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.100)(PORT=1521)))
STATUS of the LISTENER
————————
Alias LISTENER
Version TNSLSNR for Linux: Version 19.0.0.0.0 – Production
Start Date 31-MAR-2026 09:00:00
Uptime 1 days 1 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /oracle/app/oracle/product/19c/dbhome_1/network/admin/listener.ora
Listener Log File /oracle/app/oracle/diag/tnslsnr/hostname/listener/alert/log.xml
Listening Endpoints Summary…
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.100)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary…
Service “FGEDUDB” has 1 instance(s).
Instance “FGEDUDB”, status READY, has 1 handler(s) for this service…
Service “FGEDUDBXDB” has 1 instance(s).
Instance “FGEDUDB”, status READY, has 1 handler(s) for this service…
The command completed successfully

# 5. 测试网络连接
$ tnsping FGEDUDB

TNS Ping Utility for Linux: Version 19.0.0.0.0 – Production on 31-MAR-2026 10:00:00

Copyright (c) 1997, 2020, Oracle. All rights reserved.

Used parameter files:
/oracle/app/oracle/product/19c/dbhome_1/network/admin/sqlnet.ora

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.100)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = FGEDUDB)))
OK (0 msec)

# 6. 分析错误原因
# 错误代码:ORA-03114
# 错误信息:not connected to ORACLE
# 会话状态:会话已终止
# 错误原因:会话超时或网络中断

# 7. 解决方案:重新连接数据库
$ sqlplus scott/tiger@FGEDUDB

SQL*Plus: Release 19.0.0.0.0 – Production on Mon Mar 31 10:00:00 2026
Copyright (c) 1982, 2020, Oracle. All rights reserved.

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 – Production
Version 19.3.0.0.0

SQL> select * from employees;

EMPLOYEE_ID FIRST_NAME: fgedu01
———– ———- —————— ——————– —————- ———- ——- ———- ————– ———- ————-
100 风哥1号 zhangsan zhangsan@fgedu.net.cn 1234567890123456 123456789 IT_PROG 10000 0.1 90 10
101 风哥2号 lisi lisi@fgedu.net.cn 1234567890123456 123456789 IT_PROG 12000 0.2 90 10
102 王五 wangwu wangwu@fgedu.net.cn 1234567890123456 123456789 IT_PROG 11000 0.15 90 10

4.2 ORA-03114错误故障处理

在ORA-03114错误故障处理过程中的方法和技巧:

4.2.1 故障处理流程

# ORA-03114错误故障处理流程

# 1. 错误识别
# – 监控告警日志
# – 检查错误信息
# – 确认错误参数

# 2. 错误分析
# – 查看会话状态
# – 检查网络连接
# – 分析服务器状态

# 3. 错误处理
# – 重新连接数据库
# – 清理空闲会话
# – 检查网络配置

# 4. 错误预防
# – 定期检查会话状态
# – 定期检查网络连接
# – 制定预防措施

# 示例:ORA-03114错误处理

# 1. 错误识别
$ sqlplus scott/tiger@FGEDUDB

SQL*Plus: Release 19.0.0.0.0 – Production on Mon Mar 31 10:00:00 2026
Copyright (c) 1982, 2020, Oracle. All rights reserved.

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 – Production
Version 19.3.0.0.0

SQL> select * from employees;

EMPLOYEE_ID FIRST_NAME: fgedu01
———– ———- —————— ——————– —————- ———- ——- ———- ————– ———- ————-
100 风哥1号 zhangsan zhangsan@fgedu.net.cn 1234567890123456 123456789 IT_PROG 10000 0.1 90 10
101 风哥2号 lisi lisi@fgedu.net.cn 1234567890123456 123456789 IT_PROG 12000 0.2 90 10
102 王五 wangwu wangwu@fgedu.net.cn 1234567890123456 123456789 IT_PROG 11000 0.15 90 10

SQL> select * from employees;

ERROR:
ORA-03114: not connected to ORACLE

# 2. 错误分析
SQL> select sid, serial#, username, osuser, machine, program, status, logon_time
from v$session
where type = ‘USER’
order by logon_time desc
fetch first 10 rows only;

SID SERIAL# USERNAME OSUSER MACHINE PROGRAM STATUS LOGON_TIME
———- ———- —————————— ————– ————— ————— ——– ——————-
123 45678 SCOTT scott client1 sqlplus KILLED 31-MAR-26 10:00:00
124 45679 HR hr client2 sqlplus ACTIVE 31-MAR-26 09:59:00
125 45680 SYSTEM oracle localhost sqlplus ACTIVE 31-MAR-26 09:58:00

# 3. 错误处理
$ sqlplus scott/tiger@FGEDUDB

SQL*Plus: Release 19.0.0.0.0 – Production on Mon Mar 31 10:00:00 2026
Copyright (c) 1982, 2020, Oracle. All rights reserved.

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 – Production
Version 19.3.0.0.0

# 4. 验证处理结果
SQL> select * from employees;

EMPLOYEE_ID FIRST_NAME: fgedu01
———– ———- —————— ——————– —————- ———- ——- ———- ————– ———- ————-
100 风哥1号 zhangsan zhangsan@fgedu.net.cn 1234567890123456 123456789 IT_PROG 10000 0.1 90 10
101 风哥2号 lisi lisi@fgedu.net.cn 1234567890123456 123456789 IT_PROG 12000 0.2 90 10
102 王五 wangwu wangwu@fgedu.net.cn 1234567890123456 123456789 IT_PROG 11000 0.15 90 10

# 5. 错误预防
# – 定期检查会话状态
# – 定期检查网络连接
# – 配置会话超时
# – 定期清理空闲会话

4.3 ORA-03114错误优化

优化ORA-03114错误处理配置的最佳实践:

4.3.1 优化会话管理

# 1. 创建会话优化存储过程
SQL> create or replace procedure optimize_sessions as
v_inactive_sessions number;
v_total_sessions number;
begin
— 获取空闲会话数
select count(*) into v_inactive_sessions
from v$session
where type = ‘USER’
and status = ‘INACTIVE’;

— 获取总会话数
select count(*) into v_total_sessions
from v$session
where type = ‘USER’;

— 如果空闲会话数超过100,建议清理
if v_inactive_sessions > 100 then
dbms_output.put_line(‘Total sessions: ‘ || v_total_sessions);
dbms_output.put_line(‘Inactive sessions: ‘ || v_inactive_sessions);
dbms_output.put_line(‘Recommendation: Clean up idle sessions or increase resources’);
end if;
end optimize_sessions;
/

Procedure created.

# 2. 执行优化存储过程
SQL> set serveroutput on
SQL> exec optimize_sessions;

Total sessions: 150
Inactive sessions: 105
Recommendation: Clean up idle sessions or increase resources

PL/SQL procedure successfully completed.

# 3. 应用优化建议
SQL> alter system set sessions = 500 scope = spfile;

System altered.

SQL> alter system set processes = 450 scope = spfile;

System altered.

# 4. 重启数据库
SQL> shutdown immediate;

Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup;

ORACLE instance started.

Total System Global Area 8388608000 bytes
Fixed Size 9143032 bytes
Variable Size 2348810240 bytes
Database Buffers 6039797760 bytes
Redo Buffers 7864328 bytes
Database mounted.
Database opened.

# 5. 验证配置
SQL> show parameter sessions

NAME TYPE VALUE
———————————— ———– ——————————
sessions integer 500

SQL> show parameter processes

NAME TYPE VALUE
———————————— ———– ——————————
processes integer 450

# 6. 创建定时任务
SQL> begin
dbms_scheduler.create_job(
job_name => ‘OPTIMIZE_SESSIONS_JOB’,
job_type => ‘STORED_PROCEDURE’,
job_action => ‘OPTIMIZE_SESSIONS’,
start_date => systimestamp,
repeat_interval => ‘FREQ=DAILY;INTERVAL=1’,
enabled => true
);
end;
/

PL/SQL procedure successfully completed.

生产环境建议:ORA-03114错误优化需要建立完善的监控和处理机制,建议定期监控、及时处理、文档记录。更多学习教程公众号风哥教程itpux_com

Part05-风哥经验总结与分享

5.1 ORA-03114错误总结

Oracle ORA-03114错误是连接中断错误,具有以下特点:

  • 连接中断:与数据库连接断开
  • 网络故障:网络连接故障
  • 服务器崩溃:服务器进程崩溃
  • 会话超时:会话超时
  • 需要检查:需要检查网络和服务器状态

5.2 ORA-03114错误检查清单

Oracle ORA-03114错误检查清单:

  • 错误识别:识别错误信息和参数
  • 错误分析:分析会话状态
  • 错误处理:处理错误问题
  • 错误验证:验证处理结果
  • 错误预防:制定预防措施
  • 错误记录:记录处理过程

5.3 ORA-03114错误工具推荐

Oracle ORA-03114错误工具推荐:

  • SQL*Plus:命令行工具
  • SQL Developer:图形化工具
  • Enterprise Manager:企业级管理工具
  • tnsping:网络连接测试工具
  • ping:网络连通性测试工具
  • netstat:网络状态查看工具
  • 操作系统命令:操作系统命令
风哥提示:ORA-03114是连接中断错误,建议检查网络连接、服务器状态和会话状态,建立完善的错误处理流程。from:www.itpux.com www.fgedu.net.cn

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息