Primary/Secondary Switchover
After the data consistency verification is complete and all data in the secondary database is correct, perform a primary/secondary switchover to adjust the existing primary/secondary deployment structure. After the switchover is complete, check the consistency between the new primary database and the new secondary database.
- Before the primary/secondary switchover, there is one primary database and two secondary databases. The primary database and secondary database 1 are on x86 servers, and the secondary database 2 is on a Kunpeng server.
- Switch the Kunpeng secondary database to the new primary database. Switch the original x86 primary database to the new secondary database 1. At last, replace the new secondary database 1 on the x86 server with the new secondary database 2 running on a Kunpeng ser.ver.
The primary/secondary switchover is shown in Figure 1.
The following describes how to perform a primary/secondary switchover. After the switchover, the new secondary database can successfully connect to and keep data consistent with the new Kunpeng primary database.
- Stop the primary database service.Log in to the primary database server using SSH and stop the primary database service to ensure that data is not written to the server.
su - postgres /usr/local/pgsql-13.2/bin/pg_ctl -D /data/pg-13.2/data -l logfile stop

- Switch the Kunpeng secondary database to the new primary database.Use SSH to log in to the Kunpeng secondary database server and run the following command to switch the Kunpeng secondary database to the new primary database:
su - postgres /usr/local/pgsql-13.2/bin/pg_ctl promote -D /data/pg-13.2/data

- Log in to the x86 secondary database (new secondary database 1) server and connect to the new primary database.
- Open the postgresql.conf file.
su - postgres vi /data/pg-13.2/data/postgresql.conf
- Press i to enter the insert mode. Modify the primary_conninfo parameter to specify the IP address, port number, user name, and password of the new primary database server.
primary_conninfo = 'host = IP address of the new Kunpeng primary database server port = 5432 user = backup password = 123456'

- Press Esc, type :wq!, and press Enter to save the file and exit.
- Restart the database service of the x86 secondary database (new secondary database 1) for the new configurations to take effect.
/usr/local/pgsql-13.2/bin/pg_ctl -D /data/pg-13.2/data -l logfile restart

- Open the postgresql.conf file.
- Verify the configurations and synchronization status.
- Verify the status of the new primary database.
- Log in to the new primary database and check the database process status.
su - postgres ps -ax | grep postgres

- Log in to the database and check the synchronization status of the primary/secondary LSNs.
/usr/local/pgsql-13.2/bin/psql -U postgres select pg_current_wal_lsn(); select * from pg_stat_replication;

- Exit the database.
\q

- Log in to the new primary database and check the database process status.
- Verify the status of the x86 secondary database (new secondary database 1).
Log in to the x86 secondary database (new secondary database 1) and confirm that the database process is running properly.
su - postgres ps -ax | grep postgres

- Verify the status of the new primary database.
- After the primary/secondary switchover is complete, connect a new Kunpeng server to add to the secondary database cluster. For details, see Performing a Full Backup of an x86 Node to Verifying Primary/Secondary Data Consistency.
Before the primary/secondary switchover, the "primary database" in sections from Performing a Full Backup of an x86 Node to Verifying Primary/Secondary Data Consistency refers to the x86 primary database. After the primary/secondary switchover, the "primary database" refers to the new Kunpeng primary database.
After the addition of a new Kunpeng server, the database server cluster has one Kunpeng server as the primary database server, and one Kunpeng server and one x86 server function as the secondary database servers.
- Verify the data consistency between the new primary database and the new secondary database. For details, see Verifying Primary/Secondary Data Consistency.
Before the primary/secondary switchover, the primary database in Verifying Primary/Secondary Data Consistency refers to the x86 primary database. After the primary/secondary switchover, the primary database refers to the new Kunpeng primary database.
