今天開(kāi)發(fā)需要?jiǎng)h除AWS Redshift的一個(gè)歸檔表,但是直接drop發(fā)生了如下報(bào)錯(cuò),發(fā)現(xiàn)有其他對(duì)象依賴這個(gè)表,導(dǎo)致無(wú)法直接刪除,但是報(bào)錯(cuò)沒(méi)有直接顯示是什么對(duì)象依賴它,可能是有視圖,外鍵等約束
成都創(chuàng)新互聯(lián)是創(chuàng)新、創(chuàng)意、研發(fā)型一體的綜合型網(wǎng)站建設(shè)公司,自成立以來(lái)公司不斷探索創(chuàng)新,始終堅(jiān)持為客戶提供滿意周到的服務(wù),在本地打下了良好的口碑,在過(guò)去的十余年時(shí)間我們累計(jì)服務(wù)了上千家以及全國(guó)政企客戶,如成都食品包裝袋等企業(yè)單位,完善的項(xiàng)目管理流程,嚴(yán)格把控項(xiàng)目進(jìn)度與質(zhì)量監(jiān)控加上過(guò)硬的技術(shù)實(shí)力獲得客戶的一致贊美。
analyticsprod=# DROP TABLE IF EXISTS facts.auto_events_bk_20170223;
ERROR: cannot drop table auto_events_bk_20170223 because other objects depend on it
HINT: Use DROP ... CASCADE to drop the dependent objects too.
通過(guò)\d+ auto_events_bk_20170223 查看表結(jié)構(gòu),發(fā)現(xiàn)并沒(méi)有其他表的外鍵約束,所以排除;
然后通過(guò)\dv+命令在schema:facts下查看視圖,但是發(fā)現(xiàn)沒(méi)有任何view存在,但是view可能存在其他schema或db,
那么問(wèn)題來(lái)了,如何在整個(gè)數(shù)據(jù)庫(kù)中找到與這個(gè)表有依賴的的view?
這里AWS Redshift已經(jīng)給我們提供了一個(gè)好的方法,參考鏈接:https://docs.aws.amazon.com/redshift/latest/dg/r_DROP_TABLE.html
創(chuàng)建一個(gè)視圖find_depend:
create view find_depend as select distinct c_p.oid as tbloid, n_p.nspname as schemaname, c_p.relname as name, n_c.nspname as refbyschemaname, c_c.relname as refbyname, c_c.oid as viewoid from pg_catalog.pg_class c_p join pg_catalog.pg_depend d_p on c_p.relfilenode = d_p.refobjid join pg_catalog.pg_depend d_c on d_p.objid = d_c.objid join pg_catalog.pg_class c_c on d_c.refobjid = c_c.relfilenode left outer join pg_namespace n_p on c_p.relnamespace = n_p.oid left outer join pg_namespace n_c on c_c.relnamespace = n_c.oid where d_c.deptype = 'i'::"char" and c_c.relkind = 'v'::"char";
查詢視圖找到與表auto_events_bk_20170223相關(guān)的view:
analyticsprod=# select * from facts.find_depend where schemaname='facts' and name not in ('find_depend') order by name; tbloid | schemaname | name | refbyschemaname | refbyname | viewoid --------+------------+-------------------------+-----------------+-------------+--------- 879566 | facts | auto_events_bk_20170223 | public | map_routes2 | 965969 879566 | facts | auto_events_bk_20170223 | public | map_routes | 966155 879566 | facts | auto_events_bk_20170223 | public | map_edges | 1019697 (3 rows) analyticsprod=# set search_path to public; analyticsprod=# \dv List of relations schema | name | type | owner --------+-----------------------+------+------- public | map_edges | view | fengw public | map_edges_group | view | fengw public | map_route_edges_group | view | fengw public | map_routes | view | fengw public | map_routes2 | view | fengw public | map_routes_group | view | fengw (6 rows)
最后如果判斷這些相關(guān)的view沒(méi)有用的話,可以通過(guò)命令drop table auto_events_bk_20170223 cascade刪除表,包括視圖一同刪除。
當(dāng)前名稱:Redshiftdrop有依賴關(guān)系的表
本文URL:http://jinyejixie.com/article16/pppdgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開(kāi)發(fā)、搜索引擎優(yōu)化、網(wǎng)站制作、關(guān)鍵詞優(yōu)化、網(wǎng)站營(yíng)銷、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)