Diving in, I haven’t worked with PostgreSQL for 15 years, but sharing random notes and obsrervations

  • RoundSparrowOPM
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    query to get your row counts

    To see how many comments, posts, persons, etc you have in your database, this query gives accurate counts and takes less than 1/3 of a second to execute. You can re-run this query and see new activity instantly.

    SELECT table_schema, table_name, 
    	(xpath('/row/cnt/text()', xml_count))[1]::text::int as row_count
    		FROM (
    			SELECT table_name, table_schema, 
    				query_to_xml(format('select count(*) as cnt from %I.%I', table_schema, table_name), false, true, '') as xml_count
    				FROM information_schema.tables
    				WHERE table_schema = 'public' --<< change here for the schema you want
    			) t;