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
相关推荐
余衫马1 小时前
CentOS7 离线安装 Postgresql 指南
数据库·postgresql
E___V___E1 小时前
MySQL数据库入门到大蛇尚硅谷宋红康老师笔记 高级篇 part 2
数据库·笔记·mysql
m0_748254882 小时前
mysql之如何获知版本
数据库·mysql
mikey棒棒棒2 小时前
Redis——优惠券秒杀问题(分布式id、一人多单超卖、乐悲锁、CAS、分布式锁、Redisson)
数据库·redis·lua·redisson·watchdog·cas·并发锁
专注VB编程开发20年3 小时前
除了 EasyXLS,加载和显示.xlsx 格式的excel表格,并支持单元格背景色、边框线颜色和粗细等格式化特性
c++·windows·excel·mfc·xlsx
Natsuagin4 小时前
轻松美化双系统启动界面与同步时间设置(Windows + Ubuntu)
linux·windows·ubuntu·grub
水手胡巴4 小时前
oracle apex post接口
数据库·oracle
xing.yu.CTF5 小时前
Web入侵实战分析-常见web攻击类应急处置实验2
运维·服务器·windows·web安全·apache·php漏洞·phpstudy后门漏洞
史迪仔01126 小时前
【SQL】SQL多表查询
数据库·sql
Quz6 小时前
MySQL:修改数据库默认存储目录与数据迁移
数据库·mysql