PostgreSQL listens on port 5432. By default only on localhost (listen_addresses = 'localhost'); for remote connections, change listen_addresses and pg_hba.conf and reload PostgreSQL.
Do not open it to the internet. Allow only the application servers' IPs, use scram-sha-256 in pg_hba.conf and ideally hostssl. For admin access use an SSH tunnel.
Common errors: no pg_hba.conf entry for host (missing rule or wrong order), Connection refused (listening locally only) and too many connections with Nextcloud and no connection pooling.
Check
pg_isready -h db.example.com -p 5432