How to obtain a list of all projects and repositories from Bitbucket database and UI

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.

Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. 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.

*Except Fisheye and Crucible

Purpose

Whenever you have too many projects and too many repositories configured in the instance, having a better picture of how many of each you have can become challenging.

The purpose of this article is to help anybody that needs to retrieve a list of projects and repositories, along with personal repositories, directly from the database used by Bitbucket Server.

Advanced repository management available in Bitbucket Data Center 7.13

In 7.13, Bitbucket introduced Advanced repository management allowing you to more easily manage all of the repositories in your instance from the Repositories page in the Administration area.

Solution

Via database

Important Note on DB Queries

  • This Database Query / Functionality is not officially supported!

  • Atlassian is not responsible for translating queries for different databases.
    • This query should only be used as an example. Any desired adjustments should be checked with your local Database Administrator, including queries related to different DBMS that are not present/listed in this KB article, like Oracle Database. 
  • Atlassian will not be providing support for changes, adjustments, or inquiries regarding the below queries, as this is not part of our Atlassian Support Offerings.
    • Atlassian does not provide any support to sample database queries provided in our Knowledge Base documents. Extraction of data from Bitbucket should be performed using our REST API Documentation because we do not keep all data relationships in the DB. Many connections to data are handled in the code. The REST API can go through the code paths to get the data. A SQL would have to do that manually or, in some cases, it can’t be done at all.


Connect to the database used by Bitbucket Server using the database vendor supplied tool or maybe using a client like DBVisualizer and run the following SQL query:


SELECT 
       prj.name AS "Project / User Name"
     , prj.project_key AS "Project / User Key"
     , rep.name AS "Repository Name"
     , rep.slug AS "Repository Slug"
FROM repository rep 
INNER JOIN project prj ON rep.project_id = prj.id
ORDER BY prj.name, rep.name


Sample result:

Project / User Name  Project / User Key  Repository Name  Repository Slug  
-------------------  ------------------  ---------------  ---------------  
Project One          PROJ                Temp1            temp1            
Project Two          PT                  GitHook          githook          
~internal1           ~INTERNAL1          PersonalRepo     personalrepo     

Where

  • Project Project One has one repository, named Temp1.
  • Project Project Two has one repository, named GitHook.
  • User internal1 has a personal repository, named PersonalRepo.

If you would like to find out when a project or repository was created, you can use the queries below for Postgres and MSSQL databases:

  • Postgres 

    select
    	p."name" ,
    	p.project_key ,
    	a."ACTION" ,
    	cast(to_timestamp(a."ENTITY_TIMESTAMP" / 1000) as date) creation_date ,
    	a."USER_NAME"
    from
    	"AO_C77861_AUDIT_ENTITY" a ,
    	"project" p
    where
    	a."PRIMARY_RESOURCE_ID" = cast(p.id as varchar(255))
    	and "ACTION" in ('Project created', 'Repository created')
    	and cast(to_timestamp(a."ENTITY_TIMESTAMP" / 1000) as date) > '2023-12-31';
  • MSSQL 

    MSSQL




    SELECT
          a.PRIMARY_RESOURCE_ID
        , a.ID
        , p.name
        , p.project_key
        , a.USER_ID
        , a.USER_NAME
        , a.ACTION
        , CAST(DATEADD(SECOND, a.ENTITY_TIMESTAMP / 1000, '1970/1/1') AS DATE) creation_date
    FROM AO_C77861_AUDIT_ENTITY a
        JOIN project p ON a.PRIMARY_RESOURCE_ID = p.id
    WHERE
        CAST(DATEADD(SECOND, a.ENTITY_TIMESTAMP / 1000, '1970/1/1') AS DATE) > '2023-12-30'
        AND a.[ACTION] in ('Project created', 'Repository created')
    ORDER BY a.ENTITY_TIMESTAMP DESC;



Via UI

Steps:

  • The Administration COG wheel top right-click on it.
  • Troubleshooting and support tools bottom left
  • System Information Tab.
  • Scroll down, and you will see the Project count:




Last modified on Jan 24, 2025

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.