There is an existing solution for that: the libpq connection service file:https://www.postgresql.org/docs/current/libpq-pgservice.html
pgsql-general by date:
Соглашаюсь с условиями обработки персональных данных