Let’s say you have a port conflict and need to change the port on your Availability Group endpoint. How can we accomplish this?
The first step is to change the port on the endpoint itself. Note that as soon as you do this the replica on which you are running it will no longer be able to replicate data until you have updated the URL as well. Here is the code to change the port, just make sure you know what the IP is unless you are changing that too. If you are, then read this post on changing the endpoint IP address.
ALTER ENDPOINT [MyEndpoint] STATE = STARTED AS TCP (LISTENER_PORT = 7777, LISTENER_IP = (10.x.x.x)) FOR DATA_MIRRORING (ROLE = ALL, AUTHENTICATION = Windows Negotiate, ENCRYPTION = REQUIRED ALGORITHM AES) GO
The second step is to change the replica URL. This part is pretty straight forward since you already know the port from above. What I want to encourage you to do is use the full URL or FQDN for the server name.
ALTER AVAILABILITY GROUP [MyAG] MODIFY REPLICA ON 'MyNode1' WITH (ENDPOINT_URL = 'TCP://MyNode1.mydomain.com:7777') GO
That’s all there is to it!