Update a table after insertion to another table in PostgreSQL?
The cleanest solution is to remove the redundant number_of_cars column completely. Your solution (as well as many related ideas floating around) are not safe against concurrent write access.

Instead, create a VIEW (or a MATERIALIZED VIEW to optimize read performance) like:

CREATE VIEW person_cars AS
SELECT *
FROM  (
   SELECT owner AS personid, count(*) AS number_of_cars
   FROM   car 
   GROUP  BY 1
   ) c
JOIN person p USING (personid);


Or you could have a custom materialized view where you only update persons that had actual changes. Related example:


Refresh materalized view incrementally in PostgreSQL


If you insist on your original idea (and concurrent write access is not an issue), you could use a trigger solution. Basic example:


How do I make a trigger to update a column in another table?


You need to cover all possible changes: INSERT, UPDATE, DELETE on either table. @bgiles added more considerations.