|
查询段头块(放的本块最重要的元数据:位图或者freelist):
- select s.header_block
- from dba_segments s where s.tablespace_name='EXAMPLE'
- and s.segment_name='EMPLOYEES';
复制代码 查询段的第一个块:
- select e.block_id
- from dba_extents e
- where e.segment_name='EMPLOYEES';
复制代码
------------------------------------------------------------------------------用户账号的4个方面
1. Authentication 2. Account 3. Password 4. Session
sys的两重身份:
- [oracle@station90 ~]$ sqlplus /nolog
- SQL*Plus: Release 12.1.0.2.0 Production on Wed Jul 18 20:21:43 2018
- Copyright (c) 1982, 2014, Oracle. All rights reserved.
- SQL> conn / as sysdba
- Connected.
- SQL> show user
- USER is "SYS"
- SQL> conn / as sysoper
- Connected.
- SQL> show user
- USER is "PUBLIC"
- SQL>
复制代码
举个外部验证的例子:
- SQL> show parameter authen
- NAME TYPE VALUE
- ------------------------------------ ----------- ------------------------------
- os_authent_prefix string ops$
- remote_os_authent boolean FALSE
- SQL> create user ops$oracle identified externally ;
- User created.
- SQL>
复制代码- SQL> grant connect to ops$oracle;
- Grant succeeded.
- SQL>
复制代码- SQL> conn /
- Connected.
- SQL> show user
- USER is "OPS$ORACLE"
- SQL>
复制代码- SQL> conn /
- Connected.
- SQL> show user
- USER is "OPS$ORACLE"
- SQL> create table t_ops( a number );
- create table t_ops( a number )
- *
- ERROR at line 1:
- ORA-01031: insufficient privileges
复制代码 SYS授权:
- grant create table to ops$oracle;
- select * from dba_sys_privs sp
- where sp.grantee='OPS$ORACLE';
复制代码 | GRANTEE | PRIVILEGE | ADMIN_OPTION | COMMON | 1 | OPS$ORACLE | CREATE TABLE | NO | NO |
- SQL> conn /
- Connected.
- SQL> show user
- USER is "OPS$ORACLE"
- SQL> create table t_ops( a number );
- create table t_ops( a number )
- *
- ERROR at line 1:
- ORA-01031: insufficient privileges
- SQL>
- SQL>
- SQL> create table t_ops( a number );
- Table created.
- SQL>
复制代码 现在如果要插入数据,就会报错:
- SQL> create table t_ops( a number );
- Table created.
- SQL> insert into t_ops values (1) ;
- insert into t_ops values (1)
- *
- ERROR at line 1:
- ORA-01950: no privileges on tablespace 'USERS'
复制代码
- select * from dba_ts_quotas;
复制代码 | TABLESPACE_NAME | USERNAME | BYTES | MAX_BYTES | BLOCKS | MAX_BLOCKS | DROPPED | 1 | SYSAUX | AUDSYS | 1507328 | -1 | 184 | -1 | NO | 2 | SYSAUX | GSMADMIN_INTERNAL | 1441792 | 104857600 | 176 | 12800 | NO | 3 | SYSAUX | APPQOSSYS | 0 | -1 | 0 | -1 | NO | 4 | SYSAUX | OLAPSYS | 0 | -1 | 0 | -1 | NO | 5 | SYSAUX | FLOWS_FILES | 0 | -1 | 0 | -1 | NO | 6 | EXAMPLE | OE | 10420224 | -1 | 1272 | -1 | NO |
- alter user ops$oracle quota 64K on users;
复制代码- select * from dba_ts_quotas;
复制代码 | TABLESPACE_NAME | USERNAME | BYTES | MAX_BYTES | BLOCKS | MAX_BLOCKS | DROPPED | 1 | SYSAUX | FLOWS_FILES | 0 | -1 | 0 | -1 | NO | 2 | SYSAUX | OLAPSYS | 0 | -1 | 0 | -1 | NO | 3 | SYSAUX | APPQOSSYS | 0 | -1 | 0 | -1 | NO | 4 | SYSAUX | GSMADMIN_INTERNAL | 1441792 | 104857600 | 176 | 12800 | NO | 5 | SYSAUX | AUDSYS | 1507328 | -1 | 184 | -1 | NO | 6 | USERS | OPS$ORACLE | 0 | 65536 | 0 | 8 | NO | 7 | EXAMPLE | OE | 10420224 | -1 | 1272 | -1 | NO |
- SQL> insert into t_ops values (1) ;
- insert into t_ops values (1)
- *
- ERROR at line 1:
- ORA-01950: no privileges on tablespace 'USERS'
- SQL> insert into t_ops values (1) ;
- 1 row created.
- SQL> commit;
- Commit complete.
- SQL>
复制代码 如果回收quota,还能插入数据吗?
- alter user ops$oracle quota 0 on users;
复制代码- SQL> insert into t_ops values (2) ;
- 1 row created.
- SQL> commit;
- Commit complete.
复制代码
关于quota的使用的简单的实验而复杂的原理:
- SQL> begin
- 2 for i in 3..4000
- 3 loop
- 4 insert into t_ops values (i);
- 5 end loop;
- 6 commit;
- 7 end;
- 8 /
- begin
- *
- ERROR at line 1:
- ORA-01536: space quota exceeded for tablespace 'USERS'
- ORA-06512: at line 4
- SQL> select count(*) from t_ops;
- COUNT(*)
- ----------
- 2
- SQL> begin
- 2 for i in 3..2000
- 3 loop
- 4 insert into t_ops values (i);
- 5 end loop;
- 6 commit;
- 7 end;
- 8 /
- PL/SQL procedure successfully completed.
- SQL> select count(*) from t_ops;
- COUNT(*)
- ----------
- 2000
- SQL>
复制代码 其他建用户的方法:
- grant connect to user1 identified by oracle_4U;
- grant create session to user2 identified by oracle_4U;
- select * from system_privilege_map spm
- where spm.name='CREATE SESSION';
复制代码 | PRIVILEGE | NAME | PROPERTY | 1 | -5 | CREATE SESSION | 0 |
- select * from role_sys_privs rsp
- where rsp.role='CONNECT';
复制代码 | ROLE | PRIVILEGE | ADMIN_OPTION | COMMON | 1 | CONNECT | SET CONTAINER | NO | YES | 2 | CONNECT | CREATE SESSION | NO | YES |
--------------------------------------------------------之后经常会使用以下的语句查询一个账户的Account和Athentication状态:
- select u.username,
- u.password,
- u.account_status,
- u.lock_date,
- u.expiry_date,
- u.authentication_type
- from dba_users u
- where u.username like 'USER%' or
- u.username='OPS$ORACLE';
复制代码 | USERNAME | PASSWORD | ACCOUNT_STATUS | LOCK_DATE | EXPIRY_DATE | AUTHENTICATION_TYPE | 1 | OPS$ORACLE | EXTERNAL | OPEN | | | EXTERNAL | 2 | USER1 | | OPEN | | 1/14/2019 9:01:20 PM | PASSWORD | 3 | USER2 | | OPEN | | 1/14/2019 9:01:51 PM | PASSWORD |
------------------------------------------------以下研究ORA-28000:
- alter user user1 account lock;
复制代码- SQL> conn user1/oracle_4U
- ERROR:
- ORA-28000: the account is locked
复制代码 user1账号永久被锁定。
| USERNAME | PASSWORD | ACCOUNT_STATUS | LOCK_DATE | EXPIRY_DATE | AUTHENTICATION_TYPE | 1 | OPS$ORACLE | EXTERNAL | OPEN | | | EXTERNAL | 2 | USER1 | | LOCKED | 7/18/2018 9:14:00 PM | 1/14/2019 9:01:20 PM | PASSWORD | 3 | USER2 | | OPEN | | 1/14/2019 9:01:51 PM | PASSWORD |
--------------------------------------------------以下研究ORA-28001:
- alter user user2 password expire;
复制代码- SQL> conn user2/oracle_4U
- ERROR:
- ORA-28001: the password has expired
- Changing password for user2
- New password:
复制代码
| USERNAME | PASSWORD | ACCOUNT_STATUS | LOCK_DATE | EXPIRY_DATE | AUTHENTICATION_TYPE | 1 | OPS$ORACLE | EXTERNAL | OPEN | | | EXTERNAL | 2 | USER1 | | LOCKED | 7/18/2018 9:14:00 PM | 1/14/2019 9:01:20 PM | PASSWORD | 3 | USER2 | | EXPIRED |
| 7/18/2018 9:19:32 PM | PASSWORD |
他自己就能解决:
- Changing password for user2
- New password: *********
- Retype new password: *********
- Password changed
- Connected.
- SQL>
复制代码 | USERNAME | PASSWORD | ACCOUNT_STATUS | LOCK_DATE | EXPIRY_DATE | AUTHENTICATION_TYPE | 1 | OPS$ORACLE | EXTERNAL | OPEN | | | EXTERNAL | 2 | USER1 | | LOCKED | 7/18/2018 9:14:00 PM | 1/14/2019 9:01:20 PM | PASSWORD | 3 | USER2 | | OPEN | | 1/14/2019 9:21:24 PM | PASSWORD |
-------------------------------------------------------------------------以下研究ORA-28002(过了宽限期后伴随ORA-28001出现)/ORA-28007:
- CREATE PROFILE "PROFILE1" LIMIT CPU_PER_SESSION DEFAULT
- CPU_PER_CALL DEFAULT
- CONNECT_TIME DEFAULT
- IDLE_TIME DEFAULT
- SESSIONS_PER_USER DEFAULT
- LOGICAL_READS_PER_SESSION DEFAULT
- LOGICAL_READS_PER_CALL DEFAULT
- PRIVATE_SGA DEFAULT
- COMPOSITE_LIMIT DEFAULT
- PASSWORD_LIFE_TIME DEFAULT
- PASSWORD_GRACE_TIME DEFAULT
- PASSWORD_REUSE_MAX DEFAULT
- PASSWORD_REUSE_TIME DEFAULT
- PASSWORD_LOCK_TIME 0.000694444
- FAILED_LOGIN_ATTEMPTS 1
- PASSWORD_VERIFY_FUNCTION DEFAULT
复制代码- select u.username,
- u.password,
- u.account_status,
- u.lock_date,
- u.expiry_date,
- u.authentication_type,
- u.profile
- from dba_users u
- where u.username ='USER2';
-
- alter user user2 profile profile1;
-
- select * from dba_profiles p
- where p.profile='PROFILE1' and p.resource_type <> 'KERNEL';
复制代码 | PROFILE | RESOURCE_NAME | RESOURCE_TYPE | LIMIT | COMMON | 1 | PROFILE1 | FAILED_LOGIN_ATTEMPTS | PASSWORD | 1 | NO | 2 | PROFILE1 | PASSWORD_LIFE_TIME | PASSWORD | DEFAULT | NO | 3 | PROFILE1 | PASSWORD_REUSE_TIME | PASSWORD | DEFAULT | NO | 4 | PROFILE1 | PASSWORD_REUSE_MAX | PASSWORD | DEFAULT | NO | 5 | PROFILE1 | PASSWORD_VERIFY_FUNCTION | PASSWORD | DEFAULT | NO | 6 | PROFILE1 | PASSWORD_LOCK_TIME | PASSWORD | .0006 | NO | 7 | PROFILE1 | PASSWORD_GRACE_TIME | PASSWORD | DEFAULT | NO |
试错一次密码:
- [oracle@station90 ~]$ sqlplus /nolog
- SQL*Plus: Release 12.1.0.2.0 Production on Sat Jul 21 09:23:27 2018
- Copyright (c) 1982, 2014, Oracle. All rights reserved.
- SQL> conn user2/oracle_4U
- Connected.
- SQL> conn user2/oracle_5U
- ERROR:
- ORA-01017: invalid username/password; logon denied
- Warning: You are no longer connected to ORACLE.
- SQL> conn user2/oracle_4U
- ERROR:
- ORA-28000: the account is locked
- SQL> conn user2/oracle_4U
- Connected.
- SQL>
复制代码- select u.username,
- u.password,
- u.account_status,
- u.lock_date,
- u.expiry_date,
- u.authentication_type,
- u.profile
- from dba_users u
- where u.username ='USER2';
复制代码 | USERNAME | PASSWORD | ACCOUNT_STATUS | LOCK_DATE | EXPIRY_DATE | AUTHENTICATION_TYPE | PROFILE | 1 | USER2 | | LOCKED(TIMED) | 7/21/2018 9:25:21 AM | 1/14/2019 9:21:24 PM | PASSWORD | PROFILE1 |
ora-28002:
上面图中的第一个lock和第2个lock不是同一个意思,第1个lock 实际上是“过期”。
刚刚改完口令生命期的时候,马上查看用户:
- select u.username,
- u.password,
- u.account_status,
- u.lock_date,
- u.expiry_date,
- u.authentication_type,
- u.profile
- from dba_users u
- where u.username ='USER2';
复制代码 | USERNAME | PASSWORD | ACCOUNT_STATUS | LOCK_DATE | EXPIRY_DATE | AUTHENTICATION_TYPE | PROFILE | 1 | USER2 | | OPEN | | 7/18/2018 9:22:24 PM | PASSWORD | PROFILE1 |
------------------------------
- select u.username,
- u.password,
- u.account_status,
- u.lock_date,
- u.expiry_date,
- u.authentication_type,
- u.profile
- from dba_users u
- where u.username ='USER2';
复制代码 | USERNAME | PASSWORD | ACCOUNT_STATUS | LOCK_DATE | EXPIRY_DATE | AUTHENTICATION_TYPE | PROFILE | 1 | USER2 | | EXPIRED(GRACE) | | 7/21/2018 9:40:45 AM | PASSWORD | PROFILE1 |
- SQL> conn user2/oracle_4U
- Connected.
- SQL> conn user2/oracle_4U
- ERROR:
- ORA-28002: the password will expire within 0 days
- ......
- 7/21/2018 9:40:45 AM之后
- Connected.
- SQL> conn user2/oracle_4U
- ERROR:
- ORA-28001: the password has expired
- Changing password for user2
- New password:
复制代码- select u.username,
- u.password,
- u.account_status,
- u.lock_date,
- u.expiry_date,
- u.authentication_type,
- u.profile
- from dba_users u
- where u.username ='USER2';
复制代码 | USERNAME | PASSWORD | ACCOUNT_STATUS | LOCK_DATE | EXPIRY_DATE | AUTHENTICATION_TYPE | PROFILE | 1 | USER2 | | EXPIRED | | 7/21/2018 9:40:45 AM | PASSWORD | PROFILE1 |
然后用户在提示符下改密码:
- New password: *********
- Retype new password: *********
- Password changed
- Connected.
- SQL> conn user2/oracle_4U
- Connected.
- SQL> conn user2/oracle_4U
- Connected.
- SQL>
复制代码
- select u.username,
- u.password,
- u.account_status,
- u.lock_date,
- u.expiry_date,
- u.authentication_type,
- u.profile
- from dba_users u
- where u.username ='USER2';
复制代码 | USERNAME | PASSWORD | ACCOUNT_STATUS | LOCK_DATE | EXPIRY_DATE | AUTHENTICATION_TYPE | PROFILE | 1 | USER2 | | OPEN | | 7/21/2018 9:50:34 AM | PASSWORD | PROFILE1 | 在7/21/2018 9:50:34 AM之前正常登录,之后 ORA-28002
还有1分钟,然后被逼着改密码:
------------------------------------------------------------------------
Password history: Checks the new password to ensure that the password is not reused for a specified amount of time or a specified number of password changes. (说明Oracle会记住旧的密码,不想让你使用旧的密码)These checks can be implemented by using one of the following:
PASSWORD_REUSE_TIME: Specifies that a user cannot reuse a password for a given number of days
PASSWORD_REUSE_MAX: Specifies the number of password changes that are required before the current password can be reused
If both password history parameters have a value of UNLIMITED, Oracle Database ignores both.(默认没限制,导致用户在grace期过以后,还是老是用同一个密码)。
If both parameters are set, password reuse is allowed—but only after meeting both conditions.(“与”的关系) The user must have changed the password the specified number of times, and the specified number of days must have passed since the old password was last used.
For example, the profile of user ALFRED has PASSWORD_REUSE_MAX set to 10 and PASSWORD_REUSE_TIME set to 30. User ALFRED cannot reuse a password until he has reset the password 10 times and until 30 days have passed since the password was last used.
If one parameter is set to a number and the other parameter is specified as UNLIMITED, then the user can never reuse a password.(书上本句是错的,正确的是只听一个指令的,同时图形界面也有bug):以下是图形界面最的大的bug:
只好在命令行上改:
- alter profile profile1 limit
- PASSWORD_REUSE_TIME 0.010416667
- PASSWORD_REUSE_MAX 1;
复制代码-
- select * from dba_profiles p
- where p.profile='PROFILE1' and p.resource_type <> 'KERNEL';
复制代码 | PROFILE | RESOURCE_NAME | RESOURCE_TYPE | LIMIT | COMMON | 1 | PROFILE1 | FAILED_LOGIN_ATTEMPTS | PASSWORD | DEFAULT | NO | 2 | PROFILE1 | PASSWORD_LIFE_TIME | PASSWORD | .0006 | NO | 3 | PROFILE1 | PASSWORD_REUSE_TIME | PASSWORD | .0104 | NO | 4 | PROFILE1 | PASSWORD_REUSE_MAX | PASSWORD | 1 | NO | 5 | PROFILE1 | PASSWORD_VERIFY_FUNCTION | PASSWORD | DEFAULT | NO | 6 | PROFILE1 | PASSWORD_LOCK_TIME | PASSWORD | DEFAULT | NO | 7 | PROFILE1 | PASSWORD_GRACE_TIME | PASSWORD | .0006 | NO |
经过一次不同的“改”,如果这时时间不够,仍然无法重用特别喜欢的旧密码:
- SQL> alter user user2 identified by oracle_4U ;
- alter user user2 identified by oracle_4U
- *
- ERROR at line 1:
- ORA-28007: the password cannot be reused
复制代码 通过等待,能解决这个问题,(等过15分钟):
- SQL> alter user user2 identified by oracle_4U ;
- alter user user2 identified by oracle_4U
- *
- ERROR at line 1:
- ORA-28007: the password cannot be reused
- ......
- 等过15分钟
- SQL> alter user user2 identified by oracle_4U ;
- User altered.
- SQL>
复制代码 -------------------------------------------------密码复杂性函数:
[oracle@station90 admin]$ ls -l `pwd`/utlpwdmg.sql
-rw-r--r-- 1 oracle oinstall 12543 11月 7 2013 /u01/app/oracle/product/12.1.0/dbhome_2/rdbms/admin/utlpwdmg.sql
以下关于角色:
- select u.username,
- u.password,
- u.account_status,
- u.lock_date,
- u.expiry_date,
- u.authentication_type
- from dba_users u
- where u.username like 'USER%' or
- u.username='OPS$ORACLE';
-
- alter user user2 password expire;
-
- select u.name, u.password from user$ u ;
-
- revoke select any table from hr;
-
- grant select_catalog_role to hr;
-
- revoke select_catalog_role from hr;
-
- select * from dba_role_privs rp
- where rp.grantee='HR';
-
- create role role1 identified by oracle_4U;
-
- grant role1 to hr;
-
- alter user hr default role none;
复制代码- SQL> conn hr/oracle_4U
- Connected.
- SQL> select password from dba_users;
- select password from dba_users
- *
- ERROR at line 1:
- ORA-00942: table or view does not exist
- SQL> conn hr/oracle_4U
- Connected.
- SQL> select * from session_roles;
- ROLE
- --------------------------------------------------------------------------------
- RESOURCE
- SQL> conn hr/oracle_4U
- Connected.
- SQL> select * from session_roles;
- no rows selected
- SQL> set role resource;
- Role set.
- SQL> select * from session_roles;
- ROLE
- --------------------------------------------------------------------------------
- RESOURCE
- SQL> set role resource,role1;
- set role resource,role1
- *
- ERROR at line 1:
- ORA-01979: missing or invalid password for role 'ROLE1'
- SQL> set role resource,role1 identified by oracle_4U;
- Role set.
- SQL> select * from session_roles;
- ROLE
- --------------------------------------------------------------------------------
- RESOURCE
- ROLE1
- SQL>
复制代码
|
|