pg_restoring into a table with a not null column I'm merging two databases. The newer one has a table with an integer column failed_port which is NOT NULL. The older database does not have this column.  

So after using pg_dump to dump both databases and then pg_insert to merge them there is an error:  

pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 2336; 0 58976 TABLE DATA c_a postgres
pg_restore: [archiver (db)] could not execute query: ERROR:  null value in column "faild_port" violates not-null constraint
DETAIL:  Failing row contains (1, A, B, 2000, null, 2019-01-19 16:27:15.335126, Tool).
    Command was: INSERT INTO c_a (c_a_pk, c_b_fk, name, port, row_created, row_creator) VALUES (1...


The table in older database looks like this:

c_a_pk | c_b_fk | name | port  |        row_created         | row_creator 
-------+--------+------+-------+----------------------------+-------------
     1 | A      | B    |  2000 | 2019-01-19 16:27:15.335126 | Tool 


And in the newer like this:  

c_a_pk | c_b_fk | name | port | failed_port |        row_created         | row_creator 
-------+--------+------+------+-------------+----------------------------+-------------
     1 | C      | D    | 2000 |           0 |2019-02-19 16:27:15.335126  | Tool 


How to merge the older table with the newer? Is there for example a command for pg_restore to automatically set default value to 0 if there is a NOT NULL column that doesn't exist in first table? I could do this manually, but I'm planning to merge multiple databases so it would be burdensome to do this by hand.
Temporarily put a trigger on your target table to set default values:

CREATE FUNCTION override_null()
RETURNS trigger AS $$
BEGIN
  IF NEW.failed_port IS NULL THEN
    NEW.failed_port := 0;
  END IF;
  RETURN NEW;
END
$$ LANGUAGE 'plpgsql';

CREATE TRIGGER override_null_trigger
BEFORE INSERT ON c_a
FOR EACH ROW
EXECUTE PROCEDURE override_null();