PostgreSQL insert record by trigger create table tab1(id int,name text);
create table tab2(id int,name text);

  create or replace function t_tab() returns trigger
as
$$
begin
insert into tab2
values (new.id, new.name)
return new;     
end;
$$
language plpgsql;

create trigger t_tab
after insert on tab1
for each row
execute procedure t_tab();


The statement:

insert into tab1(1,'king');


inserts data in both tables tab1 and tab2. 

Now my question is: I want same thing in tab2 table. When I insert data in tab2 table automatically insert same data in tab1. If I create same trigger function in tab2 then the execution unlimited. Is there any solution to fix this?
assuming ID is a primary key.

on conflict do nothing:

create or replace function t2_tab() returns trigger
as
$$declare r record;
begin
insert into tab2                                 
select new.*
on conflict do nothing
returning * into r;
return r;    
end;                
$$ language plpgsql;