ORA-65048和ORA-00959报错处理

ORA-65048和ORA-00959报错处理

  • PDB与本地用户
  • CDB与普通用户

在Oracle多租户数据库环境(Multitenant Container Database)中创建用户时遇到以下报错:

ORA-65048: error encountered when processing the current DDL statement in pluggable database ORCLPDB
ORA-00959: tablespace 'XXXX' does not exist

数据库版本:19c

PDB与本地用户

在可插拔数据库(Pluggable Database, PDB)中创建的用户为本地用户(local user)。本地用户命名不能以C##c##开头(实际上是不能以参数COMMON_USER_PREFIX值的大小写形式开头,该参数的默认值为C##)。

在PDB中创建本地用户时指定的默认表空间也要在当前PDB中创建。

SQL> show con_name

CON_NAME
------------------------------
CDB$ROOT

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 ORCLPDB                        READ WRITE NO
SQL>
SQL> alter session set container=ORCLPDB;

Session altered.

SQL> create tablespace TB_HUG datafile '+DATADG' size 1G;

Tablespace created.

SQL> create user orcl_hug identified by "Pwd_2077" default tablespace TB_HUG;

User created.

SQL> select con_id,tablespace_name from cdb_tablespaces;

    CON_ID TABLESPACE_NAME
---------- ------------------------------
         3 SYSTEM
         3 SYSAUX
         3 UNDOTBS1
         3 TEMP
         3 USERS
         3 TB_HUG

6 rows selected.

SQL> show con_id

CON_ID
------------------------------
3
SQL> show con_name

CON_NAME
------------------------------
ORCLPDB

CDB与普通用户

在数据库容器(Container Database, CDB)中创建的用户为普通用户(common user)。普通用户命名必须以C##c##开头(实际上是必须以参数COMMON_USER_PREFIX值的大小写形式开头)。普通用户可以在CDB和各个PDB中直接切换session。

SQL> alter session set container=CDB$ROOT;

Session altered.

SQL> show con_name;

CON_NAME
------------------------------
CDB$ROOT
SQL>
SQL> show con_id

CON_ID
------------------------------
1
SQL> select con_id,tablespace_name from cdb_tablespaces;

    CON_ID TABLESPACE_NAME
---------- ------------------------------
         3 SYSTEM
         3 SYSAUX
         3 UNDOTBS1
         3 TEMP
         3 USERS
         3 TB_HUG
         1 SYSTEM
         1 SYSAUX
         1 UNDOTBS1
         1 TEMP
         1 USERS

11 rows selected.

SQL> create tablespace TB_MUG datafile '+DATADG' size 1G;

Tablespace created.

SQL> select con_id,tablespace_name from cdb_tablespaces;

    CON_ID TABLESPACE_NAME
---------- ------------------------------
         3 SYSTEM
         3 SYSAUX
         3 UNDOTBS1
         3 TEMP
         3 USERS
         3 TB_HUG
         1 SYSTEM
         1 SYSAUX
         1 UNDOTBS1
         1 TEMP
         1 USERS

    CON_ID TABLESPACE_NAME
---------- ------------------------------
         1 TB_MUG

12 rows selected.

SQL> create user cdb_mug identified by 'Pwd_2078' default tablespace TB_MUG;
create user cdb_mug identified by 'Pwd_2078' default tablespace TB_MUG
                                  *
ERROR at line 1:
ORA-00988: missing or invalid password(s)     --密码必须用双引号括起来

SQL> create user cdb_mug identified by "Pwd_2078" default tablespace TB_MUG;
create user cdb_mug identified by "Pwd_2078" default tablespace TB_MUG
            *
ERROR at line 1:
ORA-65096: invalid common user or role name   --CDB普通用户命名必须以C##或c##开头

SQL> create user c##mugdb identified by "Pwd_2078" default tablespace TB_MUG;
create user c##mugdb identified by "Pwd_2078" default tablespace TB_MUG
*
ERROR at line 1:
ORA-65048: error encountered when processing the current DDL statement in
pluggable database ORCLPDB
ORA-00959: tablespace 'TB_MUG' does not exist

在CDB中创建普通用户时,如果在CREATE USER语句中指定了任何默认表空间、临时表空间、Quota或者Profile,则它们必须同时存在于所有从属于该CDB的PDB中。

SQL> alter session set container=ORCLPDB;

Session altered.

SQL> create tablespace TB_MUG datafile '+DATADG' size 1G;

Tablespace created.

SQL> alter session set container=CDB$ROOT;

Session altered.

SQL> create user c##mugdb identified by "Pwd_2077" default tablespace TB_MUG;

User created.

SQL> select con_id,tablespace_name from cdb_tablespaces;

    CON_ID TABLESPACE_NAME
---------- ------------------------------
         3 SYSTEM
         3 SYSAUX
         3 UNDOTBS1
         3 TEMP
         3 USERS
         3 TB_HUG
         3 TB_MUG
         1 SYSTEM
         1 SYSAUX
         1 UNDOTBS1
         1 TEMP

    CON_ID TABLESPACE_NAME
---------- ------------------------------
         1 USERS
         1 TB_MUG

13 rows selected.

SQL> grant connect,create session,resource to c##mugdb;

Grant succeeded.

References
【1】https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/CREATE-USER.html#GUID-F0246961-558F-480B-AC0F-14B50134621C
【2】https://dba.stackexchange.com/questions/159745/ora-00959-tablespace-does-not-exist-but-i-can-see-it-in-select
【3】https://www.cnblogs.com/aeolian/p/16473507.html
【4】https://www.cnblogs.com/kerrycode/p/3386917.html

你可能感兴趣的:(Oracle,数据库,sql,oracle)