To properly manage the PostgreSQL database cluster the PostgreSQL Recovery Kit requires the postmaster process to be running with the port argument: “-p port”. The port is required to create a PostgreSQL resource hierarchy and for monitoring once the hierarchy is created. To view the current argument list for the postmaster process see the postmaster.opts file located in the data directory for PostgreSQL database cluster. The following is an example of the contents of this file:
C:/Program Files/PostgreSQL/9.6/bin/postgres.exe “-D” “E:\PGSQL1” “-p” “5432”
In this example the postmaster process is running with the port argument. If the postmaster process is not running with the port argument it will need to be added via one of the two methods listed below:
- Adding the port argument to an existing Windows Service Instance
- Adding the port argument to a non-Windows Service Instance
Adding the port argument to an existing Windows Service Instance
If the PostgreSQL database cluster to be protected by the PostgreSQL recovery kit is running via a Windows Service, such as the postgresql-x64-9.6 service created by the initial install of the PostgreSQL software v9.6, then the startup command line for the service will need to be modified. This can be done via the following steps:
Stop the existing PostgreSQL database cluster instance. This can be done using several different methods:
Use the Windows Service Interface (services.msc) and select to stop the service.
Use the command line utility “sc”, e.g. sc stop service name.
Use the command “net”, e.g net stop service_name.
Modify the startup command line for the service. This can be done via the command line using the “sc” utility or by editing the startup command line in the registry. Note: The startup command line for the PostgreSQL service uses the pg_ctl.exe utility. To pass arguments to the postmaster process from the pg_ctl utility requires the use of the “-o” argument. The “-o” argument takes a quoted list of postmaster startup options such as the “-p port” as used in the modifications shown below.
To edit the startup command line using the “sc” command line utility follow these steps. This example uses the postgresql-x64-9.6 service:
Retrieve the binPath (startup command line) for the service, e.g “sc qc postgresql-x64-9.6” it will return something like the following (for this example only the output line with the startup command line is shown):
BINARY_PATH_NAME : “C:\Program Files\PostgreSQL\9.6\bin\pg_ctl.exe” runservice -N “postgresql-x64-9.6” -D “E:\PGSQL1” –w
Update the binPath. Note: There is a space after the “=” for the binPath argument and the value must be in double quotes therefore it requires escaping the imbedded double quotes.
sc config postgresql-x64-9.6 binPath= “\“C:\Program Files\PostgreSQL\9.6\bin\pg_ctl.exe\” runservice -N \“postgresql-x64-9.6\” -D \“E:\PGSQL1\” –w –o \”-p 5432\” “
To edit the startup command line in registry requires the use of a registry edit tool such as regedit.
a. Using regedit find the service ImagePath registry value: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\postgresql-x86-9.6\ImagePath
b. Modify the ImagePath value by adding the port argument at the end of the existing command line: -o “-p 5432”
Restart the existing PostgreSQL database cluster instance. This can be done using several different methods:
Use the Windows Service Interface (services.msc) and select to start the service.
Use the command line utility “sc”, e.g. sc start service_name.
Use the command “net”, e.g net start service_name.
- Verify the postmaster process is running with port argument by checking the postmaster.opts file as described above.
Adding the port argument to a non- Windows Service Instance
If a Windows Service does not exist for the PostgreSQL database cluster then stopping and restarting the PostgreSQL database cluster via the PostgreSQL utility pg_ctl.exe will be required. This can be done via the following steps:
- Stop the PostgreSQL database cluster.
pg_ctl stop –D F:\PGSQL2
- Start the PostgreSQL database cluster.
pg_ctl start –D F:\PGSQL2 –w –o “-p 5433”
- Verify the postmaster process is running with port argument by checking the postmaster.opts file as described above.
Post your comment on this topic.