# Running multiple PostgreSQL instances on gentoo?

## LordVan

hi.

i was wondering if there was some standard way of running multiple instances of postgresql (e.g. on port 5432 and 5433) with different Data dirs (same postgres version).

I know i can copy the init script and config and modify them so that it works but did anyone do this already?

Thanks

----------

## Tekeli Li

I've never done it, and I believe if I did, I'd be doing separate init script for that. Although I believe the data dir env var is still being ignored (bug)?

Still, why would you want to run multiple pgsql instances on the same machine?

----------

## LordVan

With dbmail and several other apps i found it to be an issue with vacuum and optimize .. also dbmail has lots and lots of inserts which seem to degrade performance on other apps/dbs as well as it takes up resources (i think)

----------

## hannibal218bc

Sorry to revive this old thread, but I'm also searching for a sensible way to run multiple instances / clusters on one Gentoo machine. What I'd like to do is to have one machine serve as a server for one cluster and also as a streaming replication slave. So, I need two clusters and two instances.

Thanks for any input!

----------

## hannibal218bc

I added this "enhancement request" to bugzilla:

https://bugs.gentoo.org/show_bug.cgi?id=375185

----------

## titanofold

I won't be adding support in the init scripts for multiple instances per slot.

You'll have to create an additional cluster manually using initdb. (The init script assumes the user will be postgres, so make it easy on yourself and instruct initdb that the owner is postgres.)

ln -s /etc/init.d/postgresql-${SLOT} /etc/init.d/something-else

cp /etc/conf.d/postgresql-${SLOT} /etc/conf.d/something-else

Edit /etc/conf.d/something-else to point to the proper directory where you've created the additional cluster, where the configuration files are, and the port you want it to run on.

You should be good to go at that point.

----------

## hannibal218bc

Ah, I see -- it's that easy!? Cool, already works. Thank you!

----------

## Vieri

I was looking for that too.

Could it be possible to have this information within the postgresql-server ebuilds (just as plain einfo)?

And/or on the official Gentoo postgresql documentation web page?

Thanks

----------

## titanofold

 *Vieri wrote:*   

> I was looking for that too.
> 
> Could it be possible to have this information within the postgresql-server ebuilds (just as plain einfo)?
> 
> And/or on the official Gentoo postgresql documentation web page?
> ...

 

Yes, it's possible, but I'll neither add it to the ebuild nor the quick start guide.

There are one or two edge cases where one would actually want two instances of the same version running on the same computer. It is not something that should be encouraged for the general public to consider as a solution.

----------

## svoop

[quote="titanofold"] *Vieri wrote:*   

> There are one or two edge cases where one would actually want two instances of the same version running on the same computer. It is not something that should be encouraged for the general public to consider as a solution.

 

There's one quite common situation where you absolutely have to run two daemons: Say you have two servers: A for production and B for staging (very low traffic) and backup. In order to mirror the db on A to B, you'd have to use Postgres' Streaming Replication mechanism. However, you can't use the replicated database on B for anything else, so you need a second instance of Postgres on B to serve the staging.

----------

## KAMIKAZE_

another case: I don't want to replicate all my databases in one archive. If I will run recovery for one - it will rollback other dbs too, that's bad

----------

