2

I am currently setting up a c# app to allow me to control applications on my windows 2012 server.

Architecture:

Master Server - Postgres x64 9.3 running from a windows service as read/write database, with hot-standby mode and a replication slot.

Slave Server - Postgres x64 9.3 running from a windows service as a read-only hot-standby server via a replication slot.

I plan on stopping the services using the following code:

service = new ServiceController("postgresql-x64-9.4");
                        try
                        {
                            TimeSpan timeout = TimeSpan.FromMilliseconds(5000);

                            service.Stop();
                            service.WaitForStatus(ServiceControllerStatus.Stopped, timeout);
                            log.writeLog(data, "success", "Postgres Stopped");
                        }
                        catch (Exception e)
                        {
                            log.writeLog(data, "ERROR", e.Message + " - " + e.InnerException);
                            msg = Encoding.ASCII.GetBytes("ERROR");
                            break;
                        }

However, I was wondering whether this is safe regarding the integrity of the both databases.

I know that pg_ctl has shutdown modes, where "Smart" mode waits for active processes and closes connections etc prior to stopping the database. Does stopping the windows service do the same? Yes, I can obviously use pg_ctl to achieve this, however I am asking for interest as much as anything else.

Are there risks that need to be mitigated regarding any active replication, or will the service stay alive until the servers are in sync? The timing of the "stop" will be done at a point where the databases are not under heavy write load so should be essentially in sync. I can also test for this before kicking off the "Stop" code.

The intention is to leave the replicated slave "live" but still in read-only slave mode while the master server is stopped.

Thanks in advance

Mr.Adam
  • 294
  • 5
  • 23

0 Answers0