<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Alfresco: some useful database queries	</title>
	<atom:link href="https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/</link>
	<description></description>
	<lastBuildDate>Fri, 17 Jan 2025 11:39:57 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>
		By: Morgan Patou		</title>
		<link>https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3649</link>

		<dc:creator><![CDATA[Morgan Patou]]></dc:creator>
		<pubDate>Fri, 17 Jan 2025 11:39:57 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3649</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3648&quot;&gt;Mike&lt;/a&gt;.

Hello,

As mentioned in some other comments, as soon as you want recursive queries, it becomes pretty complex. The DB is usually not the easiest way to get information in this case, as it&#039;s often easier through Share or a Search query. But then if you want details on versions, that means you probably cannot use Search queries. I still think it would be easier to use the JavaScript Console in Share to get the details that you are looking for (maybe first a query to find all Nodes in the folder, and then parsing these with the JavaScript Console to extract the version details needed).

In you want to use a SQL query non-the-less, then it would be something that mixes both queries from the section &quot;All documents from a custom type with version history&quot; as well as &quot;Recursively find the number of childs&quot;. First in the recursive, you would get Node ID and then in the second time, you would retrieve all versions for all Node IDs from the list and display that as the outcome.

Also, please note that you need to take care of the metamodel, if you are using the default cm:content type or some custom ones.


As you said &quot;in a certain folder&quot;, I assumed above you wanted recursive parsing. If you don&#039;t want that and simply want the direct content of a folder, then it&#039;s much easier as you can just take the query from &quot;All documents from a custom type with version history&quot; and add an additional where clause to specify that the parent_node_id should be a specific value.

Regards,
Morgan]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3648">Mike</a>.</p>
<p>Hello,</p>
<p>As mentioned in some other comments, as soon as you want recursive queries, it becomes pretty complex. The DB is usually not the easiest way to get information in this case, as it&#8217;s often easier through Share or a Search query. But then if you want details on versions, that means you probably cannot use Search queries. I still think it would be easier to use the JavaScript Console in Share to get the details that you are looking for (maybe first a query to find all Nodes in the folder, and then parsing these with the JavaScript Console to extract the version details needed).</p>
<p>In you want to use a SQL query non-the-less, then it would be something that mixes both queries from the section &#8220;All documents from a custom type with version history&#8221; as well as &#8220;Recursively find the number of childs&#8221;. First in the recursive, you would get Node ID and then in the second time, you would retrieve all versions for all Node IDs from the list and display that as the outcome.</p>
<p>Also, please note that you need to take care of the metamodel, if you are using the default cm:content type or some custom ones.</p>
<p>As you said &#8220;in a certain folder&#8221;, I assumed above you wanted recursive parsing. If you don&#8217;t want that and simply want the direct content of a folder, then it&#8217;s much easier as you can just take the query from &#8220;All documents from a custom type with version history&#8221; and add an additional where clause to specify that the parent_node_id should be a specific value.</p>
<p>Regards,<br />
Morgan</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Mike		</title>
		<link>https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3648</link>

		<dc:creator><![CDATA[Mike]]></dc:creator>
		<pubDate>Fri, 17 Jan 2025 03:14:11 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3648</guid>

					<description><![CDATA[Hi Morgan, can you create a query that lists all documents and historical versions in a certain folder?]]></description>
			<content:encoded><![CDATA[<p>Hi Morgan, can you create a query that lists all documents and historical versions in a certain folder?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Morgan Patou		</title>
		<link>https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3639</link>

		<dc:creator><![CDATA[Morgan Patou]]></dc:creator>
		<pubDate>Mon, 13 Jan 2025 15:42:50 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3639</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3638&quot;&gt;wulala&lt;/a&gt;.

Hello,
Sorry but I didn&#039;t get the question. Namespaces are related to metamodels (i.e. for example which kind of nodes you want to get, cm:content, cm:folder, custom types, ...) while SpacesStore is related to the storage / file system where real document contents are. These 2 things have nothing in common so I&#039;m not sure what you mean. As mentioned in some other comments, by default, a node using &quot;workspace://SpacesStore&quot; for the storage is the latest version of a document&#039;s content while something that uses &quot;workspace://version2Store&quot; would be a previous version of a content.
Regards,
Morgan Patou]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3638">wulala</a>.</p>
<p>Hello,<br />
Sorry but I didn&#8217;t get the question. Namespaces are related to metamodels (i.e. for example which kind of nodes you want to get, cm:content, cm:folder, custom types, &#8230;) while SpacesStore is related to the storage / file system where real document contents are. These 2 things have nothing in common so I&#8217;m not sure what you mean. As mentioned in some other comments, by default, a node using &#8220;workspace://SpacesStore&#8221; for the storage is the latest version of a document&#8217;s content while something that uses &#8220;workspace://version2Store&#8221; would be a previous version of a content.<br />
Regards,<br />
Morgan Patou</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: wulala		</title>
		<link>https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3638</link>

		<dc:creator><![CDATA[wulala]]></dc:creator>
		<pubDate>Mon, 13 Jan 2025 15:18:43 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3638</guid>

					<description><![CDATA[May I ask that the namespaces associated with the parent_node_id corresponding to the folder on the alfresco Web page are all SpacesStore. What is the relationship between the earlier version of that file and the latest version in the database?]]></description>
			<content:encoded><![CDATA[<p>May I ask that the namespaces associated with the parent_node_id corresponding to the folder on the alfresco Web page are all SpacesStore. What is the relationship between the earlier version of that file and the latest version in the database?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Pramod		</title>
		<link>https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3468</link>

		<dc:creator><![CDATA[Pramod]]></dc:creator>
		<pubDate>Wed, 18 Sep 2024 07:52:33 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3468</guid>

					<description><![CDATA[Alfresco psql query to get user and their email ids

SELECT 
    n.id AS node_id
    , concat(s.protocol,&#039;://&#039;,s.identifier,&#039;/&#039;, n.uuid) AS node_ref
    , np1.string_value AS username
    , np2.string_value AS email
FROM alf_node n
JOIN alf_store s ON (n.store_id=s.id)
-- filter on type person
JOIN alf_qname qn ON (n.type_qname_id=qn.id AND qn.local_name=&#039;person&#039; 
    AND ns_id=(SELECT id FROM alf_namespace WHERE uri=&#039;http://www.alfresco.org/model/content/1.0&#039;)
 )
-- join property userName
left JOIN alf_node_properties np1 ON (n.id=np1.node_id 
    AND np1.qname_id =(SELECT id FROM alf_qname WHERE local_name=&#039;userName&#039;
        AND ns_id=(SELECT id FROM alf_namespace WHERE uri=&#039;http://www.alfresco.org/model/content/1.0&#039;)
        )
    )
-- join property email
left JOIN alf_node_properties np2 ON (n.id=np2.node_id 
    AND np2.qname_id =(SELECT id FROM alf_qname WHERE local_name=&#039;email&#039;
        AND ns_id=(SELECT id FROM alf_namespace WHERE uri=&#039;http://www.alfresco.org/model/content/1.0&#039;)
        )
    )
ORDER BY np1.string_value;]]></description>
			<content:encoded><![CDATA[<p>Alfresco psql query to get user and their email ids</p>
<p>SELECT<br />
    n.id AS node_id<br />
    , concat(s.protocol,&#8217;://&#8217;,s.identifier,&#8217;/&#8217;, n.uuid) AS node_ref<br />
    , np1.string_value AS username<br />
    , np2.string_value AS email<br />
FROM alf_node n<br />
JOIN alf_store s ON (n.store_id=s.id)<br />
&#8212; filter on type person<br />
JOIN alf_qname qn ON (n.type_qname_id=qn.id AND qn.local_name=&#8217;person&#8217;<br />
    AND ns_id=(SELECT id FROM alf_namespace WHERE uri=&#8217;http://www.alfresco.org/model/content/1.0&#8242;)<br />
 )<br />
&#8212; join property userName<br />
left JOIN alf_node_properties np1 ON (n.id=np1.node_id<br />
    AND np1.qname_id =(SELECT id FROM alf_qname WHERE local_name=&#8217;userName&#8217;<br />
        AND ns_id=(SELECT id FROM alf_namespace WHERE uri=&#8217;http://www.alfresco.org/model/content/1.0&#8242;)<br />
        )<br />
    )<br />
&#8212; join property email<br />
left JOIN alf_node_properties np2 ON (n.id=np2.node_id<br />
    AND np2.qname_id =(SELECT id FROM alf_qname WHERE local_name=&#8217;email&#8217;<br />
        AND ns_id=(SELECT id FROM alf_namespace WHERE uri=&#8217;http://www.alfresco.org/model/content/1.0&#8242;)<br />
        )<br />
    )<br />
ORDER BY np1.string_value;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Morgan Patou		</title>
		<link>https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3356</link>

		<dc:creator><![CDATA[Morgan Patou]]></dc:creator>
		<pubDate>Tue, 02 Jul 2024 10:43:41 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3356</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3355&quot;&gt;Collins&lt;/a&gt;.

Hi Collins,

I&#039;m not sure I got the question. The query you mentioned comes from this blog in the section &quot;Listing all groups and their membership&quot;. As the name implies, this query will list all existing groups that have at least 1 member inside. There is no direct relation between authorities (groups/users) and permissions on their own. A group/user is assigned to a &quot;role&quot; (has permissions through an ACL) on a specific Node. But you need a node to have a link between an authority and a permission set.

To list permissions on a node, I also already provided a query under the section &quot;Listing the permissions assigned to a specific Alfresco node&quot;. I believe that&#039;s what you wanted to see. You just select a Node ID (UUID) and execute this query for it. It will tell you which group/user has which access level on that specific node.

Regards,
Morgan]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3355">Collins</a>.</p>
<p>Hi Collins,</p>
<p>I&#8217;m not sure I got the question. The query you mentioned comes from this blog in the section &#8220;Listing all groups and their membership&#8221;. As the name implies, this query will list all existing groups that have at least 1 member inside. There is no direct relation between authorities (groups/users) and permissions on their own. A group/user is assigned to a &#8220;role&#8221; (has permissions through an ACL) on a specific Node. But you need a node to have a link between an authority and a permission set.</p>
<p>To list permissions on a node, I also already provided a query under the section &#8220;Listing the permissions assigned to a specific Alfresco node&#8221;. I believe that&#8217;s what you wanted to see. You just select a Node ID (UUID) and execute this query for it. It will tell you which group/user has which access level on that specific node.</p>
<p>Regards,<br />
Morgan</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Collins		</title>
		<link>https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3355</link>

		<dc:creator><![CDATA[Collins]]></dc:creator>
		<pubDate>Tue, 02 Jul 2024 10:04:56 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3355</guid>

					<description><![CDATA[Hello. How can I get groups, users, and roles using 

&lt;code&gt;SELECT ca.parent_node_id AS &quot;Parent ID&quot;,
  ca.child_node_id AS &quot;Child ID&quot;,
  p.string_value AS &quot;Group Name&quot;,
  ca.qname_localname AS &quot;User Name&quot;
FROM alf_child_assoc AS ca,
  alf_node AS n1,
  alf_node AS n2,
  alf_node_properties AS p
WHERE n1.id=ca.parent_node_id
  AND n2.id=ca.child_node_id
  AND p.node_id=n1.id
  AND n1.type_qname_id IN (SELECT id FROM alf_qname WHERE local_name=&#039;authorityContainer&#039;)
  AND n2.type_qname_id IN (SELECT id FROM alf_qname WHERE local_name=&#039;person&#039;)
  AND p.qname_id IN (SELECT id FROM alf_qname WHERE local_name=&#039;authorityName&#039;)
ORDER BY p.string_value, ca.qname_localname;&lt;/code&gt;]]></description>
			<content:encoded><![CDATA[<p>Hello. How can I get groups, users, and roles using </p>
<p><code>SELECT ca.parent_node_id AS "Parent ID",<br />
  ca.child_node_id AS "Child ID",<br />
  p.string_value AS "Group Name",<br />
  ca.qname_localname AS "User Name"<br />
FROM alf_child_assoc AS ca,<br />
  alf_node AS n1,<br />
  alf_node AS n2,<br />
  alf_node_properties AS p<br />
WHERE n1.id=ca.parent_node_id<br />
  AND n2.id=ca.child_node_id<br />
  AND p.node_id=n1.id<br />
  AND n1.type_qname_id IN (SELECT id FROM alf_qname WHERE local_name='authorityContainer')<br />
  AND n2.type_qname_id IN (SELECT id FROM alf_qname WHERE local_name='person')<br />
  AND p.qname_id IN (SELECT id FROM alf_qname WHERE local_name='authorityName')<br />
ORDER BY p.string_value, ca.qname_localname;</code></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Morgan Patou		</title>
		<link>https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3228</link>

		<dc:creator><![CDATA[Morgan Patou]]></dc:creator>
		<pubDate>Thu, 25 Apr 2024 14:52:46 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3228</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3227&quot;&gt;sergiobaiao&lt;/a&gt;.

Hi sergiobaiao,

For the query regarding all but the latest version, you have the needed details in this blog post already. If you take the query to list all documents bigger than 40Mb (for example) and execute it, you will see that the 2nd column &quot;Store Name&quot; changes and as it&#039;s written in blog post and in the comment, &quot;workspace://SpacesStore&quot; is the latest version of the document while &quot;workspace://version2Store&quot; is an old version of a document. So you could select only the entries from the &quot;version2Store&quot; identifier column and that would normally be non-latest version of documents.

You should not remove versions from the database. As it was said in the discord, you should use API (REST-API or similar) to get the list of old versions of a document and delete them. If you don&#039;t want to do it properly through API, for your space problem, a quick&#038;dirty workaround could be to fetch all filesystem path for all non-latest versions of documents and replace the real content (on the alf-data folder) by a dummy one (e.g. an empty file - then reflect this in the metadata maybe?).

Regards,
Morgan]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3227">sergiobaiao</a>.</p>
<p>Hi sergiobaiao,</p>
<p>For the query regarding all but the latest version, you have the needed details in this blog post already. If you take the query to list all documents bigger than 40Mb (for example) and execute it, you will see that the 2nd column &#8220;Store Name&#8221; changes and as it&#8217;s written in blog post and in the comment, &#8220;workspace://SpacesStore&#8221; is the latest version of the document while &#8220;workspace://version2Store&#8221; is an old version of a document. So you could select only the entries from the &#8220;version2Store&#8221; identifier column and that would normally be non-latest version of documents.</p>
<p>You should not remove versions from the database. As it was said in the discord, you should use API (REST-API or similar) to get the list of old versions of a document and delete them. If you don&#8217;t want to do it properly through API, for your space problem, a quick&amp;dirty workaround could be to fetch all filesystem path for all non-latest versions of documents and replace the real content (on the alf-data folder) by a dummy one (e.g. an empty file &#8211; then reflect this in the metadata maybe?).</p>
<p>Regards,<br />
Morgan</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: sergiobaiao		</title>
		<link>https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3227</link>

		<dc:creator><![CDATA[sergiobaiao]]></dc:creator>
		<pubDate>Thu, 25 Apr 2024 12:25:04 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-3227</guid>

					<description><![CDATA[Hi there,

Can you please create a query that would show all but the latest versions of each document? And maybe one that removes all versions but the latest?]]></description>
			<content:encoded><![CDATA[<p>Hi there,</p>
<p>Can you please create a query that would show all but the latest versions of each document? And maybe one that removes all versions but the latest?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Morgan Patou		</title>
		<link>https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-2952</link>

		<dc:creator><![CDATA[Morgan Patou]]></dc:creator>
		<pubDate>Thu, 16 Nov 2023 14:56:32 +0000</pubDate>
		<guid isPermaLink="false">https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-2952</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-2950&quot;&gt;SG@1234@&lt;/a&gt;.

Hello,

The list of people who accessed the site or uploaded/downloaded documents within the site wouldn&#039;t be available by default since the audit is turned off. It&#039;s only if you have the audit enabled that this would be stored. If you have the audit enabled, then I would say that the way-to-go is to check the REST-API, c.f. https://docs.alfresco.com/content-services/latest/admin/audit/ &#038;&#038; https://api-explorer.alfresco.com/api-explorer/... If you really want to use the DB, then it should be data from the alf_audit_* tables (in conjunction with other tables as shown in the blog to get properties and find out on which site it is). The DB isn&#039;t really efficient for recursive things since Associations in Alfresco will only work with the direct parent folder. So if you want to look for all people who uploaded/downloaded from a Site, you need to find the Site Node, then list all its children and all their children&#039;s children and all their children&#039;s children&#039;s children and etc...

For the total size/number of files in a Site, it&#039;s the same as well... Doing the total for all Alfresco is easy, you just sum-up everything. But if you want only restricted to a specific Node (a Site being a certain Node), then it becomes quite complex because of the hierarchy/recursive problem. If you look at the section &quot;Size and number of documents created by all users&quot;, you can find some information on what could be done to evaluate the total size per user, but to restrict that to a certain Site, you would need to browse through all nodes 1 by 1 and sum-up their size, so if you have millions of nodes, it&#039;s going to put a huge load on the DB. For the total number, you might find it easier to ask Solr with a PATH query using an Admin account, since that would be almost instantaneous and easy to execute.

You can also look at the &quot;Recursively find the number of childs&quot; section from the blog, which starts a query to find all the children and I believe that&#039;s the starting point for all your queries, if you really want to do that through the DB.

Regards,
Morgan]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.dbi-services.com/blog/alfresco-some-useful-database-queries/#comment-2950">SG@1234@</a>.</p>
<p>Hello,</p>
<p>The list of people who accessed the site or uploaded/downloaded documents within the site wouldn&#8217;t be available by default since the audit is turned off. It&#8217;s only if you have the audit enabled that this would be stored. If you have the audit enabled, then I would say that the way-to-go is to check the REST-API, c.f. <a href="https://docs.alfresco.com/content-services/latest/admin/audit/" rel="nofollow ugc">https://docs.alfresco.com/content-services/latest/admin/audit/</a> &amp;&amp; <a href="https://api-explorer.alfresco.com/api-explorer/" rel="nofollow ugc">https://api-explorer.alfresco.com/api-explorer/</a>&#8230; If you really want to use the DB, then it should be data from the alf_audit_* tables (in conjunction with other tables as shown in the blog to get properties and find out on which site it is). The DB isn&#8217;t really efficient for recursive things since Associations in Alfresco will only work with the direct parent folder. So if you want to look for all people who uploaded/downloaded from a Site, you need to find the Site Node, then list all its children and all their children&#8217;s children and all their children&#8217;s children&#8217;s children and etc&#8230;</p>
<p>For the total size/number of files in a Site, it&#8217;s the same as well&#8230; Doing the total for all Alfresco is easy, you just sum-up everything. But if you want only restricted to a specific Node (a Site being a certain Node), then it becomes quite complex because of the hierarchy/recursive problem. If you look at the section &#8220;Size and number of documents created by all users&#8221;, you can find some information on what could be done to evaluate the total size per user, but to restrict that to a certain Site, you would need to browse through all nodes 1 by 1 and sum-up their size, so if you have millions of nodes, it&#8217;s going to put a huge load on the DB. For the total number, you might find it easier to ask Solr with a PATH query using an Admin account, since that would be almost instantaneous and easy to execute.</p>
<p>You can also look at the &#8220;Recursively find the number of childs&#8221; section from the blog, which starts a query to find all the children and I believe that&#8217;s the starting point for all your queries, if you really want to do that through the DB.</p>
<p>Regards,<br />
Morgan</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)

Served from: www.dbi-services.com @ 2026-06-10 16:10:57 by W3 Total Cache
-->