Question: What port does PostgreSQL use for replication?
Answer
PostgreSQL uses the same port for both standard client connections and replication connections, which by default is port 5432
. When setting up replication, you don't need to configure a separate port specifically for replication purposes. Instead, the distinction between a normal connection and a replication connection is made through the connection string or the settings in the pg_hba.conf
file.
Example: Replication Connection String
When a replication client connects to the PostgreSQL server, it specifies the desire to replicate by including replication-related parameters in its connection string. Here's an example connection string for a replication connection:
host=replica-server.example.com port=5432 user=replicator password=yourpassword dbname=replication application_name=my_replica_client sslmode=prefer
In this string, dbname=replication
signifies that this is a replication connection. Note that sslmode=prefer
is optional and used here to indicate a preference for SSL connections.
pg_hba.conf Configuration
For replication to work, the PostgreSQL instance must be configured to allow replication connections. This is done in the pg_hba.conf
configuration file. You would add a line similar to the following:
host replication replicator 192.168.1.100/32 md5
This line allows a host with the IP 192.168.1.100
to connect for replication purposes using the user replicator
and requires MD5 password authentication.
Summary
The key takeaway is that PostgreSQL doesn't use a separate port for replication. Both regular and replication connections can be made through the server's main port, typically 5432
, unless it has been changed in the PostgreSQL configuration. The type of connection is determined not by the port number but by the connection parameters and the server's configuration.
Was this content helpful?
Other Common PostgreSQL Questions (and Answers)
- How can I limit the number of rows updated in a PostgreSQL query?
- How do you limit the number of rows deleted in PostgreSQL?
- How do you use the PARTITION OVER clause in PostgreSQL?
- What are PostgreSQL replication slots and how do they work?
- How can you partition an existing table in PostgreSQL?
- How do you partition a table by multiple columns in PostgreSQL?
- How do you check the replication status in PostgreSQL?
- What are the scaling limits of PostgreSQL?
- How do you scale Azure PostgreSQL?
- How can I improve delete performance in PostgreSQL?
- How can PostgreSQL be auto-scaled?
- What are the best practices for PostgreSQL replication?
Free System Design on AWS E-Book
Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.
Switch & save up to 80%
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost