Greenplum was started with PGHOST and/or PGHOSTADDR set.
This can cause issues when a query creates a plan that needs to run a slice on the master host.
Normally plans will execute all slices on the segments. However sometimes it may need to run a slice on the master host and connect to the master. To do this it would normally use the local socket connection on the master,. But if PGHOST is set it will use TCP port on the master host and it will fail with the error "rejecting TCP connection to master using internalconnection protocol"
There are 2 options:
Do not set PGHOST or PGHOSTADDR environment variables when starting Greenplum database.
OR
Set GUC "gp_reject_internal_tcp_connection" to off and restart the DB. To set the GUC run "gpconfig -c gp_reject_internal_tcp_connection -v off --skipvalidation"