Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create multiple Postgres instances on same machine

Tags:

postgresql

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

The instances should use different configuration files and different data directories. I tried following the instructions here http://ubuntuforums.org/showthread.php?t=1431697 but I haven't figured out 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'm using Postgres 9.3 and the Postgres help pages say to specify the configuration file on the postgres command line. I'm not really sure what this means. Am I supposed to install some client for this to work? Thanks.

like image 991
npCompleteNoob Avatar asked Jun 16 '16 13:06

npCompleteNoob


People also ask

How do I create multiple instances in PostgreSQL?

Multiple Instances Adding a new PostgreSQL is as simple as executing pg_createcluster with the version of the PostgreSQL and clustername. The files belonging to this database system will. This user must also own the server process. The database cluster will be initialized with locale.

How many PSQL instances can you start on a single machine?

Note: By default, you can have up to 100 instances per project.

Can we create multiple databases in PostgreSQL?

A single Postgres server process can manage multiple databases at the same time. Each database is stored as a separate set of files in its own directory within the server's data directory. To view all of the defined databases on the server you can use the \list meta-command or its shortcut \l .

Can I install 2 versions of PostgreSQL?

On local machines, it is a collection of databases that are managed by a single database server. Clusters allow us to install multiple versions of Postgresql on our macOS. To manage these clusters, we will be using a package called Postgresql Common.


1 Answers

I assume you can work your way out on using postgresql utilities.

Create the clusters

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

Run the 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 

Test streaming

Now you have two instances running on ports 5433 and 5434. Configuration files for them are in data dirs specified by initdb. Tweak them for streaming replication.
Your default installation remains untouched in port 5432.

like image 127
cachique Avatar answered Sep 22 '22 04:09

cachique