Calculating balance sheet with a single query
If your account table doesn't change often, you could take advantage of Postgres Materialized Views.

CREATE MATERIALIZED VIEW account_tree 
AS
WITH RECURSIVE
  -- recursively build tree table, assigning path for each row
  tree 
AS (
    SELECT account.id        AS id,
           account.parent_id AS parent_id,
           account.name      AS name,
           ARRAY[account.id] AS path
      FROM account
     WHERE account.parent_id IS NULL

     UNION ALL

    SELECT account.id                     AS id,
           account.parent_id              AS parent_id,
           account.name                   AS name,
           tree.path || ARRAY[account.id] AS path
      FROM account, tree
     WHERE account.parent_id = tree.id
  )
SELECT 
    t.id,
    t.account_id,
    CASE WHEN t.parent_id = t.account_id 
         THEN a.name ELSE t.name END AS name
FROM
    (SELECT id, parent_id, name, unnest(path) as account_id
     FROM   tree) t
JOIN
    account a
    ON a.id = t.parent_id;


Materialized views allows the use of index:

CREATE INDEX account_tree_ix
  ON account_tree (id, account_id);


This view returns next result:


 id | account_id | name           
--: | ---------: | :--------------
101 |        100 | ASSET          
101 |        101 | Cash           
102 |        100 | ASSET          
102 |        102 | Bank           
201 |        200 | LIABILITY      
201 |        201 | Loan           
301 |        300 | EQUITY         
301 |        301 | Opening Balance


Now you can use this view to obtain the balance sheet avoiding the recursive CTE:

SELECT    at.account_id, 
          at.name,
          coalesce(abs(sum(p.amount)), 0) AS amount
FROM      account_tree at
LEFT JOIN posting p
          ON p.account_id = at.id
GROUP BY  at.account_id,
          at.name
ORDER BY  at.account_id;




account_id | name            |     amount
---------: | :-------------- | ---------:
       100 | ASSET           | 1500000.00
       101 | Cash            |  250000.00
       102 | Bank            | 1250000.00
       200 | LIABILITY       |  500000.00
       201 | Loan            |  500000.00
       300 | EQUITY          | 1000000.00
       301 | Opening Balance | 1000000.00



db&lt;>fiddle here