How to Search Confluence for Uses of a Macro

Still need help?

The Atlassian Community is here for you.

Ask the community

Refer to the Document for Confluence 3.5 or later.

Expand to see pre-Confluence 3.5 SQL

Illegal Search Terms

Several terms are illegal to use when searching Confluence, like : or {. If you search for just the macro term, you're likely not to get the right search results. For example, searching for 'usage', which is the name of a macro but also a common English word, will not yield an accurate count.

Query the Database

If, for example, you want to search for the uses of the usage macro, you can search the database:

For large instances of Confluence, searches across the entire bodycontent table of the database might be environmentally taxing. You can try this on a test server.

You might want to use the SQL Plugin to automate this, or better yet the Macro usage stats plugin. Note that these are third party (unsupported) plugins.

SELECT * FROM BODYCONTENT WHERE BODY LIKE '%{usage}%'

If you want to get the last users or the creators of the pages where the noformat macro is used, you might run:

SELECT CREATOR FROM CONTENT WHERE CONTENTID IN (SELECT CONTENTID FROM BODYCONTENT WHERE BODY LIKE '%{noformat}%') GROUP BY CREATOR
SELECT LASTMODIFIER FROM CONTENT WHERE CONTENTID IN (SELECT CONTENTID FROM BODYCONTENT WHERE BODY LIKE '%{noformat}%') GROUP BY LASTMODIFIER

Listing the occurences of the excerpt include macro (MYSQL only)

select c.contentid, c.title, c.lastmoddate, c.lastmodifier, s.spacename from bodycontent bc join content c on bc.contentid=c.contentid join spaces s on s.spaceid = c.spaceid where c.contenttype='PAGE' and prevver is null and bc.body regexp '.*\{(excerpt-)?include*\}.*';

Logging Uses of a Macro

This information won't tell you how often a macro is invoked, but rather how often it appears on pages. For counting how often it's invoked (and measuring the time it takes to invoke it), check Identifying Slow Performing Macros.

Counting the Incidents of Invoked Logs

You can then grep the logs like:

grep -c "{usage" atlassian-confluence.log
 
Last modified on Mar 3, 2023

Was this helpful?

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