温馨提示×

linux oracle如何启动服务

小樊
48
2026-10-10 08:30:03
栏目: 云计算

在 Linux 上启动 Oracle 数据库服务,通常是指启动 Oracle 实例(数据库) 和 监听(Listener)。下面按常见场景说明。


一、前提说明

  • Oracle 一般安装在 oracle 用户 下
  • 环境变量非常重要(ORACLE_SID、ORACLE_HOME)

二、切换到 oracle 用户

su - oracle

三、设置环境变量

export ORACLE_SID=orcl
export ORACLE_HOME=/u01/app/oracle/product/19.3.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH

orcl 替换为你的实际数据库名


四、启动监听(Listener)

lsnrctl start

查看状态:

lsnrctl status

五、启动数据库实例

sqlplus / as sysdba

进入 SQL*Plus 后:

startup;

正常输出类似:

ORACLE instance started.
Database mounted.
Database opened.

退出:

exit;

六、关闭数据库(备用)

shutdown immediate;

七、使用 dbstart(可选,推荐)

Oracle 提供脚本:

dbstart $ORACLE_HOME

需在 /etc/oratab 中设置为:

orcl:/u01/app/oracle/product/19.3.0/dbhome_1:Y

八、设置开机自启(Linux)

1️⃣ 修改 /etc/oratab

orcl:/u01/app/oracle/product/19.3.0/dbhome_1:Y

2️⃣ 设置系统服务(示例 systemd)

vi /etc/systemd/system/oracle.service

内容示例:

[Unit]
Description=Oracle Database
After=network.target

[Service]
User=oracle
Type=forking
ExecStart=/u01/app/oracle/product/19.3.0/dbhome_1/bin/dbstart /u01/app/oracle/product/19.3.0/dbhome_1
ExecStop=/u01/app/oracle/product/19.3.0/dbhome_1/bin/dbshut /u01/app/oracle/product/19.3.0/dbhome_1

[Install]
WantedBy=multi-user.target

启用:

systemctl enable oracle
systemctl start oracle

九、常见问题

❌ command not found → 环境变量没设置或没切到 oracle 用户

❌ ORA-01034 → 数据库没启动

❌ 监听启动但连不上 → 检查 listener.ora 和 tnsnames.ora


如果你告诉我:

  • Oracle 版本(11g / 12c / 19c)
  • Linux 发行版(CentOS / RHEL / Ubuntu)
  • 是否使用 CDB/PDB

我可以给你更精确的启动命令。

0 踩