Relating to original question posted on Stack Overflow here.
Interested in distributing a copy of PostgreSQL with a C# app (for Windows). However, trying to understand how the following scenario should be handled:
- PostgreSQL already installed on the user's system
From my understanding, should be possible to install a 2nd instance of PostgreSQL to run at the same time on the same computer system (as a different service, bound to a different TCP port #?). However, the closest answer for how this would be done was found here, which does not really provide a lot of detail.
So far, in my test environment (VM), I have one instance of Ver. 12 PostgreSQL installed in the default directory C:\Program Files\PostgreSQL\12
.
Am I correct to understand that I should copy all of the contens of the C:\Program Files\PostgreSQL\12
directory and copy/paste to a different directory (e.g. C:\Program Files\PostgreSQL\Test12
?
Then, run pg_ctl register
, but with what options?
And, then after, I should run pg_ctl start
?
Are there any considerations that should be made before all of this is done?
Best Answer
You don't need the binaries two times, you only need to create a second data directory (aka "cluster").
The following creates a new data directory under
c:\ProgramData\pgdata2
. I highly recommend to not put the data directory underc:\Program Files
(that's one of the reasons I stopped using the EntpriseDB installer because it always suggested that)Then edit
c:\ProgramData\pgdata2\postgresql.conf
and change the value forport
, e.g.Then you can register the new Windows service and provide the data directory during registration:
Once the service is registered, you can start it using
net start