Confluence SQL Query of Page related data in the database
Asked by Tim Hailey:

I am trying to construct a SQL query that will provide some inventory of a Confluence space from the database, so that I can clean it up based on the results.  

Any suggestions on how to retrieve this specific data from a Confluence space in the Confluence database?

1. Space Name
2. Page Name
3. Page URL
4. Page Created Date
5. Page Created By (optional)
6. Last Edited  

Thank you,  

Tim Hailey  
Atlassian Systems Administrator


Answers:
author: Srinatha T
body: [@Tim Hailey](/t5/user/viewprofilepage/user-id/3298105) ,

That should be achievable I will update you once i have it modified.

Thanks,

Srinath T

comments: author: Tim Hailey
body: Hello [@Srinatha T](/t5/user/viewprofilepage/user-id/4686256)  

Did you ever get a chance to look at this?  

I need to search for only 1 space name in the database. Do you know how I could get these same results but for just a specified space name?  

Thank you,  

Tim Hailey


author: Srinatha T
body: [@Tim Hailey](/t5/user/viewprofilepage/user-id/3298105) ,

If you are looking for individual space details they you need to enter the space id manually.

Step 1: Get the sapce id from below query:

* SELECT spaceid, spacename, spacekey FROM spaces;

Step2: change the space id and run the query.

* SELECT title, contentid, lastmoddate, content_status FROM content WHERE spaceid = \<spaceId\> and contenttype = 'PAGE' and content_status in ('current', 'deleted')

I hope that helps. Have a good day!

Thanks,

Srinath T

comments: author: Tim Hailey
body: [@Srinatha T](/t5/user/viewprofilepage/user-id/4686256)  

Thank you. This gives me results for the specified space id but not for what I had originally requested in this thread.   

Can you please help with this query? I am trying to clean up the Space based on the results.

1. Space Name or Space Key or Space Id (**I only need results for 1 specified space**)
2. **Page Name**
3. **Page URL**
4. **Page Created Date**
5. **Last Edited date**

Thank you very much for your assistance.  

Tim Hailey

<br />

<br />


author: Srinatha T
body: [@Tim Hailey](/t5/user/viewprofilepage/user-id/3298105) ,

The previous query gives all the details . You can simply modify it like below to get it for one space, just change the space name and you will get details for that space.

SELECT c.title, s.spacename AS SpaceName, s.spacekey, u.username AS Creator, c.creationdate, c.lastmoddate, um.username AS LastModifier FROM content c join spaces s ON c.spaceid = s.spaceid JOIN user_mapping u ON c.creator = u.user_key JOIN user_mapping um ON c.lastmodifier = um.user_key WHERE c.prevver IS NULL AND c.contenttype = 'PAGE' AND c.content_status = 'current' and spacename = 'MySpace';

Thanks,

Srinath T


author: Srinatha T
body: [@Tim Hailey](/t5/user/viewprofilepage/user-id/3298105) ,

I could not work on it during weekend as its festival time here in India.

Checking now.

Thanks,

Srinath T


author: Srinatha T
body: Hi [@Tim Hailey](/t5/user/viewprofilepage/user-id/3298105) ,

Welcome to Atlassian community.

Below is the query.

SELECT c.title, s.spacename AS SpaceName, s.spacekey, u.username AS Creator, c.creationdate, c.lastmoddate, um.username AS LastModifier FROM content c join spaces s ON c.spaceid = s.spaceid JOIN user_mapping u ON c.creator = u.user_key JOIN user_mapping um ON c.lastmodifier = um.user_key WHERE c.prevver IS NULL AND c.contenttype = 'PAGE' AND c.content_status = 'current';

I hope the above helps. Have a good day!

Thanks,

Srinath T

comments: author: Tim Hailey
body: [@Srinatha T](/t5/user/viewprofilepage/user-id/4686256)  

This gets me most of the way there. However, I need to search for only 1 space name in the database. Do you know how I could get these same results but for just a specified space name?  

Thank you so much,  

Tim Hailey


author: Tim Hailey
body: [@Srinatha T](/t5/user/viewprofilepage/user-id/4686256) Thank you. I look forward to your next response.


author: Moses Ebrahimi
body: Hi [@Srinatha T](/t5/user/viewprofilepage/user-id/4686256)

This was very helpful for my case too! thanks for the information. Just a quick question, can this query modified to return (ONLY) last page that been updated along with list of spaces?

I think this query returns all spaces as well as all pages and their last update etc, I'm looking for a way to capture all spaces but only last page updated record.

Thank you

Moses


author: Muhammad Yasin
body: Suggested to our Service team to done as soon as possible.

And report to service center as soon as possible.

Thansl

Muhammad Yasin


Tags: confluence-server

server