[postgres@db113 qianyi]$ psql -U postgres -d postgres
postgres=# drop user ctsdb;
ERROR: role "ctsdb" cannot be dropped because some objects depend on it
DETAIL: 1 object in database ctsdb
postgres=# \c ctsdb ctsdb
You are now connected to database "ctsdb" as user "ctsdb".
这里找不到任何对象。
重新删除ctsdb,还是同样的报错。
查询search_path,发现依赖于 xc_test用户下的 模式xc_test,
ctsdb=> show search_path;
search_path
-------------
xc_test
(1 row)
删除schema xc_test,这里还好是 xc_test用户创建的,不然就删掉了 xc_test模式下所有的对象。
ctsdb=> drop schema xc_test;
ERROR: must be owner of schema xc_test
修改ctsdb用户的search_path。
ctsdb=> set search_path = public;
SET
切换重新删除user ctsdb;
ctsdb=> \c ctsdb postgres
You are now connected to database "ctsdb" as user "postgres".
这时候找到了所依赖的对象
ctsdb=# drop user ctsdb;
ERROR: role "ctsdb" cannot be dropped because some objects depend on it
DETAIL: owner of function multinstance_init()
ctsdb=# \df multinstance_init();
List of functions
Schema | Name | Result data type | Argument data types | Type
--------+-------------------+------------------+---------------------+------
public | multinstance_init | text | | func
删除该函数,
ctsdb=# drop function public.multinstance_init();
DROP FUNCTION
删除该用户
ctsdb=# \c ctsdb postgres
You are now connected to database "ctsdb" as user "postgres".
ctsdb=# drop user ctsdb;
DROP ROLE
思考:
为什么这里不直接爆出来owner of function multinstance_init(),是否可以理解为登录的不是ctsdb数据库
postgres=# drop user ctsdb;
ERROR: role "ctsdb" cannot be dropped because some objects depend on it
DETAIL: 1 object in database ctsdb