Retrieve all pages with last view date with total view count

Platform Notice: Data Center Only - This article only applies to Atlassian apps on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs 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

Summary

Data on how often a page is viewed and whether it has been viewed recently can be valuable in a variety of situations, such as pruning old content. This article contains instructions for retrieving this information from the database.

Solution

The below query will retrieve the following data:

  • Total Views Per Page

  • Page Title

  • Space Name

  • Space Key

  • Latest Viewed Date/Time

  • Content ID

Warning: Backup your database before proceeding.

This article describes how to run SQL UPDATE statements directly against the Confluence database to replace hard-coded links. UPDATE statements are not reversible — any mistake will modify your live data permanently. Before running any SQL in this article, create a full backup of your Confluence database. Test the queries in a staging environment first if possible.

SELECT count (*) as "TOTAL_VIEWS_PER_PAGE", c.title AS "PAGE_TITLE", s.spacename AS "SPACE_NAME", s.spacekey AS "SPACE_KEY", max(to_timestamp(aoe."EVENT_AT" / 1000)::timestamp) AS "LATEST_VIEWEDTIME", c.contentid AS "CONTENT_ID" FROM "AO_7B47A5_EVENT" aoe JOIN content c on aoe."CONTENT_ID" = c.contentid JOIN spaces s on c.spaceid = s.spaceid JOIN user_mapping um ON aoe."USER_KEY" = um.user_key WHERE aoe."NAME" = 'page_viewed' AND c.prevver is null AND c.CONTENT_STATUS = 'current' GROUP BY aoe."CONTENT_ID", c.spaceid, c.title, s.spacename, c.contentid, s.spacekey ORDER BY s.spacename;

More Information

For a broader overview on retrieving content analytics and additional queries to pull similar data, please see the below article:

Updated on September 26, 2025

Still need help?

The Atlassian Community is here for you.