postgresql 在同一台机器上创建多个 Postgres 实例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37861262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Create multiple Postgres instances on same machine
提问by npCompleteNoob
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.
为了测试流复制,我想在同一台机器上创建第二个 Postgres 实例。这个想法是,如果它可以在测试服务器上完成,那么在两个生产服务器上设置它应该是微不足道的。
The instances should use different configuration files and different data directories. I tried following the instructions here http://ubuntuforums.org/showthread.php?t=1431697but 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.
实例应该使用不同的配置文件和不同的数据目录。我尝试按照http://ubuntuforums.org/showthread.php?t=1431697的说明进行操作,但我还没有弄清楚如何让 Postgres 使用不同的配置文件。如果我复制 init 脚本,这些脚本只是同一个 Postgres 实例的别名。
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.
我正在使用 Postgres 9.3 并且 Postgres 帮助页面说要在postgres
命令行上指定配置文件。我不太确定这意味着什么。我应该安装一些客户端才能正常工作吗?谢谢。
回答by cachique
I assume you can work your way out on using postgresql utilities.
我假设您可以使用 postgresql 实用程序解决问题。
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.
现在您有两个实例在端口 5433 和 5434 上运行。它们的配置文件位于由initdb
. 调整它们以进行流式复制。
您的默认安装在端口 5432 中保持不变。
回答by sharez
On Debian based distros you could use pg_createcluster
instead of initdb
:
在基于 Debian 的发行版上,您可以使用pg_createcluster
代替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
.
还pg_ctlcluster
是一个替代pg_ctl
。
回答by shreya kothari
Steps to create New Server Instance on PostgreSQL 9.5
在 PostgreSQL 9.5 上创建新服务器实例的步骤
On command prompt run:
initdb -D Instance_Directory_path -U username -W
(prompts for password)
Once the new Instance Directory is created. Run command prompt as Administrator
pg_ctl register -N service_name -D Instance_Directory_path -o "-p port_no"
After the service is registered, start server
pg_ctl start -D Instance_Directory_path -o "-p port_no"
在命令提示符下运行:
initdb -D Instance_Directory_path -U username -W
(提示输入密码)
创建新的实例目录后。以管理员身份运行命令提示符
pg_ctl register -N service_name -D Instance_Directory_path -o "-p port_no"
服务注册好后,启动服务器
pg_ctl start -D Instance_Directory_path -o "-p port_no"