Professional Documents
Culture Documents
Lab 2 - Quản lý người dùng trong Oracle
Lab 2 - Quản lý người dùng trong Oracle
Lab 2 - Quản lý người dùng trong Oracle
I – QUẢN LÝ USER
1. Tablespace
- Một CSDL Oracle được chia thành những đơn vị lưu trữ luận lý được gọi là
các tablespace, nhằm mục đích gom nhóm các cấu trúc luận lý có liên quan
với nhau.
- Mỗi CSDL có 1 hoặc nhiều các tablespace. Mỗi tablespace chứa 1 hoặc nhiều
các datafile. Datafile là các cấu trúc vật lý tương thích với hệ điều hành bên
dưới, dùng để lưu trữ dữ liệu của các cấu trúc luận lý trong tablespace chứa
nó. Kích thước tổng cộng của các datafile chính là dung tích lưu trữ tổng cộng
của tablespace đó.
Khi tạo mới 1 user, ta có thể quy định về default tablespace, temporary
tablespace, quota trên các tablespace, thời hạn hiệu lực của password,… ngay
trong câu lệnh tạo user hoặc sẽ chỉ định cụ thể sau này.
Tuy trong câu lệnh tạo user ta không chỉ định default tablespace và
temporary tablespace, Oracle đã tự gán các giá trị mặc định cho user này.
c. Hiển thị tablespace của user vừa mới tạo:
Log out ra khỏi user hiện tại và log in bằng user vừa mới tạo, sẽ nhận được
thông báo:
Đăng nhập lại user ban đầu và cấp quyền cho user nttu như sau:
d. Khi user mới được tạo ra, nếu ta không cấp các quyền tạo các loại object
(table, index,…) thì user đó không thể tạo được các object. Tùy thuộc vào nhu cầu của
từng user, ta chỉ nên cấp những quyền cần thiết chứ không nên cấp dư.
Một điều kiện bắt buộc khác để user có thể tạo được các object là ta phải cấp quota
cho user trên các tablespace tương ứng. Một user có thể được cấp quota sử dụng trên 1
hoặc nhiều tablespace. Quota có thể limited hoặc unlimited.
Ví dụ: Cho thấy khi user nttu tạo mới 1 bảng sẽ hiển thị thông báo lỗi:
Nếu muốn user có thể sử dụng tối đa 1 tablespace nào đó thì dùng cú pháp
sau:
e. Nếu muốn user có thể tạo object trên bất kỳ tablespace nào thì dùng cú pháp
sau:
Hoặc
b. Password expiration:
Ta có thể làm cho 1 password hết hạn bằng 2 cách:
Hoặc
*Ta cũng có thể bắt buộc password expire ngay khi tạo mới một user:
Xem trạng thái tài khoản (Account Status) của tất cả các user:
3. Xóa User
DROP USER nttu;
User Dropped.
II – User Profile
A. Lý thuyết
1. Profile
▪ Một profile là một tập hợp có tên của các giới hạn tài nguyên, được gán cho một
hay nhiều user trong CSDL Oracle.
▪ Profile cung cấp một cách quản lý dễ dàng việc giới hạn tài nguyên. Nó giúp giới
hạn việc sử dụng quá mức các tài nguyên của toàn hệ thống. Profile cũng là cách
để quản lý các chính sách về password.
▪ Trong một CSDL có thể tạo nhiều profile. Một profile mặc định sẽ được dùng để
gán cho những user không được gán profile một cách tường minh.
▪ Lưu ý rằng các giá trị mặc định đều được thiết lập là “unlimited”.
2. Các loại tài nguyên
▪ Một profile có thể mô tả các loại giới hạn tài nguyên sau:
✓ Số lượng các session đồng thời mà user có thể thực hiện.
✓ Thời gian xử lý CPU cho một session của user đó hoặc cho một cuộc gọi (call)
tới Oracle bởi 1 câu lệnh SQL.
✓ Số lần đọc luận lý I/O cho một session của user đó hoặc cho một cuộc gọi (call)
tới Oracle bởi 1 câu lệnh SQL.
✓ Lượng thời gian nhàn rỗi cho session của user.
✓ Lượng thời gian connect cho một session.
✓ Các quy định về password (số lần cố gắng login thất bại, thời gian hiệu lực của1
password , …)
✓
A. Thực hành
1. Tạo mới Profile
a. Trước hết, để hệ thống có thể thi hành việc ràng buộc các giới hạn tài nguyên,
ta cần enable tham số hệ thống RESOURCE_LIMIT bằng câu lệnh sau:
2. Gán Profile
a. Có thể gán profile khi vừa tạo user:
CREATE USER nttu2 IDENTIFIED BY nttu1 PROFILE app_user;
User created.
b. Khi tạo mới user, nếu không gán tường minh thì user sẽ được gán
profile mặc định như sau:
d) Số lần thay đổi password trước khi được sử lại password cũ là 5 lần.
===================================================
CREATE PROFILE profile
LIMIT { resource_parameters
| password_parameters
}
[ resource_parameters
| password_parameters
]... ;
===================================================
resource_parameters
SESSIONS_PER_USER
Specify the number of concurrent sessions to which you want to limit the user.
CPU_PER_SESSION
Specify the CPU time limit for a session, expressed in hundredth of seconds.
CPU_PER_CALL
Specify the CPU time limit for a call (a parse, execute, or fetch), expressed in hundredths of seconds.
CONNECT_TIME
Specify the total elapsed time limit for a session, expressed in minutes.
IDLE_TIME
Specify the permitted periods of continuous inactive time during a session, expressed in minutes. Long-
running queries and other operations are not subject to this limit.
LOGICAL_READS_PER_SESSION
Specify the permitted number of data blocks read in a session, including blocks read from memory and
disk.
LOGICAL_READS_PER_CALL
Specify the permitted number of data blocks read for a call to process a SQL statement (a parse, execute,
or fetch).
password_parameters
Use the following clauses to set password parameters. Parameters that set lengths of time are interpreted
in number of days. For testing purposes you can specify minutes (n/1440) or even seconds (n/86400).
FAILED_LOGIN_ATTEMPTS
Specify the number of failed attempts to log in to the user account before the account is locked.
PASSWORD_LIFE_TIME
Specify the number of days the same password can be used for authentication. If you also set a value for
PASSWORD_GRACE_TIME, the password expires if it is not changed within the grace period, and
further connections are rejected. If you do not set a value for PASSWORD_GRACE_TIME, its default
of UNLIMITED will cause the database to issue a warning but let the user continue to connect
indefinitely.
*If you specify an integer for both of these parameters, then the user cannot reuse a password until the
password has been changed the password the number of times specified for
PASSWORD_REUSE_MAX during the number of days specified for PASSWORD_REUSE_TIME.
*If you specify an integer for either of these parameters and specify UNLIMITED for the other, then
the user can never reuse a password.
* If you specify DEFAULT for either parameter, then Oracle Database uses the value defined in the
DEFAULT profile. By default, all parameters are set to UNLIMITED in the DEFAULT profile. If you
have not changed the default setting of UNLIMITED in the DEFAULT profile, then the database treats
the value for that parameter as UNLIMITED
*If you set both of these parameters to UNLIMITED, then the database ignores both of them.
PASSWORD_GRACE_TIME
Specify the number of days after the grace period begins during which a warning is issued and login is
allowed. If the password is not changed during the grace period, the password expires.
PASSWORD_VERIFY_FUNCTION
The PASSWORD_VERIFY_FUNCTION clause lets a PL/SQL password complexity verification script
be passed as an argument to the CREATE PROFILE statement. Oracle Database provides a default
script, but you can create your own routine or use third-party software instead.
*For function, specify the name of the password complexity verification routine.
If you specify expr for any of the password parameters, the expression can be of any form except scalar
subquery expression.
https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_6010.htm#i2066025