標籤:串連資料庫 程式 oracle 密碼 空間
一、oracle 常用相關sql 語句
1. 串連資料庫
su - oracle -c " sqlsplus 使用者/密碼 註:首次登陸用 sqlplus / as sysdba
註: 關閉資料庫:註:shutdown可加關閉選項,從最溫和到最粗暴的行為選項為(shutdown、shutdown transactional、shutdown immediate、shutdown abort)
shutdown:關閉,等待每個使用者退出系統戓被取消後退出關閉資料庫。
shutdown transactional:事務性關閉,等待每個使用者提交戓回退當前的事務,然oracle取消對話,在所有使用者退出系統後執行關閉。
shutdown immediate:直接關閉,取消所有使用者對話(促使回退),執行正常的關閉程式。
關閉資料庫後,需關閉監聽,lsnrctl stop
2. 查看目前使用者
show user;
3. 建立資料表空間
create tablespace 表名 datafile ‘/db/oracle11g/oradata/表名/表名01.dbf‘ size 500m autoextend on next 500m
maxsize 31g logging online permanent extent management local;
4. 添加資料表空間
ALTER TABLESPACE 資料表空間名 ADD DATAFILE ‘/db/oracle11g/oradata/表名/表名02.dbf‘ SIZE 500m AUTOEXTEND ON NEXT 500m
MAXSIZE 31g;
5. 建立使用者
create user 使用者名稱 identified by 密碼 default tablespace 資料表空間名 temporary tablespace temp;
6. 分配許可權
grant 許可權 to 使用者;
7. 重設密碼
alter user 使用者 identified by 密碼;
8. 查看目前使用者的資料表空間的資料檔案
select * from v$datafile
9. 查看錶所在的資料表空間對應的資料檔案
select t1.name from v$tablespace t1,v$datafile t2 where t1.ts=value
10. 查看目前使用者的資料表空間名
select * from v$tablespace;
11. 查看某個使用者具有什麼角色?
select * from dba_role_privs where grantee=‘SYS‘
12. 知道資料表空間,顯示該資料表空間包括的所有表;
select * from all_tables where tablespace_name=‘資料表空間名‘
13. 知道表名,顯示該表所屬的資料表空間
select tablespace_name,table_name from user_tables where table_name=‘表名‘
14. 重新命名資料表空間
在資料表空間為ONLINE的情況下
ALTER TABLESPACE tablespace_name RENAME TO new_tablespace_name ;
15. 刪除資料表空間
DROP TABLESPACE tablespace_name INCLUDING CONTENTS AND DATAFILES
16. 查看錶空間
SELECT t.tablespace_name, round(SUM(bytes / (1024 * 1024)), 0) ts_size
FROM dba_tablespaces t, dba_data_files d
WHERE t.tablespace_name = d.tablespace_name
GROUP BY t.tablespace_name;
17. 查看控制檔案
SELECT NAME FROM v$controlfile;
18. 查看記錄檔
SELECT MEMBER FROM v$logfile;
19. 查看資料庫的建立日期和方式
SELECT created, log_mode, log_mode FROM v$database;
20. 查看當前串連資料庫的主機數:
col machine for a20
set linesize 150
select distinct machine,username from v$session order by username,machine;
21. 查詢使用者會話
select username,serial#,sid from v$session;
alter system kill session ‘serial#,sid‘; -- 刪除相關使用者會話
22. 查詢 oracle 的串連數
select count(*) from v$session
23. 查詢oracle 的並發串連數
select count(*)from v$session where status=‘ACTIVE‘;
24. 查看oracle 的版本
select banner from sys.v_$version;
本文出自 “江湖笑笑生” 部落格,請務必保留此出處http://hashlinux.blog.51cto.com/9647696/1793427
oracle 常用相關sql 語句