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 YESUNDOTBS1 D:\APP\ADMINISTRATOR\ORADATA\ORCL\UNDOTBS01.DBF 85 YESSYSAUX D:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSAUX01.DBF 520 YESSYSTEM D:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSTEM01.DBF 690 YESEXAMPLE 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.875UNDOTBS1 71.625USERS 0.9375SYSTEM 3.4375EXAMPLE 21.25
3、表空间使用统计
SQL> SELECT DF.TABLESPACE_NAME "表空间名",TOTALSPACE "总空间 MB",FREESPACE "剩余空间 MB",ROUND((1-FREESPACE/TOTALSPACE)*100,2) "作用率" FROM2 (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) FS4 WHERE DF.TABLESPACE_NAME = FS.TABLESPACE_NAME ORDER BY DF.TABLESPACE_NAME;表空间名 总空间 MB 剩余空间 MB 作用率------------------------------ ---------- ----------- ----------EXAMPLE 100 21 79SYSAUX 520 31 94.04SYSTEM 690 3 99.57UNDOTBS1 85 72 15.29USERS 5 1 80
4、查看数据库相关文件的位置
查看控制文件、初始化参数文件、查看告警日志文件位置:SQL> SHOW PARAMETER CONTROL;NAME TYPE VALUE------------------------------------ ----------- ------------------------------control_file_record_keep_time integer 7control_files string D:\APP\ADMINISTRATOR\ORADATA\ORCL\CONTROL01.CTL, D:\APP\ADMINISTRATOR\FLASH_RECOVERY_AREA\ORCL\CONTROL02.CTLcontrol_management_pack_access string DIAGNOSTIC+TUNINGSQL> SHOW PARAMETER SPFILE;NAME TYPE VALUE------------------------------------ ----------- ------------------------------spfile string D:\APP\ADMINISTRATOR\PRODUCT\11.2.0\DBHOME_1\DATABASE\SPFILEORCL.ORASQL> SHOW PARAMETER DUMP;NAME TYPE VALUE------------------------------------ ----------- ------------------------------background_core_dump string partialbackground_dump_dest string d:\app\administrator\diag\rdbms\orcl\orcl\tracecore_dump_dest string d:\app\administrator\diag\rdbms\orcl\orcl\cdumpmax_dump_file_size string unlimitedshadow_core_dump string noneuser_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.DBFD:\APP\ADMINISTRATOR\ORADATA\ORCL\UNDOTBS01.DBFD:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSAUX01.DBFD:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSTEM01.DBFD:\APP\ADMINISTRATOR\ORADATA\ORCL\EXAMPLE01.DBFSQL> SELECT FILE_NAME FROM DBA_TEMP_FILES;FILE_NAME--------------------------------------------------------------------------------D:\APP\ADMINISTRATOR\ORADATA\ORCL\TEMP01.DBF
6、查看用户相关信息
SQL> SELECT USERNAME FROM DBA_USERS;USERNAME------------------------------SYSSYSTEMSYSMANSCOTTHR……=================SQL> ALTER USER HR IDENTIFIED BY rusky ACCOUNT LOCK;User alteredSQL> ALTER USER HR ACCOUNT UNLOCK;User alteredSQL> 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 0cell_offload_processing boolean TRUEdb_writer_processes integer 1gcs_server_processes integer 0global_txn_processes integer 1job_queue_processes integer 1000log_archive_max_processes integer 4processes integer 150SQL> ALTER SYSTEM SET PROCESSES=200 SCOPE=SPFILE;System altered重启生效SQL> SHUTDOWN IMMEDIATESQL> STARTUP
8、给数据库增加日志组
SQL> SELECT GROUP#,THREAD#,BYTES,MEMBERS,STATUS FROM V$LOG;GROUP# THREAD# BYTES MEMBERS STATUS---------- ---------- ---------- ---------- ----------------1 1 52428800 1 CURRENT2 1 52428800 1 INACTIVE3 1 52428800 1 INACTIVESQL> ALTER DATABASE ADD LOGFILE GROUP 4 'D:\testAddLog.log' SIZE 2M;ALTER DATABASE ADD LOGFILE GROUP 4 'D:\testAddLog.log' SIZE 2MORA-00336: 大小为 4096 的日志文件块数小于最小 8192 块数SQL> ALTER DATABASE ADD LOGFILE GROUP 4 'D:\testAddLog.log' SIZE 8M;Database altered
日志组会影响数据库的性能,根据业务情况设置合适的日志组大小和组数。