They definitely may give different results. The better one is
select count(*) from pg_stat_activity;
It's because it includes connections to WAL sender processes which are treated as regular connections and count towards max_connections
.
See max_wal_senders