所有的视图或者表
V$FIXED_TABLE 查看所有动态性能视图
dict 查看所有的固定视图
查看sga和pga的相关信息
select *from v
s
g
a
i
n
f
o
;
s
e
l
e
c
t
∗
f
r
o
m
v
sgainfo; select *from v
sgainfo;select∗fromvpgastat;
删除命名空间:
drop tablespace test_pdb1 including contents and datafiles;
查询用户的所有权限
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’ );
查看直接授予的权限或者角色:(权限说明具体是干什么的)
select * from dba_sys_privs;
查看用户对表所拥有的权限:
select * from dba_tab_privs;
查看用户被授予了那些角色:
select * from dba_role_privs;
查看一个角色有哪些权限:
select * from role_sys_privs;
查看某个角色对对象的权限:
SELECT * FROM role_tab_privs;
给用户进行批量授权
select 'grant select on '||owner||'.'||object_name||' to C##USER2;'
from dba_objects
where owner in ('C##USER1')
and object_type='TABLE';
然后将查询接结果复制并执行
归档:
oracle的归档要在mount状态下
alter database archivelog或者alter database noarchivelog
ARCHIVE LOG LIST 列出归档相关参数
ALTER SYSTEM SWITCH LOGFILE; 切换归档日志
alter system set log_archive_dest_1=‘location=xxxx’;将归档目录自定义
alter system set db_recovery_file_dest_size = ‘’;调整快速恢复区的大小
视图v$ RECOVERY_FILE_DEST来获得关于快速恢复区的如下相关信息:文件总数量,当前位置,磁盘限额,已使用空间,通过删除文件能回收空间。空间详细单位是字节
视图V$ RECOVERY_AREA_USAGE包含不同类型文件(包括控制文件、在线重做日志文件、归档重做日志文件、备份片、镜像拷贝、闪回日志、外部归档日志文件)的磁盘限额使用率及文件数量,通过删除废弃的、冗余的或者备份到磁带上的文件来回收的空间百分比。
修改redolog多副本
select * from v$logfile; 查看现有的groups
alter database add logfile member ‘/u01/app/oracle/oradata/orclcdb/redo04.log’ to group 1; 在group1中添加一个副本文件 会自动创建
修改controlfile多副本:
show parameter control
alter system set control_files=‘/u01/app/oracle/oradata/orclcdb/control01.ctl’,‘/u01/app/oracle/fast_recovery_area/orclcdb/control02.ctl’,‘/u01/app/oracle/oradata/orclcdb/control03.ctl’ scope=spfile;
shutdown immediate然后再复制现有的控制文件到新加的control03.ctl (注意文件的属主)
命名空间相关操作:
create tablespace test_pdb1 datafile '/u01/app/oracle/oradata/orclcdb/test_pdb1.dbf' size 100M autoextend on next 10M maxsize unlimited;
CREATE USER backtest identified by "xxx" DEFAULT TABLESPACE example QUOTA UNLIMITED ON example;
查询表空间使用情况:
SELECT UPPER(F.TABLESPACE_NAME) "表空间名",
D.TOT_GROOTTE_MB "表空间大小(M)",
D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)",
TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,2),'990.99') "使用比",
F.TOTAL_BYTES "空闲空间(M)",
F.MAX_BYTES "最大块(M)"
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 * from dba_ts_quotas;
查看表空间是否具有自动扩展的能力:
SELECT T.TABLESPACE_NAME,D.FILE_NAME,
D.AUTOEXTENSIBLE,D.BYTES,D.MAXBYTES,D.STATUS
FROM DBA_TABLESPACES T,DBA_DATA_FILES D
WHERE T.TABLESPACE_NAME =D.TABLESPACE_NAME
ORDER BY TABLESPACE_NAME,FILE_NAME;
增加表空间大小:
ALTER TABLESPACE app_data ADD DATAFILE
'/u01/app/oracle/oradata/orclcdb/test_pdb2.dbf' SIZE 50M
AUTOEXTEND ON NEXT 5M MAXSIZE 100M;(也可以取消自动扩展)
或者直接修改现有数据文件大小:
ALTER DATABASE DATAFILE '/u01/app/oracle/oradata/orclcdb/test_pdb1.dbf'
RESIZE 100M;
查询整个库使用大小
该语句查询oracle数据库实际的大小
select sum(GB) as "TOTAL(G)"
from (
select sum(bytes)/1024/1024/1024 as GB
from dba_data_files
union all
select sum(bytes)/1024/1024/1024
from dba_temp_files
union all
select sum(bytes)/1024/1024/1024
from v$log
)
常见的sql操作
select * from dba_users where username=‘C##USER2’ 查看用户使用的表空间
select * from dba_data_files 查看每个表空间下的所有文件
select * from dba_ts_quotas; 查询用户的表空间限额
select dbms_metadata.get_ddl(‘TABLE’,‘HH4’) from dual; 查询建表语句文章来源:https://www.toymoban.com/news/detail-432232.html
查询出系统中被锁的表
select b.owner,b.object_name,a.session_id,a.locked_mode
from v$locked_object a,dba_objects b
where b.object_id = a.object_id;
select b.username,b.sid,b.serial#,logon_time
from v$locked_object a,v$session b
where a.session_id = b.sid order by b.logon_time;
alter system kill session “sid,serial#”; 杀进程中的会话文章来源地址https://www.toymoban.com/news/detail-432232.html
-- 授予查询权限
GRANT SELECT ANY TABLE TO your_username;
GRANT SELECT ANY DICTIONARY TO your_username;
GRANT SELECT_CATALOG_ROLE TO your_username;
到了这里,关于oracle日常操作的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!