Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >关于drop user的cascade选项解惑(52天)

关于drop user的cascade选项解惑(52天)

作者头像
jeanron100
发布于 2018-03-13 10:36:11
发布于 2018-03-13 10:36:11
1.8K0
举报

在数据库中,有时候需要删除用户,大多数时候都需要使用cascade选项,有些时候却不需要,想知道在这个简单的命令之后数据库倒底在干什么, 这时候给一些指定的操作加上trace就跟把那层纱窗揭开一样,可以很清楚看到数据库倒底在干些什么。 10046,sql_trace等都是一些不错的选择。 首先来复现一下这个问题。‘ 创建一个新用户,然后马上删除。 SQL> create user jeanron identified by jeanron; User created. SQL> drop user jeanron; User dropped. ########################### 可以看到删除是不需要cascade选项的。如果想加cascade选项,会不会有问题呢。 SQL> create user jeanron identified by jeanron; User created. SQL> drop user jeanron cascade; User dropped. ########################### 可以看到是没有问题的,下面来复现ORA-01922这个错误。 SQL> create user jeanron identified by jeanron; User created. SQL> grant connect,resource to jeanron; Grant succeeded. SQL> conn jeanron/jeanron Connected. SQL> create table tt as select *from cat; Table created. SQL> conn / as sysdba Connected. SQL> drop user jeanron; drop user jeanron * ERROR at line 1: ORA-01922: CASCADE must be specified to drop 'JEANRON' ############################ 给这条命令做一个sql_trace,或者10046事件 如果在做sql_trace,10046事件的时候出现下面的情况。 SQL> alter session set sql_trace=true; ERROR: ORA-01031: insufficient privileges SQL> alter session set events '10046 trace name context forever,level 12'; ERROR: ORA-01031: insufficient privileges 只需要赋予alter session的权限就可以了。 SQL> grant alter session to jeanron; Grant succeeded. SQL> alter session set events '10046 trace name context forever,level 12'; Session altered. SQL> drop user jeanron; drop user jeanron * ERROR at line 1: ORA-01922: CASCADE must be specified to drop 'JEANRON' SQL> alter session set events '10046 trace name context off'; Session altered. 在trace目录下找到最新的trace日志,使用tkprof来格式化一下。 [ora11g@rac1 trace]$ tkprof TEST01_ora_5888.trc output = b.log TKPROF: Release 11.2.0.3.0 - Development on Wed Apr 23 07:42:26 2014 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. 可以看到格式化之后的日志文件内容就比较清晰了。可以在开头就看到如下的一段,命令开始了。 SQL ID: 6vu28ambaxjjh Plan Hash: 0 drop user jeanron call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 2 0.00 0.00 0 0 0 0 Misses in library cache during parse: 1 Optimizer mode: ALL_ROWS Parsing user id: SYS Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net break/reset to client 2 0.00 0.00 SQL*Net message to client 1 0.00 0.00 SQL*Net message from client 1 13.27 13.27 ******************************************************************************** ..... 如下的部分就是一些相应的递归sql。 select user#,password,datats#,tempts#,type#,defrole,resource$, ptime, decode(defschclass,NULL,'DEFAULT_CONSUMER_GROUP',defschclass),spare1,spare4, ext_username,spare2 from user$ where name=:1 call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 1 0.00 0.00 0 2 0 1 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 3 0.00 0.00 0 2 0 1 Misses in library cache during parse: 0 Optimizer mode: CHOOSE Parsing user id: SYS (recursive depth: 1) Number of plan statistics captured: 1 Rows (1st) Rows (avg) Rows (max) Row Source Operation ---------- ---------- ---------- --------------------------------------------------- 1 1 1 TABLE ACCESS BY INDEX ROWID USER$ (cr=2 pr=0 pw=0 time=152 us cost=1 size=101 card=1) 1 1 1 INDEX UNIQUE SCAN I_USER1 (cr=1 pr=0 pw=0 time=98 us cost=0 size=0 card=1)(object id 46) ********************************************************************************

可以看到在最后面有这样一条sql的信息。 SQL ID: 8mj6vafkkhyr4 Plan Hash: 310931108 select null from obj$ where owner#=:1 and type#!=10 union all select null from link$ where owner#=:1 union all select null from streams$_capture_process where capture_userid=:1 union all select null from streams$_apply_process where apply_userid=:1 union all select null from wri$_sqlset_definitions s,user$ u where s.owner = u.name and u.user#=:1 union all select null from wri$_adv_tasks where owner#=:1 call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 1 0.00 0.00 0 0 0 0 Fetch 1 0.00 0.00 0 41 0 1 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 3 0.00 0.00 0 41 0 1 Misses in library cache during parse: 0 Optimizer mode: CHOOSE Parsing user id: SYS (recursive depth: 1) Number of plan statistics captured: 1 Rows (1st) Rows (avg) Rows (max) Row Source Operation ---------- ---------- ---------- --------------------------------------------------- 1 1 1 UNION-ALL (cr=41 pr=0 pw=0 time=2554 us) 1 1 1 INDEX FAST FULL SCAN I_OBJ1 (cr=41 pr=0 pw=0 time=2510 us cost=12 size=10367 card=1481)(object id 36) 0 0 0 INDEX RANGE SCAN I_LINK1 (cr=0 pr=0 pw=0 time=0 us cost=0 size=13 card=1)(object id 138) 0 0 0 TABLE ACCESS FULL STREAMS$_CAPTURE_PROCESS (cr=0 pr=0 pw=0 time=0 us cost=2 size=13 card=1) 0 0 0 TABLE ACCESS FULL STREAMS$_APPLY_PROCESS (cr=0 pr=0 pw=0 time=0 us cost=2 size=13 card=1) 0 0 0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us) 0 0 0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us cost=0 size=34 card=1) 0 0 0 INDEX FULL SCAN WRI$_SQLSET_DEFINITIONS_IDX_01 (cr=0 pr=0 pw=0 time=0 us cost=0 size=17 card=1)(object id 6242) 0 0 0 INDEX UNIQUE SCAN I_USER1 (cr=0 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 46) 0 0 0 TABLE ACCESS BY INDEX ROWID USER$ (cr=0 pr=0 pw=0 time=0 us cost=0 size=17 card=1) 0 0 0 INDEX RANGE SCAN WRI$_ADV_TASKS_IDX_02 (cr=0 pr=0 pw=0 time=0 us cost=1 size=38 card=19)(object id 5811) 自己好好琢磨了下,这里面还这有些文章。它会从回收站,各数据字典基表中查询是否有相应的Object和db link,stream对象。 为了方便查看起见,我把sql整理了一下,可以用如下的方式。如果有返回结果,说明需要cascade选项。 column userid new_value userid format 999999; select user# userid from user$ where name='A'; select 'drop user need cascade option' from obj$ where owner#=&userid and type#!=10 union all select 'drop user need cascade option' from link$ where owner#=&userid union all select 'drop user need cascade option' from streams$_capture_process where capture_userid=&userid union all select 'drop user need cascade option' from streams$_apply_process where apply_userid=&userid union all select 'drop user need cascade option' from wri$_sqlset_definitions s,user$ u where s.owner = u.name and u.user#=&userid union all select 'drop user need cascade option' from wri$_adv_tasks where owner#=&userid / N - 如果返回now rows selected 就表明不需要cascade. SQL> select 'drop user need cascade option' 2 from 3 obj$ where owner#=&userid and type#!=10 4 union all 5 select 'drop user need cascade option' from link$ where 6 owner#=&userid 7 union all 8 select 'drop user need cascade option' from streams$_capture_process where 9 capture_userid=&userid 10 union all 11 select 'drop user need cascade option' from streams$_apply_process where 12 apply_userid=&userid 13 union all 14 select 'drop user need cascade option' from wri$_sqlset_definitions s,user$ 15 u where s.owner = u.name and u.user#=&userid 16 union all 17 select 'drop user need cascade option' from 18 wri$_adv_tasks where owner#=&userid 19 / old 3: obj$ where owner#=&userid and type#!=10 new 3: obj$ where owner#= 53 and type#!=10 old 6: owner#=&userid new 6: owner#= 53 old 9: capture_userid=&userid new 9: capture_userid= 53 old 12: apply_userid=&userid new 12: apply_userid= 53 old 15: u where s.owner = u.name and u.user#=&userid new 15: u where s.owner = u.name and u.user#= 53 old 18: wri$_adv_tasks where owner#=&userid new 18: wri$_adv_tasks where owner#= 53 no rows selected

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2014-04-24,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 杨建荣的学习笔记 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
部署keystone
完成基础环境配置后,应先部署keystone组件,只需在controller节点上部署。 1、创建数据库实例和数据库用户 在MySQL中创建数据库keystone,同时创建数据库用户,并授权权限。 [root@controller ~]# mysql -u root -p000000 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 15 Server version: 10.3.20-MariaDB MariaDB Server
宝耶需努力
2022/12/13
3120
openstack安装(14)
[root@controller ~]# vim /usr/share/keystone/keystone-dist-paste.ini#因为安全性的原因,关闭临时认证令牌机制,删除 以下三个段中 admin_token_auth字段
陈不成i
2021/05/06
5040
玩转企业云计算平台系列(三):Openstack 身份认证服务 Keystone
Keystone (OpenStack Identity Service)是OpenStack中的一个独立的提供安全认证的模块,主要负责openstack用户的身份认证、令牌管理、提供访问资源的服务目录、以及基于用户角色的访问控制。
民工哥
2023/12/28
1.6K0
玩转企业云计算平台系列(三):Openstack 身份认证服务 Keystone
OpenStack运维之安装Glance
Glance(OpenStack Image Service)是为虚拟机提供发现,注册,和下载镜像的服务。Glance 提供了虚拟机镜像的集中存储。通过 Glance 的 RESTful API,可以查询镜像元数据、下载镜像。虚拟机的镜像可以很方便的存储在各种地方,从简单的文件系统到对象存储系统(比如 OpenStack Swift)。
王先森sec
2023/04/24
7730
OpenStack运维之安装Glance
Opensack-T版脚本安装
配置 ;/etc/my.cnf.d/openstack.cnf``/etc/my.cnf.d/
误入歧途
2024/05/08
1330
python-troveclient源代
client.Client返回值为troveclient.v1.client.Client(option.os_database_api_version, ...),以上代码实际相当于调用
py3study
2020/01/15
6170
OpenStack运维之安装Placement服务
Placement服务跟踪资源(比如计算节点,存储资源池,网络资源池等)的使用情况,提供自定义资源的能力,为分配资源提供服务。
王先森sec
2023/04/24
1.2K0
OpenStack安装流程(juno版)- 添加认证服务(keystone)
可使用OpenStack云服务的个人、系统或服务的数字化形象。(Digital representation of a person, system, or service who uses OpenStack cloud services. )
全栈程序员站长
2022/06/29
1K0
Chapter 3 OpenStack认
Chapter 3 OpenStack认证服务(Identity service)
py3study
2020/01/09
5590
openstack系列- keystone部署文档
rabbitmqctl 命令参考 rabbitmq-plugins list 查看 rabbitmq 插件列表 rabbitmq-plugins enable rabbitmq_management 开启 web 管理功能 rabbitmqctl list_users 查看用户列表 rabbitmqctl set_user_tags admin administrator 修改用户角色
cuijianzhe
2022/06/14
1.1K0
OpenStack踩坑之路(2)
身份服务通常是用户与之交互的第一个服务。一旦通过身份验证,最终用户就可以使用他们的身份访问其他OpenStack服务。同样,其他OpenStack服务利用身份服务来确保用户是他们所说的人,并发现部署中其他服务的位置。身份识别服务还可以与一些外部用户管理系统(如LDAP)集成。
没有故事的陈师傅
2019/07/27
2.4K0
Centos7上部署openstack ocata配置详解
之前写过一篇《openstack mitaka 配置详解》然而最近使用发现阿里不再提供m版本的源,所以最近又开始学习ocata版本,并进行总结,写下如下文档
yaohong
2019/09/11
1.7K0
Centos7上部署openstack ocata配置详解
玩转企业云计算平台系列(十八):Openstack 部署常见问题及解决方案
配置网络时,需要先使用dhcp,获取虚拟机网卡ip,然后再使用static的方式,配置网卡ip。如果直接使用dhcp的方式,可能会导致该ip无法使用,无法ping通。
民工哥
2024/01/18
6530
玩转企业云计算平台系列(十八):Openstack 部署常见问题及解决方案
OpenStack Juno系列之控制节点搭建
apt-get install python-software-properties
DevinGeng
2019/04/09
8750
玩转企业云计算平台系列(十一):Openstack 编排服务 Heat
OpenStack Heat 是一个基于模板的编排服务,用于自动化部署和管理基础设施资源。它允许用户通过编写模板文件来描述所需的基础设施资源和配置,然后使用 Heat 引擎来解析和执行这些模板,自动创建、配置和管理云环境中的资源。
民工哥
2024/01/18
1.5K0
玩转企业云计算平台系列(十一):Openstack 编排服务 Heat
CentOS 7部署OpenStack(
[root@controller ~]# mysql -u root -p -e "CREATE DATABASEglance;"
py3study
2020/01/09
9820
OpenStack踩坑之路(3)
使用OpenStack Compute来托管和管理云计算系统。OpenStack Compute是基础架构即服务(IaaS)系统的重要组成部分。主要模块是用Python实现的。
没有故事的陈师傅
2019/07/28
1.6K0
OpenStack云计算之路-Mitaka 版本
1.1 云计算简介 云计算(英语:cloud computing ),是一种基于互联网的计算方式,通过这种方式,共享的软硬件资源和信息可以按需求提供给计算机各种终端和其他设备。 云计算是继1980年代
惨绿少年
2018/03/30
6.4K0
Ubuntu 20.04 搭建OpenStack Yoga(allinone)
很多文章都是devstack安装的allinone,我这里使用源码组件手动安装。
全栈程序员站长
2022/11/17
3.8K0
部署Glance
1、创建glance数据库、用户、表 登录MySQL客户端,创建数据库和用户,并授权相应的数据库权限 [root@controller ~]# mysql -u root -p000000 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 22 Server version: 10.3.20-MariaDB MariaDB Server
宝耶需努力
2022/12/13
4420
相关推荐
部署keystone
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档