windows平台上 oracle简单操作手册

一 环境描述

Oracle 11g单机环境

二 基本操作

2.1 数据库的启动与停止

language 复制代码
启动:
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>
language 复制代码
停止:
SQL> shutdown immediate
数据库已经关闭。
已经卸载数据库。
ORACLE 例程已经关闭。

点击开始-管理工具-服务

数据库以及监听运行服务

2.2 监听的启动与停止

language 复制代码
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)设置系统变量

找到计算机-右键-点击属性

点击高级系统设置:

选择高级-环境变量

点击新建:

点击确定

查看:

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)查看操作系统日志:

开始-管理工具-事件查看器

(2)数据库警告日志位置:

$ORACLE_BASE\diag\rdbms\orcl\orcl\trace

C:\app\Administrator\diag\rdbms\orcl\orcl\trace

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系统资源使用

任务管理器

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

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

language 复制代码
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
相关推荐
流星白龙13 分钟前
【Redis】2.Redis重大版本
数据库·redis·junit
流星白龙14 分钟前
【Redis】7.Hash表
数据库·redis·哈希算法
love530love14 分钟前
OpenClaw Windows Companion 桌面客户端 连接 LM Studio 完整配置指南
人工智能·windows·python·openclaw
流星白龙1 小时前
【Redis】4.基本全局命令
数据库·redis·缓存
王八八。2 小时前
Navicat 17破解版下载安装教程 附安装激活步骤(2026 最新版)
数据库·navicat
Jelena157795857923 小时前
电商运营分析数据比价接口实战:多平台价格监控与智能决策系统
java·大数据·数据库
流星白龙4 小时前
【Redis】3.Redis安装与命令行客户端
数据库·redis·缓存
凌虚5 小时前
基于 PostgreSQL WAL 构建 CDC 系统:原理与工程实现
数据库·后端·postgresql
BullSmall5 小时前
PostgreSQL 14 pg_dumpall 完整备份指南
数据库·postgresql·oracle
一只枫林6 小时前
MySQL内、外连接知识点汇总
java·前端·数据库