Recursively find the path to all leaves descending from a given parent in a tree
WITH RECURSIVE
cte AS ( SELECT id, 
                parent_id, 
                id::TEXT path,
                NOT EXISTS ( SELECT NULL
                             FROM graph gr
                             WHERE graph.id = gr.parent_id ) is_leaf
                FROM graph 
                WHERE id = 2 /* initital node id */
         UNION ALL
         SELECT graph.id, 
                graph.parent_id, 
                cte.path || ',' || graph.id,
                NOT EXISTS ( SELECT NULL
                             FROM graph gr
                             WHERE graph.id = gr.parent_id ) 
         FROM cte JOIN graph ON cte.id = graph.parent_id)
SELECT path 
FROM cte
WHERE is_leaf

https://dbfiddle.uk/?rdbms=postgres_12&amp;fiddle=2e40ff454f302033bf5e8cba8b0b0d85
Multiple initial nodes may be applied too (WHERE id IN (0, 1)).