When you master server is crashed or inaccessible, then we can do failover and promote slave server as master.
PRIMARY SERVER(MASTER)= 10.20.30.40
STANDBY SERVER(SLAVE) =10.20.30.41
REPLICATION MODE- ASYNC
POSTGRES VERSION- 14
Let’s say master becomes inaccessible, then we need to promote the slave using below command.
on slave server:
-bash-4.2$ which pg_ctl /usr/pgsql-14/bin/pg_ctl -bash-4.2$ /usr/pgsql-14/bin/pg_ctl promote -D /oracle/pg_data waiting for server to promote.... done server promoted
Then check the logfile:
Is the server running on that host and accepting TCP/IP connections? 2022-07-11 10:46:34.095 +03  LOG: received promote request 2022-07-11 10:46:34.095 +03  LOG: redo done at 0/3000AE8 system usage: CPU: user: 0.26 s, system: 0.42 s, elapsed: 70790.02 s 2022-07-11 10:46:34.095 +03  LOG: last completed transaction was at log time 2022-07-10 15:54:55.077262+03 2022-07-11 10:46:34.102 +03  LOG: selected new timeline ID: 2 2022-07-11 10:46:34.154 +03  LOG: archive recovery complete 2022-07-11 10:46:34.167 +03  LOG: database system is ready to accept connections
If you see the log, a new timeline ID as been created and database opened. i.e it becomes Primary and ready to accepts transactions(both read and write). But there is not standby now.
So when old primary becomes accessible, then you need to either rebuild it as standby using fresh pg_basebackup or using pg_rewind.