个人整理,以便记忆:
1. 更改数据库的用户密码
alter user user identified by “user”;
2. 改变oracle字符集
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
3. 备份数据库
exp user/pass@orcl owner=user file=user.dmp log=user.log
4. 恢复数据库
imp fromuser=user touser=user1 file=user.dmp log=new-user.log
5. 查看表空间及文件存放路径
select file_name,tablespace_name from dba_data_files;
6. 查看用户所对应的表空间
select username,default_tablespace from dba_users;
7. 删除用户
Drop user user1 cascade(删除用户及其所属的表空间,完全删除)
8. 创建用户设置默认表空间
create user user_name identified by passwd default tablespace tablespace_name;
9. 授予用户权限
grant connect,resource to user;
grant dba to user;
10. 创建表空间
create tablespace wlotx
logging
datafile '/home/oracle/oradata/orcl/wlotx.dbf'
size 50m
autoextend on;
11. 查询当前连接用户的会话进程
SELECT SID,SERIAL# FROM V$SESSION WHERE USERNAME='USER1';
SID SERIAL#
---------- ----------
24 25341
86 18117
12. 结束此用户的会话进程
ALTER SYSTEM KILL SESSION '24,25341';
ALTER SYSTEM KILL SESSION '86,18117';
13. 查看死锁的进程
SELECT
s.username,l.OBJECT_ID,l.SESSION_ID,s.SERIAL#,l.ORACLE_USERNAME,l.OS_USER_NAME,l.PROCESS FROM V$LOCKED_OBJECT l,V$SESSION S WHERE l.SESSION_ID=S.SID;
14. 查看表空间的状态
select name,status from v$datafile;
15. 查看表空间的大小,可用空间及使用率;
select df.tablespace_name "表空间名",totalspace "总空间M",freespace "剩余空间M",
round((1- freespace/totalspace)*100,2) "使用率%"
from
(select tablespace_name,round(sum(bytes)/1024/1024) totalspace
from dba_data_files
group by tablespace_name) df,
(select tablespace_name,round(sum(bytes)/1024/1024) freespace
from dba_free_space
group by tablespace_name) fs
where df.tablespace_name=fs.tablespace_name;
16. 使表空间脱机,联机
alter tablespace users offline;
alter tablespace users online;
17. 查看表空间的状态是否自动扩展
select file_id,file_name,tablespace_name,autoextensible,increment_by from dba_data_files order by file_id desc;
18. 修改表空间大小(表空间一定要在联机状态下,做扩展)
alter database datafile '/opt/oracle/oradata/orcl/users01.dbf' resize 5000m;
阅读(806) | 评论(0) | 转发(0) |