In den folgenden Abschnitten wird beschrieben, wie Sie den primären AlloyDB Omni-Server für die Replikation konfigurieren, den Replikatserver konfigurieren und den Replikationsstatus auf dem primären Server prüfen.
Primären Server für die Replikation konfigurieren
Aktualisieren Sie die Netzwerk- oder Firewalleinstellungen des Hosts Ihres primären Servers, damit eingehender Traffic vom Host des Replikatservers über den TCP-Port 5432 zugelassen wird.
Fügen Sie der Datei /var/alloydb/config/pg_hba.conf die folgenden Zeilen hinzu:
DATA_DIR: Der Dateisystempfad, den dieses Replikat für sein Datenverzeichnis verwenden soll.
PORT: Der TCP-Port, über den AlloyDB Omni Verbindungen akzeptieren soll. Wenn Sie diesen Wert nicht angeben, wendet AlloyDB Omni den Standardwert 5432 an.
SOURCE_IP: Die IP-Adresse der primären AlloyDB Omni-Instanz, von der repliziert werden soll.
SOURCE_PORT: Der TCP-Port der primären AlloyDB Omni-Instanz, von der repliziert werden soll. Wenn Sie diesen Wert nicht angeben, wendet AlloyDB Omni den Standardwert 5432 an.
Prüfen Sie, ob das Replikat eine Netzwerkverbindung zum primären Server hat:
pingSOURCE_IP
Replikat starten:
sudoalloydbdatabase-serverstart
Replikationsstatus auf dem primären Server prüfen
Führen Sie den folgenden Befehl auf dem Host des primären Servers aus, um zu prüfen, ob die Replikation richtig konfiguriert ist:
dockerexec-itpg-servicepsql-hlocalhost-Ualloydbadmin-c"select * from pg_stat_replication"
Die Ausgabetabelle enthält eine Zeile für jedes Replikat, das mit Ihrem primären Datenbankserver verbunden ist.
Nachdem Sie die Replikation eingerichtet haben, sind alle Einfügungen, Aktualisierungen und Löschungen von Zeilen auf Ihrem primären Datenbankserver innerhalb von Sekunden auf Ihrem Replikat lesbar.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-17 (UTC)."],[[["\u003cp\u003eAlloyDB Omni replica servers offer read-only clones of the primary database, enhancing read throughput and availability by continuously updating with the primary server's data.\u003c/p\u003e\n"],["\u003cp\u003eConfiguring a primary server for replication involves updating network/firewall settings to allow ingress traffic from the replica and modifying the \u003ccode\u003e/var/alloydb/config/pg_hba.conf\u003c/code\u003e file to permit connections.\u003c/p\u003e\n"],["\u003cp\u003eCreating a replica server requires installing AlloyDB Omni and using the \u003ccode\u003ealloydb database-server install\u003c/code\u003e command with specific flags, including the data directory, port, source IP, and source port of the primary server.\u003c/p\u003e\n"],["\u003cp\u003eTo ensure the replica is correctly set up, network connectivity to the primary server must be confirmed via a \u003ccode\u003eping\u003c/code\u003e command, and the replica must be started using \u003ccode\u003esudo alloydb database-server start\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eReplication status can be verified on the primary server using a \u003ccode\u003edocker exec\u003c/code\u003e command that checks the \u003ccode\u003epg_stat_replication\u003c/code\u003e table, and once configured, changes on the primary server reflect on the replica within seconds.\u003c/p\u003e\n"]]],[],null,["# Create a read-only replica\n\nSelect a documentation version: 15.5.2keyboard_arrow_down\n\n- [Current (16.8.0)](/alloydb/omni/current/docs/set-up-read-replica)\n- [16.8.0](/alloydb/omni/16.8.0/docs/set-up-read-replica)\n- [16.3.0](/alloydb/omni/16.3.0/docs/set-up-read-replica)\n- [15.12.0](/alloydb/omni/15.12.0/docs/set-up-read-replica)\n- [15.7.1](/alloydb/omni/15.7.1/docs/set-up-read-replica)\n- [15.7.0](/alloydb/omni/15.7.0/docs/set-up-read-replica)\n- [15.5.5](/alloydb/omni/15.5.5/docs/set-up-read-replica)\n- [15.5.4](/alloydb/omni/15.5.4/docs/set-up-read-replica)\n- [15.5.2](/alloydb/omni/15.5.2/docs/set-up-read-replica)\n\n\u003cbr /\u003e\n\nTo increase read throughput and availability, you can create an AlloyDB Omni replica server for an existing AlloyDB Omni server. A replica server provides a read-only clone of your primary database server. It continuously updates its own data to reflect changes to your primary server's data.\n\n\u003cbr /\u003e\n\nThe following sections provide steps to configure your\nAlloyDB Omni primary server for replication, configure the\nreplica server, and verify replication status on the primary server.\n\n\n| The information on this page applies only to AlloyDB Omni for containers. It does not apply to AlloyDB Omni for Kubernetes.\n\n\u003cbr /\u003e\n\nConfigure your primary server for replication\n---------------------------------------------\n\n1. Update the network or firewall settings of your primary server's host so\n that it allows ingress traffic from the replica server's host through TCP\n port `5432`.\n\n2. Add the following lines in the `/var/alloydb/config/pg_hba.conf` file:\n\n host all alloydbreplica \u003cvar translate=\"no\"\u003eIP_RANGE\u003c/var\u003e trust\n host replication alloydbreplica \u003cvar translate=\"no\"\u003eIP_RANGE\u003c/var\u003e trust\n host alloydbmetadata alloydbmetadata \u003cvar translate=\"no\"\u003eIP_RANGE\u003c/var\u003e trust\n\n Replace \u003cvar translate=\"no\"\u003eIP_RANGE\u003c/var\u003e with the IP range, in CIDR notation, of\n the subnet where your replica machine is located. For example,\n `203.0.113.0/24`.\n3. Restart your primary server:\n\n sudo alloydb database-server stop\n sudo alloydb database-server start\n\nCreate and configure the replica server\n---------------------------------------\n\nTo create and configure an AlloyDB Omni replica server, complete\nthe following steps:\n\n1. [Install\n AlloyDB Omni](/alloydb/omni/15.5.2/docs/install) onto the system\n you want to host the replica.\n\n When you run the `alloydb\n database-server install` command, include the flags that are specific\n to creating a replica: \n\n sudo alloydb database-server install \\\n --data-dir=\u003cvar translate=\"no\"\u003eDATA_DIR\u003c/var\u003e \\\n --pg-port=\u003cvar translate=\"no\"\u003ePORT\u003c/var\u003e \\\n --replica-source-ip=\u003cvar translate=\"no\"\u003eSOURCE_IP\u003c/var\u003e \\\n --replica-source-port=\u003cvar translate=\"no\"\u003eSOURCE_PORT\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eDATA_DIR\u003c/var\u003e: the file system path you want this replica\n to use for its data directory.\n\n - \u003cvar translate=\"no\"\u003ePORT\u003c/var\u003e: the TCP port that you want\n AlloyDB Omni to accept connections on. If you don't\n provide this value, then AlloyDB Omni applies a default\n value of `5432`.\n\n - \u003cvar translate=\"no\"\u003eSOURCE_IP\u003c/var\u003e: the IP address of the primary\n AlloyDB Omni instance to replicate from.\n\n - \u003cvar translate=\"no\"\u003eSOURCE_PORT\u003c/var\u003e: the TCP port of the primary\n AlloyDB Omni instance to replicate from. If you don't\n provide this value, then AlloyDB Omni applies a default\n value of `5432`.\n\n2. Ensure the replica has network connectivity to the primary server:\n\n ping \u003cvar translate=\"no\"\u003eSOURCE_IP\u003c/var\u003e\n\n3. Start your replica:\n\n sudo alloydb database-server start\n\nVerify replication status on the primary server\n-----------------------------------------------\n\nTo verify replication is configured properly, run the following command on the\nprimary server's host: \n\n docker exec -it pg-service psql -h localhost -U alloydbadmin -c \"select * from pg_stat_replication\"\n\nThe output table contains one row for every replica connected to your primary\ndatabase server.\n\nAfter you set up replication, all inserts, updates, and deletions to rows in\nyour primary database server become readable on your replica within seconds."]]