因为oracle 服务器占用资源比较大,所以 最好是需要的时候打开,不用的时候自动不启动
为此参照网上的教程写了下面的脚本
配置服务为手动.bat
sc config OracleRemExecServiceV2 start= DEMAND
sc config OracleOraDB12Home1TNSListener start= DEMAND
sc config OracleServiceORCL start= DEMAND
sc config OracleJobSchedulerORCL start= DEMAND
sc config OracleVssWriterORCL start= DEMAND
sc config OracleOraDB12Home1MTSRecoveryService start= DEMAND
一键启停oracle服务器.bat
@echo Restore The Service Start State Saved At 14:32:04.85 2022/02/24 周四
@echo off
title Oracle服务管理
cls
color 2f
goto MENU
:MENU
cls
@echo. =-=-=-=-=Oracle服务管理=-=-=-=-=
@echo.
@echo. 1 开启服务
@echo.
@echo. 2 关闭服务
@echo.
@echo. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
@echo. 请输入选择项目的序号:
set /p ID=
if "%id%"=="1" goto cmd1
if "%id%"=="2" goto cmd2
@echo 请输入正确序号!&ping -n 2 127.1>nul&goto MENU
:cmd1
@echo 开启Oracle服务中...
net Start OracleRemExecServiceV2
net Start OracleOraDB12Home1TNSListener
net Start OracleServiceORCL
net Start OracleJobSchedulerORCL
net Start OracleVssWriterORCL
net Start OracleOraDB12Home1MTSRecoveryService
@echo Oracle服务打开完成,按任意键退出...
@pause
exit
:cmd2
@echo 关闭Oracle服务中...
net stop OracleRemExecServiceV2
net stop OracleOraDB12Home1TNSListener
net stop OracleServiceORCL
net stop OracleJobSchedulerORCL
net stop OracleVssWriterORCL
net stop OracleOraDB12Home1MTSRecoveryService
@echo Oracle服务关闭完成,按任意键退出...
@pause
exit
但是 我因为测试不同的oralce 服务器版本,上面的oracle服务名称 每次会发生变化,然后还经常重装系统,所以每次去修改 上面脚本中的服务名称很麻烦
为此 我又 写了个脚本 来产生上面的脚本,可以适应任何的oralce服务器版本 比如10 ,11 ,10 免费版,oracle 12 ……..
产生oralce服务器一键启停脚本.bat
echo.
for /f "tokens=1, 2, 3, 4 delims=-/. " %%j in ('Date /T') do set FILENAME1=oracle服务设置为手动_%%j_%%k_%%l_%%m
for /f "tokens=1, 2 delims=: " %%j in ('TIME /T') do set FILENAME1=%FILENAME1%_%%j_%%k.bat
for /f "tokens=1, 2, 3, 4 delims=-/. " %%j in ('Date /T') do set FILENAME2=oracle服务一键启停_%%j_%%k_%%l_%%m
for /f "tokens=1, 2 delims=: " %%j in ('TIME /T') do set FILENAME2=%FILENAME2%_%%j_%%k.bat
sc query type= service state= all| findstr /r /C:"SERVICE_NAME: Oracle" >tmpsrv.txt
echo Save Service Start State In %FILENAME1%
echo @echo Restore The Service Start State Saved At %TIME% %DATE% >"%FILENAME1%"
echo Save Service Start State In %FILENAME2%
echo @echo Restore The Service Start State Saved At %TIME% %DATE% >"%FILENAME2%"
echo @echo off >>"%FILENAME2%"
echo title Oracle服务管理 >>"%FILENAME2%"
echo cls >>"%FILENAME2%"
echo color 2f >>"%FILENAME2%"
echo goto MENU >>"%FILENAME2%"
echo :MENU >>"%FILENAME2%"
echo cls >>"%FILENAME2%"
echo @echo. =-=-=-=-=Oracle服务管理=-=-=-=-= >>"%FILENAME2%"
echo @echo. >>"%FILENAME2%"
echo @echo. 1 开启服务 >>"%FILENAME2%"
echo @echo. >>"%FILENAME2%"
echo @echo. 2 关闭服务 >>"%FILENAME2%"
echo @echo. >>"%FILENAME2%"
echo @echo. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= >>"%FILENAME2%"
echo @echo. 请输入选择项目的序号: >>"%FILENAME2%"
echo set /p ID= >>"%FILENAME2%"
echo if "%%id%%"=="1" goto cmd1 >>"%FILENAME2%"
echo if "%%id%%"=="2" goto cmd2 >>"%FILENAME2%"
echo @echo 请输入正确序号!^&ping -n 2 127.1^>nul^&goto MENU >>"%FILENAME2%"
echo :cmd1 >>"%FILENAME2%"
echo @echo 开启Oracle服务中... >>"%FILENAME2%"
for /f "tokens=2 delims=:" %%j in (tmpsrv.txt) do @( sc qc %%j |findstr START_TYPE >tmpstype.txt && for /f "tokens=4 delims=:_ " %%s in ( tmpstype.txt) do @echo net Start %%j >>"%FILENAME2%")
echo @echo Oracle服务打开完成,按任意键退出... >>"%FILENAME2%"
echo @pause >>"%FILENAME2%"
echo exit >>"%FILENAME2%"
echo :cmd2 >>"%FILENAME2%"
echo @echo 关闭Oracle服务中... >>"%FILENAME2%"
for /f "tokens=2 delims=:" %%j in (tmpsrv.txt) do @( sc qc %%j |findstr START_TYPE >tmpstype.txt && for /f "tokens=4 delims=:_ " %%s in ( tmpstype.txt) do @echo sc config %%j start= DEMAND >>"%FILENAME1%")
echo @pause >>"%FILENAME1%"
for /f "tokens=2 delims=:" %%j in (tmpsrv.txt) do @( sc qc %%j |findstr START_TYPE >tmpstype.txt && for /f "tokens=4 delims=:_ " %%s in ( tmpstype.txt) do @echo net stop %%j >>"%FILENAME2%")
echo @echo Oracle服务关闭完成,按任意键退出... >>"%FILENAME2%"
echo @pause >>"%FILENAME2%"
echo exit >>"%FILENAME2%"
del tmpsrv.txt
del tmpstype.txt
cd ..
cd bat
总结:懒是人类进步最大的动力