Maybe this way.Create a roles likegr_4gr_5gr_4_5
grant roles by needs to users and define roles in pg_hba.conf (USER: +gr_4).
brKaido