0

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?

3

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 under c:\Program Files (that's one of the reasons I stopped using the EntpriseDB installer because it always suggested that)

"C:\Program Files\PostgreSQL\12\bin\initdb" -D "c:\ProgramData\pgdata2" 

Then edit c:\ProgramData\pgdata2\postgresql.conf and change the value for port, e.g.

port = 5335

Then you can register the new Windows service and provide the data directory during registration:

pg_ctl register -N other-postgres -D -D "c:\ProgramData\pgdata2"

Once the service is registered, you can start it using net start

net start other-postgres
  • 1
    If you don't use the EnterpriseDB installer, which one do you use? – Vérace Nov 25 '19 at 15:48
  • 1
    @Vérace: I use the ZIP files to install Postgres I essentially do what I described in this answer (after unzipping the archive). – a_horse_with_no_name Nov 25 '19 at 15:48
  • Followed the steps to the T, but when trying to connect with psql with the following command: psql -h localhost -p 5433, I am getting a "connection refused." I see both port 5432 and 5433 occupied by postgres.exe (running netstat). 5432 is my original instance and 5433 is my 2nd instance. – Dash Nov 25 '19 at 16:07
  • Face-palm I forgot to uncomment the listen_addresses = 'localhost' config. setting. – Dash Nov 25 '19 at 16:10
  • @a_horse_with_no_name - I did that last weekend, but I was worried about any potential performance hits? I take it there aren't any? – Vérace Nov 25 '19 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.