当前位置: 首页 > article >正文

windows平台上 oracle简单操作手册

一 环境描述

Oracle 11g单机环境

二 基本操作

2.1 数据库的启动与停止

启动:
C:\Users\Administrator>sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on 星期五 7月 31 12:19:51 2020
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
连接到:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
停止:
SQL> shutdown immediate
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。

点击开始-管理工具-服务
image.png
数据库以及监听运行服务
image.png

2.2 监听的启动与停止

C:\Users\Administrator>lsnrctl start
C:\Users\Administrator>lsnrctl stop

C:\Users\Administrator>lsnrctl status   //查看状态
LSNRCTL for 64-bit Windows: Version 11.2.0.4.0 - Production on 31-7月 -2020 14:0
0:46
Copyright (c) 1991, 2013, Oracle.  All rights reserved.
正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=WIN-D30A3J59LLL.lan)(PORT=1
521)))
LISTENER 的 STATUS
------------------------
别名                      LISTENER
版本                      TNSLSNR for 64-bit Windows: Version 11.2.0.4.0 - Produ
ction
启动日期                  31-7月 -2020 13:54:16
正常运行时间              0 天 0 小时 6 分 34 秒
跟踪级别                  off
安全性                    ON: Local OS Authentication
SNMP                     OFF
监听程序参数文件          C:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN\listener.ora
监听程序日志文件          
C:\app\Administrator\diag\tnslsnr\WIN-D30A3J59LLL\listener\alert\log.xml
监听端点概要...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=WIN-D30A3J59LLL)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
服务摘要..
服务 "CLRExtProc" 包含 1 个实例。
  实例 "CLRExtProc", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
服务 "orcl" 包含 1 个实例。
  实例 "orcl", 状态 READY, 包含此服务的 1 个处理程序...
服务 "orclXDB" 包含 1 个实例。
  实例 "orcl", 状态 READY, 包含此服务的 1 个处理程序...
命令执行成功

2.3 如何连接数据库

(包括如何设置环境变量,如何连接,如何查看监听服务)
(1)临时指定变量ORACLE_SID

C:\Users\Administrator>set ORACLE_SID=orcl
C:\Users\Administrator>set ORACLE_SID
ORACLE_SID=orcl
连接
C:\Users\Administrator>sqlplus / as sysdba

查询连接信息

SQL> select instance_name,status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
orcl             OPEN

SQL> select name from v$database;

NAME
---------
ORCL

(2)设置系统变量

找到计算机-右键-点击属性
image.png
点击高级系统设置:
image.png
选择高级-环境变量
image.png
点击新建:
image.png
点击确定
查看:
C:\Users\Administrator>set ORACLE_SID
ORACLE_SID=orcl
连接
C:\Users\Administrator>sqlplus / as sysdba

2.4 用户与表空间的创建

创建用户:

SYS@orcl11g> CREATE USER user01 
 IDENTIFIED BY user01      --创建密码
 DEFAULT TABLESPACE users  --创建用户使用默认的表空间
 TEMPORARY TABLESPACE temp --指定用户默认使用的临时表空间

创建表空间:

SQL> create tablespace tbs01
datafile '/u01/app/oracle/oradata/orcl11g/tbs01.dbf' 
size 1G
autoextend on 

向表空间中添加数据文件:

SQL> alter tablespace tbs01
add datafile '/u01/app/oracle/oradata/orcl11g/tbs02.dbf'
size 1G 
autoextend on

2.5 查看操作系统日志、数据库日志

(1)查看操作系统日志:
开始-管理工具-事件查看器
image.png
(2)数据库警告日志位置:
$ORACLE_BASE\diag\rdbms\orcl\orcl\trace
C:\app\Administrator\diag\rdbms\orcl\orcl\trace
image.png

2.5 windows清理监听日志

(1)清理监听日志:

找到存放位置
C:\app\Administrator\diag\tnslsnr\WIN-D30A3J59LLL\listener\trace\listener

清理监听日志:
C:\Users\Administrator>cd C:\app\Administrator\diag\tnslsnr\ WIN-D30A3J59LLL \listener\trace
C:\Users\Administrator>echo “ “ > listener.log

(2)关闭监听日志写功能:

C:\Users\Administrator>lsnrctl
LSNRCTL for 64-bit Windows: Version 11.2.0.4.0 - Production on 31-7月 -2020 14:3
6:14

Copyright (c) 1991, 2013, Oracle.  All rights reserved.
欢迎来到LSNRCTL, 请键入"help"以获得信息。

LSNRCTL> set log_status off
正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=WIN-D30A3J59LLL.lan)(PORT=1521)))
LISTENER 参数 "log_status" 设为 OFF
命令执行成功

LSNRCTL> save_config
正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=WIN-D30A3J59LLL.lan)(PORT=1521)))
保存的LISTENER配置参数。
监听程序参数文件          C:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\A
DMIN\listener.ora
旧的参数文件C:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN\listener.
bak
命令执行成功

再次查看监听状态:

C:\Users\Administrator>lsnrctl status
LSNRCTL for 64-bit Windows: Version 11.2.0.4.0 - Production on 31-7月 -2020 14:
8:18
Copyright (c) 1991, 2013, Oracle.  All rights reserved.
正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=WIN-D30A3J59LLL.lan)(PORT=1521)))
LISTENER 的 STATUS
------------------------
别名                      LISTENER
版本                      TNSLSNR for 64-bit Windows: Version 11.2.0.4.0 - Prod
ction
启动日期                  31-7月 -2020 13:54:16
正常运行时间              0 天 0 小时 44 分 6 秒
跟踪级别                  off
安全性                    ON: Local OS Authentication
SNMP                     OFF
监听程序参数文件          C:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\
DMIN\listener.ora
监听端点概要...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=WIN-D30A3J59LLL)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
服务摘要..
服务 "CLRExtProc" 包含 1 个实例。
  实例 "CLRExtProc", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
服务 "orcl" 包含 1 个实例。
  实例 "orcl", 状态 READY, 包含此服务的 1 个处理程序...
服务 "orclXDB" 包含 1 个实例。
  实例 "orcl", 状态 READY, 包含此服务的 1 个处理程序...
命令执行成功
//已无日志文件显示

2.6 查看windows系统资源使用

任务管理器
image.png

image.png
点击资源监视器查看其他资源信息
image.png

2.7 日常维护命令

性能查看:

查看等待事件:
SYS@prod>select event,count(*) from gv$session_wait where wait_class<>'Idle' group by event;

查看资源使用情况:
SYS@prod>select * from v$resource_limit;

表空间使用率查看

col tablespace_name format a8
 col status format a7
 col extent_management format a5
 col segment_space_management format a6
 col contents format a9
 select tpsname,status,mgr,maxsize,c_userd,max_used  from 
         (
 SELECT  d.tablespace_name  tpsname,d.status status,
         d.segment_space_management mgr, d.contents type,
         TO_CHAR(NVL(trunc(A.maxbytes / 1024 / 1024), 0),'99G999G990') maxsize,
         TO_CHAR(NVL((a.bytes - NVL(f.bytes, 0)) / a.bytes * 100, 0),'990D00') c_userd,
         TO_CHAR(NVL((a.bytes - NVL(f.bytes, 0)) / a.maxbytes * 100, 0),'990D00') max_used
         FROM sys.dba_tablespaces d,
         (SELECT tablespace_name,sum(bytes) bytes,SUM(case autoextensible when  'NO'  then BYTES when  'YES' then MAXBYTES else null end ) maxbytes   
         FROM dba_data_files  GROUP BY tablespace_name) a,
         (SELECT tablespace_name,SUM(bytes) bytes, MAX(bytes) largest_free   FROM dba_free_space   GROUP BY tablespace_name) f  
         WHERE d.tablespace_name = a.tablespace_name   AND d.tablespace_name = f.tablespace_name(+)
         )
         where max_used>0
     order by max_used desc;

MAX_USED列不要超过百分之90

2.8获取AWR报告

SQL> @?/rdbms/admin/awrrpt.sql

Current Instance
~~~~~~~~~~~~~~~~

   DB Id    DB Name      Inst Num Instance
----------- ------------ -------- ------------
 1574596224 ORCL                1 orcl

Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
Would you like an HTML report, or a plain text report?
Enter 'html' for an HTML report, or 'text' for plain text
Defaults to 'html'
输入 report_type 的值:  html

Type Specified:  html

Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   DB Id     Inst Num DB Name      Instance     Host
------------ -------- ------------ ------------ ------------
* 1574596224        1 ORCL         orcl         WIN-D30A3J59
                                             LLL

Using 1574596224 for database Id
Using          1 for instance number


Specify the number of days of snapshots to choose from
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed.  Pressing <return> without
specifying a number lists all completed snapshots.


输入 num_days 的值:  2    //显示几天内的

Listing the last 2 days of Completed Snapshots

                                                        Snap
Instance     DB Name        Snap Id    Snap Started    Level
------------ ------------ --------- ------------------ -----
orcl         ORCL                 7 31 7月  2020 11:36     1
                                  8 31 7月  2020 14:09     1
                                  9 31 7月  2020 15:00     1

Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
输入 begin_snap 的值:  8
Begin Snapshot Id specified: 8

输入 end_snap 的值:  9
End   Snapshot Id specified: 9

Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_8_9.html.  To use this name,
press <return> to continue, otherwise enter an alternative.

输入 report_name 的值:  C:\awrrpt_1_8_9.html
Using the report name C:\awrrpt_1_8_9.html
Report written to C:\awrrpt_1_8_9.html

AWR报告的位置:
C:\awrrpt_1_8_9.html

hhh6.jpg


http://www.kler.cn/a/546945.html

相关文章:

  • 【二叉树学习7】
  • Eclipse:关闭多余的工具条
  • Docker compose 以及镜像使用
  • Sprinig源码解析
  • [LeetCode]day21 15.三数之和
  • Machine Learning:Optimization
  • H5自适应响应式代理记账与财政咨询服务类PbootCMS网站模板 – HTML5财务会计类网站源码下载
  • HCIA项目实践---OSPF的基本配置
  • 在本地校验密码或弱口令 (windows)
  • DeepSeek免费部署到WPS或Office
  • Linux 内核 IPoIB 驱动中 sysfs 属性冲突问题的分析与解决
  • LAWS是典型的人机环境系统
  • 【第4章:循环神经网络(RNN)与长短时记忆网络(LSTM)— 4.6 RNN与LSTM的变体与发展趋势】
  • Unity使用iTextSharp导出PDF-04图形
  • 修改OnlyOffice编辑器默认字体
  • 小米 R3G 路由器刷机教程(Pandavan)
  • 算法练习——哈希表
  • QML使用ChartView绘制箱线图
  • harmonyOS的文件的增、删、读、写相关操作(fs/content)
  • 土星云边缘计算微服务器 SE110S-WA32加持DeepSeek,本地部署企业私有推理大模型!