---
title: "Oracle 学习笔记: Statspack安装使用"
author: "logicgate"
date: "2009-06-18T10:17:06Z"
tags: []
categories: ["数据库"]
slug: "oracle-statspack"
draft: false
lastmod: "2009-07-03T00:32:09Z"
id: 410427
url: "https://logicgate.iteye.com/blog/410427"
---

俗话说，工欲善其事，必先利其器。做数据库性能分析，也要有一款好的工具。statspack就是oracle自带的一个强大并且免费的性能分析工具。

安装statspack需要用户具有sysdba的权限。首先以sysdba登陆，为statspack创建一个单独的tablespace。

```
SQL> create tablespace perfstat datafile 'D:\oracle\oradata\epcit\data_file\PERFSTAT.DBF' size 2G;

Tablespace created.
```

 

然后运行spcreate.sql。安装 statspack所需要的sql文件都位于%oracle\_home%\\RDBMS\\ADMIN目录下。为了使用方便，可以把这个路径加入到环境变量 sqlpath中（set sqlpath=%oracle\_home\\RDBMS\\ADMIN）。

```
SQL> @spcreate

Choose the PERFSTAT user's password
-----------------------------------
Not specifying a password will result in the installation FAILING

Enter value for perfstat_password: password

Enter value for default_tablespace: perfstat
Using tablespace PERFSTAT as PERFSTAT default tablespace.

Enter value for temporary_tablespace: temp
Using tablespace temp as PERFSTAT temporary tablespace.

... Creating PERFSTAT user
... Installing required packages
... Creating views
... Granting privileges

NOTE:
SPCUSR complete. Please check spcusr.lis for any errors.

SQL> --  Build the tables and synonyms
SQL> connect perfstat/&&perfstat_password
Connected.
SQL> @@spctab

Using perfstat tablespace to store Statspack objects

... Creating STATS$SNAPSHOT_ID Sequence
... Creating STATS$... tables

NOTE:
SPCTAB complete. Please check spctab.lis for any errors.

SQL> --  Create the statistics Package
SQL> @@spcpkg

Creating Package STATSPACK...
Package created.

Creating Package Body STATSPACK...
Package body created.

NOTE:
SPCPKG complete. Please check spcpkg.lis for any errors.
```

 

安装过程中statspack会提示输入用户密码，默认表空间和临时表空间。如果想在silent mode下安装，则可以事先设置这些变量。

```
SQL> define perfstat_password='password'
SQL> define default_tablespace='perfstat'
SQL> define temporary_tablespace='temp'
```

 

安装完成了。