zoukankan      html  css  js  c++  java
  • 【转帖】如何在redhat单机服务器上运行postgresql的多个实例(howto run multiple postgresql instance on one redhat server)

    Running multiple PostgreSQL 9.2 Instances on one server in CentOS 6/RHEL 6/Fedora

    原帖网站速度很慢,故转帖在此

    This post describes how to run multiple PostgreSQL 9.2 Instances on one server in CentOS 6/RHEL 6/Fedora flavors. I am assuming that you have a running postgresql engine on the server already. If not check this post on how to install postgresql server that I wrote earlier and install the first/main instance. Now that you have a running database engine(I will call it first instance) you can start slicing second instance on the same server. As most of my posts I will divide this post into multiple steps for easier understanding and implementation.

      1. Create new data directories for this second instance and let postgres user own them
    mkdir /var/lib/pgsql/9.2/data2
    chown postgres
    .postgres /var/lib/pgsql/9.2/data2

    multiple_pg_1

      2. Create new init script for this instance and edit it

    Copy the init script from first instance and rename it to postgresql2-9.2 and edit it for making changes that reflect the new data directory that we created in the above step.

    cp /etc/init.d/postgresql-9.2/etc/init.d/postgresql2-9.2
    vi
    /etc/init.d/postgresql2-9.2

    multiple_pg_2
    modify the following lines as shown below:

    73# Set defaults for configuration variables
    74 PGENGINE=/usr/pgsql-9.2/bin
    75 PGPORT=5433
    76 PGDATA=/var/lib/pgsql/9.2/data2
    77 PGLOG=/var/lib/pgsql/9.2/pgstartup2.log
    78# Log file for pg_upgrade
    79 PGUPLOG=/var/lib/pgsql/$PGMAJORVERSION/pgupgrade2.log
    80
    81 lockfile="/var/lock/subsys/${NAME}"
    82 pidfile="/var/run/postmaster2-9.2.pid"

    multiple_pg_3

    I have updated PGPORT, PGDATA, PGLOG, PGUPLOG, pidfile variables specific to this new instance. You can subscript to what ever you like. I am currently sub-scripting all file names with 2. Also you can use what ever open port you want this new server instance to run on.

      3. Initialize and start this new postgres instance
    service postgresql2-9.2 initdb
    service postgresql2
    -9.2 start

    multiple_pg_4

      4. Update configs : pg_hba.conf and postgresql.conf

    Update the listen address and port variable values to reflect to what they actually should be.

    vi /var/lib/pgsql/9.2/data2/postgresql.conf
    57# - Connection Settings -
    58
    59 listen_addresses ='*'# what IP address(es) to listen on;
    60# comma-separated list of addresses;
    61# defaults to 'localhost'; use '*' for all
    62# (change requires restart)
    63 port =5433# (change requires restart)

    Update pg_hba.conf to your needs. Please check my other post that I have link up on how to install postgresql 9.2 which have a bit more description on ph_hba conf file.

    multiple_pg_5

      5. Test connect and add this new instance service to server startup

    Connect to this new instance, and see if you can connect, create a user and do what ever you want there.

    su postgres
    psql
    -p5433 -dpostgres

    multiple_pg_6

    And here is how you add it to server startup list :

    chkconfig --add postgresql2-9.2 
    chkconfig postgresql2
    -9.2--level 2345 on

    multiple_pg_7

    Thats all folks you have a new shiny postgres instance running on the same server as main instance. You can slice as many instances as you want as long as you have enough memory and processors on this server. Open up this port in iptables to access it from outside the server if needed.

    If you happen to have any issues are stuck in the process, please feel free to email me or post in comments.

  • 相关阅读:
    非诚勿扰骆琦攻略
    IT服务者的困惑与解决之道
    某某银行IT运维管理的三点和四化
    提升CIO地位及IT价值体现,IT治理理念在中国势在必行
    振兴民族软件,险恶的江湖该如何仗剑走天涯
    某连锁饭店IT服务台、自助服务建设
    证券行业ITIL初探助力券商成就IT管理之路
    分享屡见成效的另类方法论保障ITIL软件及ITSM方案落地实施
    城市商业银行IT科技工作管理之痛
    【转】陈天晴:信息化发展要注意规划调整 重视IT治理
  • 原文地址:https://www.cnblogs.com/dajianshi/p/3741091.html
Copyright © 2011-2022 走看看