Finding what the source of a specific PostgreSQL configuration setting
pg_settings - look for source*

For example, after

alter system set array_nulls to off;


(and reloading configuration)

select * from pg_settings where name = 'array_nulls';



╔═[ RECORD 1 ]════╤════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
║ name            │ array_nulls                                                                                                ║
║ setting         │ off                                                                                                        ║
║ unit            │ ░░░░                                                                                                       ║
║ category        │ Version and Platform Compatibility / Previous PostgreSQL Versions                                          ║
║ short_desc      │ Enable input of NULL elements in arrays.                                                                   ║
║ extra_desc      │ When turned on, unquoted NULL in an array input value means a null value; otherwise it is taken literally. ║
║ context         │ user                                                                                                       ║
║ vartype         │ bool                                                                                                       ║
║ source          │ configuration file                                                                                         ║
║ min_val         │ ░░░░                                                                                                       ║
║ max_val         │ ░░░░                                                                                                       ║
║ enumvals        │ ░░░░                                                                                                       ║
║ boot_val        │ on                                                                                                         ║
║ reset_val       │ off                                                                                                        ║
║ sourcefile      │ /var/lib/postgresql/9.5/main/postgresql.auto.conf                                                          ║
║ sourceline      │ 3                                                                                                          ║
║ pending_restart │ f                                                                                                          ║
╚═════════════════╧════════════════════════════════════════════════════════════════════════════════════════════════════════════╝




Update
And there is the query to get db/role settings, without relogin required:

with
  opt_db as (
    select s.*, d.datname, opt_name, opt_value from 
      pg_db_role_setting s join
      pg_database d on (s.setdatabase = d.oid) cross join lateral (
        select
          split_part(opt, '=',1) as opt_name,
          split_part(opt, '=', 2) as opt_value
        from
          unnest(setconfig) as opt) as opt 
    ),
  opt_role as (
    select s.*, r.rolname, opt_name, opt_value from 
      pg_db_role_setting s join
      pg_roles r on (s.setrole = r.oid) cross join lateral (
        select
          split_part(opt, '=', 1) as opt_name,
          split_part(opt, '=', 2) as opt_value
        from
          unnest(setconfig) as opt) as opt 
  )

select
  datname,
  rolname,
  opt_name,
  opt_db.opt_value as db_value,
  opt_role.opt_value as role_value
from opt_db full join opt_role using(opt_name);


Possible result:


╔══════════╤══════════╤═════════════╤═════════════════╤═════════════════╗
║ datname  │ rolname  │  opt_name   │    db_value     │   role_value    ║
╠══════════╪══════════╪═════════════╪═════════════════╪═════════════════╣
║ postgres │ nd       │ search_path │ "$user", public │ "$user", public ║
║ postgres │ postgres │ array_nulls │ off             │ on              ║
║ ░░░░     │ nd       │ foo.bar     │ ░░░░            │ 3               ║
╚══════════╧══════════╧═════════════╧═════════════════╧═════════════════╝