Create multiple Postgres instances on the same computer

To test streaming replication, I would like to create a second instance of Postgres on the same computer. The idea is that if this can be done on a test server, then it should be trivial to install it on two production servers.

In instances, different configuration files and different data directories must be used. I tried following the instructions here http://ubuntuforums.org/showthread.php?t=1431697 , but I did not understand how to get Postgres to use a different configuration file. If I copy the init script, the scripts are just aliases to the same Postgres instance.

I am using Postgres 9.3 and the Postgres help pages say to specify a configuration file on the postgres command line. I'm not quite sure what that means. Should I install some kind of client for this? Thanks.

+8
postgresql
source share
3 answers

I assume that you can resolve your issue using postgresql utilities.

Create clusters

 $ initdb -D /path/to/datadb1 $ initdb -D /path/to/datadb2 

Run instances

 $ pg_ctl -D /path/to/datadb1 -o "-p 5433" -l /path/to/logdb1 start $ pg_ctl -D /path/to/datadb2 -o "-p 5434" -l /path/to/logdb2 start 

Streaming Testing

Now you have two instances running on ports 5433 and 5434. The configuration files for them are located in the dir of data specified by initdb . Adjust them for streaming replication.
Your default setting remains untouched on port 5432.

+9
source share

Steps to create a new server instance on PostgreSQL 9.5

  • When you run the command line:

     initdb -D Instance_Directory_path -U username -W 

    (asks for a password)

  • After creating a new instance directory. Run command prompt as administrator

     pg_ctl register -N service_name -D Instance_Directory_path -o "-p port_no" 
  • After registering the service, start the server

     pg_ctl start -D Instance_Directory_path -o "-p port_no" 
+3
source share

On Debian based distributions, you can use pg_createcluster instead of initdb :

 $ pg_createcluster -u [user] -g [group] -d /path/to/data -l /path/to/log -p 5433 

Also pg_ctlcluster is an alternative to pg_ctl .

+2
source share

All Articles