How to check all the Bamboo database table constraints

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Fisheye および Crucible は除く

本記事で説明している手順は、現時点でのものとなります。そのため、一部のお客様で特定の状況下で動作したという報告がありますが、正式にサポートされているわけではなく、お客様の特定のシナリオで動作することを保証するものではありません。

本番環境での実施の前に一通り非本番環境で検証し、成功しなかった場合にはサポートされている代替案にフォール バックしてください。

また、アトラシアン サポートのサポート対象外のご質問の場合には、Community もご活用ください。

要約

This page covers database queries to extract all the constraints on Bamboo database tables. 

This is usually helpful in scenarios where we see some database failures on Bamboo logs where it says unique key or Integrity constraint violated and prints the constraint name, the below queries would be helpful to check the details related to the constraint like tables and columns involved which will help to investigate the problem area properly

[DelayedDeletionThread] [SqlExceptionHelper] ORA-02292: integrity constraint (BAMBOOAPP.FK_6KUY829K0Q2WB34WHK0GBHRS9) violated - child record found


環境

Bamboo connected to an external database.

ソリューション

Postgres

SELECT PGC.CONNAME      AS constraint_name,
       CCU.TABLE_SCHEMA AS table_schema,
       CCU.TABLE_NAME,
       CCU.COLUMN_NAME,
       CONTYPE,
       PG_GET_CONSTRAINTDEF(PGC.OID)
FROM   PG_CONSTRAINT PGC
       JOIN PG_NAMESPACE NSP
         ON NSP.OID = PGC.CONNAMESPACE
       JOIN PG_CLASS CLS
         ON PGC.CONRELID = CLS.OID
       LEFT JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE CCU
              ON PGC.CONNAME = CCU.CONSTRAINT_NAME
                 AND NSP.NSPNAME = CCU.CONSTRAINT_SCHEMA
ORDER  BY CCU.TABLE_NAME;                  

Oracle

SELECT CONS.OWNER           AS CHILD_OWNER,
       CONS.TABLE_NAME      AS CHILD_TABLE,
       CONS.CONSTRAINT_NAME AS CONSTAINT_NAME,
       CONS.CONSTRAINT_TYPE AS CONSTRAINT_TYPE,
       COL.OWNER            AS PARENT_OWNER,
       COL.TABLE_NAME       AS PARENT_TABLE,
       COL.COLUMN_NAME      AS COLUMN_NAME
FROM   DBA_CONS_COLUMNS COL,
       DBA_CONSTRAINTS CONS
WHERE  CONS.R_OWNER = COL.OWNER
       AND CONS.R_CONSTRAINT_NAME = COL.CONSTRAINT_NAME
       AND CONS.TABLE_NAME = 'yourTableName'; 

MySQL

SELECT TABLE_NAME,
       COLUMN_NAME,
       CONSTRAINT_NAME,
       REFERENCED_COLUMN_NAME,
       REFERENCED_TABLE_NAME
FROM   INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE  TABLE_NAME = 'yourTableName'; 

Please replace yourTableName with the Bamboo DB table name for which you are checking the constraint for example build




最終更新日 2022 年 11 月 30 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.