ORACLE数据库常用查询二

ORACLE数据库常用查询

1、查看表空间对应数据文件情况:

SQL> SELECT TABLESPACE_NAME,FILE_NAME,BYTES/1024/1024 MB,AUTOEXTENSIBLE FROM DBA_DATA_FILES;
TABLESPACE_NAME FILE_NAME MB AUTOEXTENSIBLE
------------------------------ -------------------------------------------------------------- ---- --------------
USERS D:\APP\ADMINISTRATOR\ORADATA\ORCL\USERS01.DBF 5 YES
UNDOTBS1 D:\APP\ADMINISTRATOR\ORADATA\ORCL\UNDOTBS01.DBF 85 YES
SYSAUX D:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSAUX01.DBF 520 YES
SYSTEM D:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSTEM01.DBF 690 YES
EXAMPLE D:\APP\ADMINISTRATOR\ORADATA\ORCL\EXAMPLE01.DBF 100 YES

2、查看剩余表空间大小

SQL> SELECT TABLESPACE_NAME,SUM(BYTES)/1024/1024 MB FROM DBA_FREE_SPACE GROUP BY TABLESPACE_NAME;
TABLESPACE_NAME MB
------------------------------ ----------
SYSAUX 30.875
UNDOTBS1 71.625
USERS 0.9375
SYSTEM 3.4375
EXAMPLE 21.25

3、表空间使用统计

SQL> SELECT DF.TABLESPACE_NAME "表空间名",TOTALSPACE "总空间 MB",FREESPACE "剩余空间 MB",ROUND((1-FREESPACE/TOTALSPACE)*100,2) "作用率" FROM
2 (SELECT TABLESPACE_NAME,ROUND(SUM(BYTES)/1024/1024) TOTALSPACE FROM DBA_DATA_FILES GROUP BY TABLESPACE_NAME) DF,
3 (SELECT TABLESPACE_NAME,ROUND(SUM(BYTES)/1024/1024) FREESPACE FROM DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) FS
4 WHERE DF.TABLESPACE_NAME = FS.TABLESPACE_NAME ORDER BY DF.TABLESPACE_NAME;

表空间名 总空间 MB 剩余空间 MB 作用率
------------------------------ ---------- ----------- ----------
EXAMPLE 100 21 79
SYSAUX 520 31 94.04
SYSTEM 690 3 99.57
UNDOTBS1 85 72 15.29
USERS 5 1 80

4、查看数据库相关文件的位置
查看控制文件、初始化参数文件、查看告警日志文件位置:

SQL> SHOW PARAMETER CONTROL;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time integer 7
control_files string D:\APP\ADMINISTRATOR\ORADATA\ORCL\CONTROL01.CTL, D:\APP\ADMINISTRATOR\FLASH_RECOVERY_AREA\ORCL\CONTROL02.CTL
control_management_pack_access string DIAGNOSTIC+TUNING

SQL> SHOW PARAMETER SPFILE;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string D:\APP\ADMINISTRATOR\PRODUCT\11.2.0\DBHOME_1\DATABASE\SPFILEORCL.ORA

SQL> SHOW PARAMETER DUMP;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
background_core_dump string partial
background_dump_dest string d:\app\administrator\diag\rdbms\orcl\orcl\trace
core_dump_dest string d:\app\administrator\diag\rdbms\orcl\orcl\cdump
max_dump_file_size string unlimited
shadow_core_dump string none
user_dump_dest string d:\app\administrator\diag\rdbms\orcl\orcl\trace

查看数据文件的位置:

SQL> SELECT FILE_NAME FROM DBA_DATA_FILES;
FILE_NAME
--------------------------------------------------------------------------------
D:\APP\ADMINISTRATOR\ORADATA\ORCL\USERS01.DBF
D:\APP\ADMINISTRATOR\ORADATA\ORCL\UNDOTBS01.DBF
D:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSAUX01.DBF
D:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSTEM01.DBF
D:\APP\ADMINISTRATOR\ORADATA\ORCL\EXAMPLE01.DBF

SQL> SELECT FILE_NAME FROM DBA_TEMP_FILES;
FILE_NAME
--------------------------------------------------------------------------------
D:\APP\ADMINISTRATOR\ORADATA\ORCL\TEMP01.DBF

6、查看用户相关信息

SQL> SELECT USERNAME FROM DBA_USERS;
USERNAME
------------------------------
SYS
SYSTEM
SYSMAN
SCOTT
HR
……
=================
SQL> ALTER USER HR IDENTIFIED BY rusky ACCOUNT LOCK;
User altered

SQL> ALTER USER HR ACCOUNT UNLOCK;
User altered

SQL> ALTER USER SCOTT IDENTIFIED BY scott;
User altered

===================
查用户对像:
select * from user_objects;
查看用户表信息:
select * from user_tables;
查看用户索引信息:
select * from user_indexes;
查看用户序列信息:
select * from user_sequences;
查看用户视图信息:
select * from user_views;
查看用户触发器信息:
select * from user_trigers;--以sys登录
查看用户权限:
SQL> conn scott/tiger;
已连接。
SQL> select * from user_sys_privs;

USERNAME PRIVILEGE ADM
------------------------------ ---------------------------------------- ---
SCOTT UNLIMITED TABLESPACE NO
=======================

7、查看及修改用户连接数

SQL> SHOW PARAMETER PROCESS;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
aq_tm_processes integer 0
cell_offload_processing boolean TRUE
db_writer_processes integer 1
gcs_server_processes integer 0
global_txn_processes integer 1
job_queue_processes integer 1000
log_archive_max_processes integer 4
processes integer 150

SQL> ALTER SYSTEM SET PROCESSES=200 SCOPE=SPFILE;
System altered
重启生效
SQL> SHUTDOWN IMMEDIATE
SQL> STARTUP

8、给数据库增加日志组

SQL> SELECT GROUP#,THREAD#,BYTES,MEMBERS,STATUS FROM V$LOG;
GROUP# THREAD# BYTES MEMBERS STATUS
---------- ---------- ---------- ---------- ----------------
1 1 52428800 1 CURRENT
2 1 52428800 1 INACTIVE
3 1 52428800 1 INACTIVE

SQL> ALTER DATABASE ADD LOGFILE GROUP 4 D:\testAddLog.log SIZE 2M;
ALTER DATABASE ADD LOGFILE GROUP 4 D:\testAddLog.log SIZE 2M
ORA-00336: 大小为 4096 的日志文件块数小于最小 8192 块数

SQL> ALTER DATABASE ADD LOGFILE GROUP 4 D:\testAddLog.log SIZE 8M;
Database altered

日志组会影响数据库的性能,根据业务情况设置合适的日志组大小和组数。

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。