Oracle命令脚本

前端之家收集整理的这篇文章主要介绍了Oracle命令脚本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一、Oracle数据库实例、用户、目录及session会话查看:

1、ORACLE SID查看设置

查看SID、用户名

$ env|grep SID 、select * from v$instance、select instance_name,host_name from v$instance;

查看数据库所有用户用户状态:
sql> select usernames,account_status from dba_users;

设置SID

$ export ORACLE_SID=hisvhfs

查看数据库DBID:
sql>select * from v$DBID

2、查询、设置Oracle数据库实例最大进程数及最大会话数

查看系统最大session:
sql>show parameter session

查看当前连接数:
sql>select count(*) from v$bgprocess

查看系统最大进程数:
sql>show parameter process

查看当前连接到数据库用户
sql>select count(*) from v$session

查看当前数据库建立的会话情况:
sql> select sid,serial#,username,program,machine,status from v$session;

查询应用的连接数sql:
sql> SELECT b.MACHINE,b.PROGRAM,COUNT (*)
FROM v$process a,v$session b
WHERE a.ADDR = b.PADDR AND b.USERNAME IS NOT NULL
GROUP BY b.MACHINE,b.PROGRAM
ORDER BY COUNT (*) DESC;

查看当前数据库的并发连接数

sql> select count(*) from v$session where status='ACTIVE';

查看当前有哪些用户正在使用数据:
select osuser,a.username,cpu_time/executions/1000000||'s',sql_fulltext,machine
from v$session a,v$sqlarea b
where a.sql_address = b.address
order by cpu_time/executions desc;

查看数据库指定用户的连接情况

sql> select sid,serial# from v$session where username='XX'; XX为用户

例如:

sql> select sid,serial# from v$session where username='BSPDEV';

SID SERIAL#
---------- ----------
204 4609
399 5841
590 6041

清除用户下连接进程

sql> alter system kill session '204,4609';

sql> alter system kill session '399,5841';

sql> alter system kill session '590,6041';

修改processes和sessions值
  sql> alter system set processes=300 scope=spfile;
  系统已更改。
  sql> alter system set sessions=335 scope=spfile;
  系统已更改。

修改processes和sessions值必须重启oracle服务器才能生效
ORACLE的连接数(sessions)与其参数文件中的进程数(process)有关,它们的关系如下:
  sessions=(1.1*process+5)

3、查看数据库目录

sql> select * from all_directories;

4、查看数据库现有模式、是否归档

sql>select name,log_mode from v$database;

也可以用下面的语句
archive log list;(该方法需要as sysdba)

查看数据库的创建日期和归档方式
sql> Select Created,Log_Mode,Log_Mode From V$Database;

5、配置用户密码过期时间

alter profile "default" limit password_life_time unlimited; 配置用户密码永不过期
alter profile "default" limit password_life_time 100; 配置用户密码100天过期

6、创建、配置新用户及查看用户属性

解锁新用户
sql> alter user scott account unlock;
sql> alter user scott identified by tiger;

删除oracle用户
sql>drop user username cascade; (删除用户相关的所有对象)

这样该用户包括用户下的表,试图,同义词,过程,索引,及相关的一切就删除了。

创建用户并赋权限以及设置默认表空间。

以sysdba用户登陆进行以下设置:

-- Create the user
create user VHFSM
identified by vhnj1fsm
default tablespace MGRVHFSTBSDEF 此处是设置默认表空间。
temporary tablespace TEMP
profile DEFAULT
quota unlimited on mgrvhfstbs2010此处是设置可操作的其他表空间
quota unlimited on mgrvhfstbsdef;
-- Grant/Revoke role privileges
grant connect to VHFSM;
grant dba to VHFSM;
-- Grant/Revoke system privileges
grant unlimited tablespace to VHFSM;

查看用户及角色权限

--1.查看所有用户
select * from dba_users;
select * from all_users;
select * from user_users;

--2.查看用户或角色系统权限(直接赋值给用户或角色的系统权限):
select * from dba_sys_privs;
select * from user_sys_privs;

--3.查看角色(只能查看登陆用户拥有的角色)所包含的权限

sql>select * from role_sys_privs;

--4.查看用户对象权限:
select * from dba_tab_privs;
select * from all_tab_privs;
select * from user_tab_privs;

--5.查看所有角色:
select * from dba_roles;

--6.查看用户或角色所拥有的角色:
select * from dba_role_privs;
select * from user_role_privs;

--7.查看哪些用户有sysdba或sysoper系统权限(查询时需要相应权限)

select * from V$PWFILE_USERS

--注意:
--1、以下语句可以查看Oracle提供的系统权限

select name from sys.system_privilege_map

--2、查看一个用户的所有系统权限(包含角色的系统权限)

SELECT privilege
FROM dba_sys_privs
WHERE grantee = 'DATAUSER'
UNION
SELECT privilege
FROM dba_sys_privs
WHERE grantee IN (SELECT granted_role FROM dba_role_privs WHERE grantee = 'DATAUSER');


二、创建、管理Oracle表空间

1、先查询空闲空间

select tablespace_name,file_id,block_id,bytes,blocks from dba_free_space;
2、增加Oracle表空间

查询数据文件名称、大小和路径的信息,语句如下:

select tablespace_name,file_name from dba_data_files;
3、修改文件大小语句如下

alter database datafile
'需要增加的数据文件路径,即上面查询出来的路径
'resize 800M;

4、创建Oracle表空间

create tablespace test
datafile '/home/app/oracle/oradata/oracle8i/test01.dbf' size 8M
autoextend on
next 5M
maxsize 10M;

create tablespace sales
datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M
autoextend on
next 50M
maxsize unlimited
maxsize unlimited 是大小不受限制

create tablespace sales
datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M
autoextend on
next 50M
maxsize 1000M
extent management local uniform;
unform表示区的大小相同,默认为1M

create tablespace sales
datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M
autoextend on
next 50M
maxsize 1000M
extent management local uniform size 500K;
unform size 500K表示区的大小相同,为500K

create tablespace sales
datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M
autoextend on
next 50M
maxsize 1000M
extent management local autoallocate;
autoallocate表示区的大小由随表的大小自动动态改变,大表使用大区小表使用小区

create tablespace sales
datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M
autoextend on
next 50M
maxsize 1000M
temporary;
temporary创建字典管理临时表空间 ,要创建本地管理临时表空间要加temporary tablespace关键字

create temporary tablespace sales
tempfile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M
autoextend on
next 50M
maxsize 1000M
创建本地管理临时表空间,如果是临时表空间,所有语句中的datafile都换为tempfile ,所有语句中的datafile都换为tempfile8i


为表空间增加数据文件
alter tablespace sales add
datafile '/home/app/oracle/oradata/oracle8i/sales02.dbf' size 800M
autoextend on next 50M
maxsize 1000M;


5、查看表空间是否自动扩展
sql> select file_id,file_name,tablespace_name,autoextensible,increment_by from dba_data_files order by file_id desc;

更改自动扩展属性

alter database datafile
'/home/app/oracle/oradata/oracle8i/sales01.dbf',
'/home/app/oracle/oradata/oracle8i/sales02.dbf'
'/home/app/oracle/oradata/oracle8i/sales01.dbf
autoextend off;

6、表空间的查看与修改

查看用户默认表空间

sql> select username,default_tablespace from dba_users;查看所有用户的默认表空间

sql> select username,default_tablespace from user_users;查看某个用户的默认表空间,前提需要connect该用户

sql> select USERNAME,DEFAULT_TABLESPACE,TEMPORARY_TABLESPACE from dba_userswhere username = 'hr'; 查看用户对应的默认表空间

修改用户默认表空间
sql> alter user zhanghr default tablespace test;

设置数据库的默认临时表空间:
sql>Alter database default temporary tablespace temp_tbs_name;

查看用户和默认表空间的关系:
sql>select username,default_tablespace from dba_users;

查看临时表空间:

sql> select file_name,blocks,user_blocks from dba_temp_files;

sql> select tablespace_name,current_users,total_blocks,used_blocks,free_blocks from v$sort_segment;

查看undo表空间

sql> show parameter undo;

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDOTBS1

查看undo表空间大小

sql> select sum(bytes)/1024/1024 "current undo size(M)" from dba_data_files where tablespace_name='UNDOTBS1';

通过增加数据文件来改变undo表空间大小

sql> alter tablespace undotbs1
add datafile '/oracle/oradata/orc6/undo02.dbf' size 10M;

通过resize更改数据文件大小

sql> alter database datafile '/oracle/oradata/orc6/undo02.dbf' resize 100M;

查看某个表空间的数据文件

sql> select file_name,bytes/1024/1024 "bytes MB",maxbytes/1024/1024 "maxbytes MB" from dba_data_files where tablespace_name='ORA1TBS';指定表空间名要大写

查看所有表空间大小

sql> select tablespace_name,sum(bytes)/1024/1024 from dba_data_files
group by tablespace_name;

查看已使用的表空间大小
sql> select tablespace_name,sum(bytes)/1024/1024 from dba_free_space
group by tablespace_name;

oracle查看表空间大小及使用率:

方法一:

SELECT UPPER(F.TABLESPACE_NAME),D.TOT_GROOTTE_MB,F.TOTAL_BYTES,TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,2),'990.99'),F.MAX_BYTES FROM (SELECT TABLESPACE_NAME,ROUND(SUM(BYTES) / (1024 * 1024),2) TOTAL_BYTES,ROUND(MAX(BYTES) / (1024 * 1024),2) MAX_BYTES FROM SYS.DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) F,(SELECT DD.TABLESPACE_NAME,ROUND(SUM(DD.BYTES) / (1024 * 1024),2) TOT_GROOTTE_MB FROM SYS.DBA_DATA_FILES DD GROUP BY DD.TABLESPACE_NAME) D WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME ORDER BY 4 DESC;

方法二:

SELECT D.TABLESPACE_NAME,
SPACE || 'M' "SUM_SPACE(M)",
BLOCKS "SUM_BLOCKS",
SPACE - NVL (FREE_SPACE,0) || 'M' "USED_SPACE(M)",
ROUND ( (1 - NVL (FREE_SPACE,0) / SPACE) * 100,2) || '%'
"USED_RATE(%)",
FREE_SPACE || 'M' "FREE_SPACE(M)"
FROM ( SELECT TABLESPACE_NAME,
ROUND (SUM (BYTES) / (1024 * 1024),2) SPACE,
SUM (BLOCKS) BLOCKS
FROM DBA_DATA_FILES
GROUP BY TABLESPACE_NAME) D,
( SELECT TABLESPACE_NAME,2) FREE_SPACE
FROM DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME) F
WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+)
UNION ALL
SELECT D.TABLESPACE_NAME,
BLOCKS SUM_BLOCKS,
USED_SPACE || 'M' "USED_SPACE(M)",
ROUND (NVL (USED_SPACE,0) / SPACE * 100,2) || '%' "USED_RATE(%)",
NVL (FREE_SPACE,0) || 'M' "FREE_SPACE(M)"
FROM ( SELECT TABLESPACE_NAME,
SUM (BLOCKS) BLOCKS
FROM DBA_TEMP_FILES
GROUP BY TABLESPACE_NAME) D,
ROUND (SUM (BYTES_USED) / (1024 * 1024),2) USED_SPACE,
ROUND (SUM (BYTES_FREE) / (1024 * 1024),2) FREE_SPACE
FROM V$TEMP_SPACE_HEADER
GROUP BY TABLESPACE_NAME) F
WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+)
ORDER BY 1;

方法三:

SELECT *
FROM (SELECT a.tablespace_name,
to_char(a.bytes / 1024 / 1024,'99,999.999') total_bytes,
to_char(b.bytes / 1024 / 1024,999.999') free_bytes,
to_char(a.bytes / 1024 / 1024 - b.bytes / 1024 / 1024,
'99,999.999') use_bytes,
to_char((1 - b.bytes / a.bytes) * 100,'99.99') || '%' USE
FROM (SELECT tablespace_name,SUM(bytes) bytes
FROM dba_data_files
GROUP BY tablespace_name) a,
(SELECT tablespace_name,SUM(bytes) bytes
FROM dba_free_space
GROUP BY tablespace_name) b
WHERE a.tablespace_name = b.tablespace_name
UNION ALL
SELECT c.tablespace_name,
to_char(c.bytes / 1024 / 1024,
to_char((c.bytes - d.bytes_used) / 1024 / 1024,
to_char(d.bytes_used / 1024 / 1024,
to_char(d.bytes_used * 100 / c.bytes,SUM(bytes) bytes
FROM dba_temp_files
GROUP BY tablespace_name) c,SUM(bytes_cached) bytes_used
FROM v$temp_extent_pool
GROUP BY tablespace_name) d
WHERE c.tablespace_name = d.tablespace_name)
ORDER BY tablespace_name;

查看表空间使用大小情况一

sql> select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024 "used MB",
b.bytes/1024/1024 "free MB",round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"
from
(select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a,
(select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name ) b
where a.tablespace_name=b.tablespace_name
order by ((a.bytes-b.bytes)/a.bytes) desc
;

TABLESPACE_NAME Sum MB used MB free MB percent_used
------------------------------ ---------- ---------- ---------- ------------
SYSAUX 490 461.0625 28.9375 94.09
UNDOTBS1 75 66.8125 8.1875 89.08
USERS 5 1.3125 3.6875 26.25
ORA1TBS 400 2 398 .5
ORA2TBS 400 2 398 .5

查看表空间使用大小情况二

sql> select a.tablespace_name,total,free,total-free used from
2 ( select tablespace_name,sum(bytes)/1024/1024 total from dba_data_files
group by tablespace_name) a,
( select tablespace_name,sum(bytes)/1024/1024 free from dba_free_space
group by tablespace_name) b
where a.tablespace_name=b.tablespace_name; 3 4 5 6

TABLESPACE_NAME TOTAL FREE USED
------------------------------ ---------- ---------- ----------
USERS 5 .9375 4.0625
TESTTB 500 499 1
SYSAUX 550 30 520
EXAMPLE 100 20.75 79.25
UNDOTBS1 110 96.625 13.375



sql命令行情况下将结果输出到指定文件中。
sql> spool out.txt
sql> select * from v$database;
sql> spool off

三、查看、管理ORACLE数据文件

查看数据文件
sql> select name from v$datafile;

更改数据文件大小:

sql> alter database datafile '/oradata2/hisvhfs/undotbs01.dbf' resize 30G;

查看用户所有表空间及对应的数据文件和数据文件大小

sql> select tablespace_name,round(bytes/(1024*1024),0) total_space from dba_data_files order by tablespace_name;

查看数据文件状态及大小

sql> select name,BYTES,STATUS,FILE# from v$datafile;

查看所有数据文件

sql> select name from v$datafile;

查看所有表空间对应的数据文件
sql> select tablespace_name,0) total_space from dba_data_files order by tablespace_name;

四、查看、管理ORACLE表

查看所有segment的大小。
Select Segment_Name,Sum(bytes)/1024/1024 From User_Extents Group By Segment_Name

查询表的大小和表空间的大小

有两种含义的表大小。一种是分配给一个表的物理空间数量,而不管空间是否被使用。可以这样查询获得字节数:
当前实例以scott用户登录,并创建dept表的副本dept_copy2为例。
sql> select segment_name,bytes
2 from user_segments
3 where segment_type = 'TABLE';

SEGMENT_NAME BYTES
-------------------------------------------------------------------------------- ----------
DEPT_COPY2 65536
DEPT_COPY 65536
BIN$7Sa/taXJEKHgQ2kFqMCxMQ==$0 65536
ITEMS 65536
SALGRADE 65536
EMP 65536
DEPT 65536

7 rows selected

或者
sql> Select Segment_Name,Sum(bytes)/1024/1024 From User_Extents Group By Segment_Name;

SEGMENT_NAME SUM(BYTES)/1024/1024
-------------------------------------------------------------------------------- --------------------
DEPT 0.0625
PK_DEPT 0.0625
EMP 0.0625
DEPT_COPY 0.0625
DEPT_COPY2 0.0625
ITEMS 0.0625
PK_EMP 0.0625
SALGRADE 0.0625

8 rows selected

另一种表实际使用的空间。这样查询
sql> select table_name from user_tables;

TABLE_NAME
------------------------------
DEPT
EMP
BONUS
SALGRADEanalyze table emp compute statistics;
ITEMS
DEPT_COPY
DEPT_COPY2

sql> analyze table DEPT_COPY2 compute statistics;

查看某个表属于哪个表空间:
sql> select tablespace_name from all_tables where table_name='SYS_EXPORT_FULL_01';

创建表时指定表空间:
sql>create table a (name varchar(10)) tablespace test;

查看数据库表结构:

sql> desc dept_copy2;
Name Type Nullable Default Comments
------ ------------ -------- ------- --------
DEPTNO NUMBER(2) Y
DNAME VARCHAR2(14) Y
LOC VARCHAR2(13) Y

修改表的列名:
sql> alter table users rename column ID to PID;

修改表的列的字符大小

sql> alter table student modify class varchar2(10);

创建主键:
sql> alter table users add constraint pk_users primary key(name);

修改表的列数据类型:
sql> select * from users;

NAME AGE PID
---------- ---------- ----------
赵霞 3.2012E+18
李莉 3.2012E+18

sql> alter table users add(newColumn varchar2(20));
sql> update users set newColumn = PID;
sql> commit;
sql> alter table users drop column PID cascade constraints;
sql> alter table users rename column newColumn to PID;
sql> commit;

sql> desc users;
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
NAME NOT NULL VARCHAR2(10)
AGE NUMBER
PID VARCHAR2(20)

sql> select * from users;

NAME AGE PID
---------- ---------- --------------------
赵霞 3201231988001010101
李莉 3201231988001010102

创建序列:
sql> create sequence seq_PID
start with 3201231988001010101
maxvalue 3201231999999999999
minvalue 3201231988001010101
nocycle
cache 100;

创建触发器:
sql> create or replace trigger trigger_users
before insert on users
for each row
begin
select seq_PID.nextval into :new.PID from dual;
end;
/

查看用户序列

sql> select sequence_name from USER_SEQUENCES;

SEQUENCE_NAME
------------------------------
SEQ_ID

查看用户触发器

sql> select * from user_triggers where table_name = upper('job');

通过group by 语句使用rollup运算符汇总ID列

sql> select ID,avg(age),sum(age),max(age),count(*)
2 from job group by rollup(ID);

ID AVG(AGE) SUM(AGE) MAX(AGE) COUNT(*)
---------- ---------- ---------- ---------- ----------
1583 25 25 25 1
1584 24 24 24 1
1585 25 25 25 1
1586 25 25 25 1
1587 23 23 23 1
1683 22 22 22 1
1684 24 24 24 1
1685 25 25 25 1
1686 24 24 24 1
1687 22 22 22 1
1688 28 28 28 1

ID AVG(AGE) SUM(AGE) MAX(AGE) COUNT(*)
---------- ---------- ---------- ---------- ----------
1689 26 26 26 1
1690 26 26 26 1
1783 35 35 35 1
1784 1
1883 24 24 24 1
1884 1
25.2 378 35 17

having子句与group by 子句一般一起使用,可以在汇总相关数据后进一步筛选汇总的数据。

sql> select ID,count(*)
2 from job group by id having avg(age)>25;

ID AVG(AGE) SUM(AGE) MAX(AGE) COUNT(*)
---------- ---------- ---------- ---------- ----------
1690 26 26 26 1
1783 35 35 35 1
1689 26 26 26 1
1688 28 28 28 1

多表连接查询

sql> select job.name,job.id,job.job,job.age,users.name,users.age from job,users
2 where job.name=users.name;

NAME ID JOB AGE NAME AGE
-------- ---------- ---------- ---------- ---------- ----------
陈灵灵 1783 KTV服务员 35 陈灵灵 38
李莉 1587 IT程序员 23 李莉
赵霞 1683 空姐 22 赵霞

desc 在oracle数据库里有两种用法,一是查询表的结构 格式:desc table_name
二是在用排序时(order by)是降序的关键字 格式 :order by column_name desc;

查看表的segment大小,即表实际占用的物理大小,无论是否使用。

sql> select segment_name,partition_name,extents from user_segments where segment_name='JOBS'; (segment名,即表明)
sql> select segment_name,count(extent_id),sum(bytes),sum(blocks) from user_extents where segment_name='JOBS' group by segment_name,partition_name;

五、查看、管理ORACLE常用的参数、配置等

查看控制文件
sql> select name from v$controlfile;

查看重做日志文件,简称日志文件
sql> select * from v$logfile;

查看表的索引:
sql>select index_name,index_type,table_name from user_indexes where table_name='表名';

修改oracle时间格式:
sql> alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS';

指定开启某个监听:
sql>lsnrctl start orc5_lisenter(此处是当初建监听时创建的监听名)

数据库SCN及时间查询

sql> select sysdate from dual; 查看数据库时间

SYSDATE
-----------------
20131216 23:52:55

sql> select dbms_flashback.get_system_change_number from dual; 查看当前数据库的SCN号

GET_SYSTEM_CHANGE_NUMBER
------------------------
1583042

sql> select to_char(scn_to_timestamp(1583042),'yyyy-mm-dd hh24:mi:ss') from dual; 根据数据库的SCN号查找对应的数据库时间

TO_CHAR(SCN_TO_TIME
-------------------
2013-12-16 23:45:38

sql> select timestamp_to_scn(to_date('2013-12-16 15:30:19','yyyy-mm-dd hh24:mi:ss')) from dual; 根据数据库的时间查找对应的数据库SCN号

TIMESTAMP_TO_SCN(TO_DATE('2013-12-1615:30:19','YYYY-MM-DDHH24:MI:SS'))
----------------------------------------------------------------------
1519388

sql> select * from (select time_dp,scn from smon_scn_time order by time_dp desc)where rownum<10;条件查找,查找rownum小于10的SCN以对应的时间。

TIME_DP SCN
----------------- ----------
20131216 15:53:02 1584574
20131216 15:46:45 1583098
20131216 15:45:20 1583022
20131216 15:39:08 1582399
20131216 15:37:01 1581998
20131216 15:31:08 1579915
20131216 14:46:02 1577210
20131216 14:40:16 1576196
20131216 14:35:12 1575597

9 rows selected.

数据库游标设置

sql> show parameter open_cursors; 查看游标参数
sql> select count(*) from v$open_cursor; 查看打开的游标
sql> select name,value from v$sysstat where name ='opened cursors current';查看当前打开的游标
sql> alter system set open_cursors=3000 scope=both; 修改默认游标数

六、查看、配置ORACLE重做日志

创建日志文件组:
sql> alter database add logfile group 4
(
'/oracle/oradata/orc6/redo04.log'
)
size 10M;

查看日志文件

sql> select group#,status,member from v$logfile;

为日志文件增加日志文件

sql> alter database add logfile member '/oracle/oradata/orc6/redo05.log' to group 3;

查看日志文件大小

sql> select GROUP#,BLOCKSIZE,MEMBERS from v$log;

七、desc的常用查询

sql> desc dba_temp_files; 查询临时表空间

sql> desc v$database; 查看数据库

sql> desc dba_data_files; 查看数据文件

sql> desc user_segments; 查看oracle segment(段)

sql> desc dba_segments; 查看ORACLE segment

sql> desc dba_tables; 查看表
sql> desc dba_objects 查看对象
sql> desc dba_users; 查看用户
sql> desc dba_tablespaces; 查看表空间

sql> desc user_segments; 查看数据段

sql> desc dba_jobs; 查看job

sql> desc dba_role_privs; 查看角色权限

sql> desc dba_constraints 查看约束

sql> desc dba_cons_columns 查看列约束

sql> show parameter log_archive_dest; 查看archive log所在位置

sql> archive log list; 查看归档目录以及log sequence

sql> select * from V$FLASH_RECOVERY_AREA_USAGE; 查看flash_recovery_area 使用情况。

sql> select sum(percent_space_used)*3/100 from v$flash_recovery_area_usage; 计算flash_recovery_area已经占用的空间。

sql> show parameter recover; 查找recovery目录

sql> desc v$process 通过v$process视图,我们获的是当前系统中所有进程信息,包括后台进程”,也包括“服务器进程”。
sql> select addr,program from v$process;


sql> desc v$bgprocess 通过v$bgprocess视图,我们获得当前系统中启动的Oracle“后台进程”信息
sql> select paddr,name from v$bgprocess where paddr<>'00';

通过v$bgprocess.paddr与v$process.addr关联起来的,关联后查询结果显而易见只会有Oracle“后台进程”的信息
sql> select a.paddr,a.name,a.description from v$bgprocess a,v$process b where a.paddr=b.addr;

八、查看ASM磁盘组信息

sql> desc v$asm_disk;

sql> desc v$asm_diskgroup;

九、常用sql命令行设置

1、set

set wrap on/off 查询返回的纪录每行超过默认宽度时,可选择换行(on )或不换行(off),默认为换行; set linesize N 设置查询返回的纪录每行的宽度,超过这个宽度则截掉,不过这个宽度则补空格。

原文链接:https://www.f2er.com/oracle/211865.html

猜你在找的Oracle相关文章