oracle之使用者和表空間

2021-08-22 08:14:05 字數 4023 閱讀 4871

使用者和表空間檢視

1:檢視當前使用者

show user;

2:資料字典dba_users (有關user的資料字典) user_users(普通使用者用)

查詢建立的所有使用者名稱

select username from dba_users;

3:啟用某個使用者(被鎖定時,需要解鎖)

解鎖某使用者scott

alter user scott account unlock;

表空間:

定義:oracle 表空間屬於儲存結構,是一種用來儲存資料庫物件的邏輯空間,用來優化效能,如資料檔案等

是oracle資訊儲存最大的邏輯空間,其下還包含有段,區,資料塊等邏輯資料型別。表空間是在資料庫開闢的

乙個空間,用於存放資料庫物件,乙個資料庫可由多個表空間組成。

分類:永久表空間:儲存資料庫中需要永久儲存的物件,如表,檢視,儲存過程,索引等

臨時表空間:儲存資料庫的中間執行過程,如:儲存order by資料庫排序,分組時產生的臨時資料,

操作後儲存的內容被自動釋放,臨時表空間是通用的,所有的使用者都使用temp作為臨時表              空間一般只需temp乙個臨時表空間就夠了,當然也可以自己在建乙個表空間

undo表空間:儲存資料修改前的副本。儲存事務所修改的舊址,即被修改之前的資料。當我們對

一張表的資料進行修改的同時會對修改之前的資料進行儲存,為了對資料進行回滾,恢復              和撤銷操作

4:檢視使用者表空間

dba_tablespaces(管理員用) user_tablespaces(普通使用者用)(資料字典)

在dba使用者檢視所有的tablespace

select tablespace_name from dba_tablespace/user_tablespace;

在普通使用者下檢視所有的tablespace

select tablespace_name from user_tablespace;

5:檢視某使用者所在的預設表空間,臨時表空間

select default_tablespace,temporary_tablespace from dba_users where username='system';(字串匹配時注意大小寫,因為oracle內部儲存都為大寫)

6:修改某使用者的預設表空間

語法:alter user user_name default tablespace tablespace_name;

alter user system  default tablespace system;

7建立表空間

語法:create [temporary] tablespace tablespacename tempfile/datafile '路徑名/檔名.dbf' size 10m/g;

[temporary] 關鍵字:用該關鍵字表示建立臨時表空間。

路徑名預設為oracle的安裝路徑

size 表示大小

create tablespace text1_tablespace datafile 'd:\text1.dbf' size 10m;

8:檢視表空間所在的檔案路徑

用dba_data_files 資料字典

select file_name from dba_data_files where tablespace_name='text1_tablespace';

9:檢視臨時temp表空間所在的檔案路徑

用dba_temp_files資料字典

select file_name from dba_temp_files where tablespace_name='temp';

10:修改表空間的狀態

alter tablespace tablespace_name online/offline(offline下不能使用);

11:檢視某錶空間狀態

用dba_tablespaces 資料字典

select status from dba_tablespaces where tablespace_name='text1_tablespace(表空間名)';

12:設定表空間狀態(read only/read write)

語法:alter tablespace tablespace_name read only/read write;

alter tablespace text1_tablespace read only;

alter tablespace text1_tablespace read write;

13:往表空間新增資料檔案

語法:alter tablespace tablespace_name

add datafile '路徑名\檔名.dbf' size xx;

alter tablespace text1_tablespace add datafile 'text2.dbf' size 10m;

14:刪除資料檔案

注:不能刪除建立表空間時第乙個建立的檔案,除非把錶空間也刪除

語法:alter tablespace tablespace_name

drop datafile '路徑名\檔名.dbf';

alter tablespace text1_tablespace drop datafile 'text2.dbf';

15:刪除表空間

語法:drop tablespace tablespace_name [including contents and datafiles];

[including contents]:是表空間有資料檔案(非空)時刪除表空間的必要條件

[and datafiles]:刪除表空間及其資料檔案

drop tablespace text1_tablespace including contents;

16:建立表空間

create [undo] tablespace tablespace_name

[datafile datafile_spec1(檔案路徑)][,datafile datefile_spec2]...

[{minimun extent integer[k|m]

|blocksize integer[k]

|[logging|nologging]

|default storage_clause

|[online|offline]

|[permanent|temporary]

|extent_manager_clause

|segment_manager_clause

mininum extent:指定表空間區的大小

blocksize:指定表空間非標準塊的大小

logging/nologging:是否將表空間物件的更改寫入重做日誌

default storage_clause:指定表空間的預設儲存引數

datafile:檔案及其儲存屬性

filename [size integer[k|m]]  [reuse] [autoextend_clause]

autoextend_clause:autoextend on next integer[k|m] maxsize integer[k|m]

extent_manager_cause:表空間的管理方式

extent  manager [local|dictionary](本地管理或者字典管理)

[autoalllocal | uniform [size integer[k|m]]](管理區的大小)

其中:autoallocal:指定oracle自動管理區的大小

uniform:指定所有區的大小都相同

extent_manager_segment:段空間管理方式

segment space manager auto;

default storage:(儲存引數)

default storage(initial integer[k],next integer[k],minextents integer,maxextents                    integer,pctincrase integer)

oracle之使用者和表空間

使用者和表空間檢視 1 檢視當前使用者 show user 2 資料字典dba users 有關user的資料字典 user users 普通使用者用 查詢建立的所有使用者名稱 select username from dba users 3 啟用某個使用者 被鎖定時,需要解鎖 解鎖某使用者scot...

Oracle之使用者建立,賦許可權,賦表空間

將下面的指令碼,另存成乙個bat echo off echo echo 生成sql指令碼 建立表空間,使用者名稱和密碼 echo set p tsname 請輸入表空間名 set p tsdir 請輸入表空間檔案所在的資料夾路徑 set p username 請輸入使用者名稱 set p userp...

oracle使用者和表空間

建立表空間 create tablespace test1 table datafile test1file.dbf size 10m 建立永久表空間 create temporary tablespace temptest1 tablespace tempfile test1tempfile.db...