Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fROU8-0000ff-80 for pgsql-general@arkaria.postgresql.org; Fri, 08 Jun 2018 20:59:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fROU4-0000TU-Dk for pgsql-general@arkaria.postgresql.org; Fri, 08 Jun 2018 20:59:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fROU2-0000TL-MX for pgsql-general@lists.postgresql.org; Fri, 08 Jun 2018 20:59:44 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fROTw-00040D-ID for pgsql-general@lists.postgresql.org; Fri, 08 Jun 2018 20:59:42 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 238C521C2C; Fri, 8 Jun 2018 16:59:34 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 08 Jun 2018 16:59:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=xi4GGcste8fwZ48E1a0vlMQyFUJ50 Z/CwIUY0bH3qNo=; b=HxYOfERxMm0Kn/1BwGEh/qW8qeHXifWvsqHu4ZQlpF+FL WkGWAu/mNuUXWBipF+GYk31JOOqvvb/OG3qmH13hUt5+VumtQSFvulDauocYBFXJ FXAOJ2yt0xtrXLvBypEBZodrEjhJeASFCwvaPiG9HGQACryf4NoSLst2RTnGYS0o RX/+T57i6oeGKmsayCmgvR3Mh0FN7F/bwceq8R4FOGCiIyI3pcHSbhrRr2KMOyGs citN4TlzYmRbZtURNKlaScKcT1gcYfzzy1ESOceRzD4mBYZH4bCC6jemWugdIhme ahU6M7kYuLUjR/cAupxDWY/4Zf0KSAjiq9ypvwNvA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=xi4GGc ste8fwZ48E1a0vlMQyFUJ50Z/CwIUY0bH3qNo=; b=dwn8vxEj5TxDmGR+C4D39D Otr+sZZy1ZCw63Esoxetg1e6t9Q+DwxP/IeOk4tK/OebtNmDY14YTkitI9rXhUVj 710uVUZ0Zw63PoAY6UDK81106Bci54ftMrygByLki8HxdVsH0uTpDVZy9imaXK0Z 33bQDAAllF2uQG+ZgDqyhPNV4mlqz9kwdts6JrQf/vBu+NYpbdtxIYAC7FG272eX dTmm/NBxzWwEHuU3gX+FZzPJe8OaX5ULy1R2gKU2Dvlw6WT+HE/NFU6dQ7M8oR6l vxJgaShlkeskWNQUneCbo0Qb4hfgpHswo3xI54C3F8M+lSshEHhxtSu5nxxyWKEw == X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.3] (unknown [71.212.159.209]) by mail.messagingengine.com (Postfix) with ESMTPA id 6F361E49AD; Fri, 8 Jun 2018 16:59:33 -0400 (EDT) Subject: Re: Multiple PostgreSQL instances on one machine To: Tony Sullivan , pgsql-general@lists.postgresql.org References: <43cd24d444bb19a06c028f24dadbc5cc.squirrel@www.exquisiteimages.com> From: Adrian Klaver Message-ID: <7e691ce0-3e30-731d-1780-4bc5fb25960d@aklaver.com> Date: Fri, 8 Jun 2018 13:59:32 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <43cd24d444bb19a06c028f24dadbc5cc.squirrel@www.exquisiteimages.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 06/08/2018 01:29 PM, Tony Sullivan wrote: > I am trying to consolidate some machines in my server room particularly in > the testing environment and I was hoping someone could point me in the > right direction. > > I currently have three machines running PostgreSQL for testing purposes. > Each week a backup is made of the production database and this is deployed > onto these three machines. None of these machines is any where near > capacity. I would like to host all three instances on one machine. > > I know that "initdb" can be used to create additional installations, but > the part I am unsure about is the tablespace. The production database has > a tablespace defined that resides on its SSD. When I use the production > backup, I have to create a mount point on the test machine with the same > name as the one on the production database. I am not certain how I would > handle this situation if I am serving three separate instances of that > database from one computer. > From here: https://www.postgresql.org/docs/10/static/manage-ag-tablespaces.html "The directory $PGDATA/pg_tblspc contains symbolic links that point to each of the non-built-in tablespaces defined in the cluster. Although not recommended, it is possible to adjust the tablespace layout by hand by redefining these links. Under no circumstances perform this operation while the server is running. Note that in PostgreSQL 9.1 and earlier you will also need to update the pg_tablespace catalog with the new locations. (If you do not, pg_dump will continue to output the old tablespace locations.)" A quick test here showed that you can create a new directory and move the contents of the existing tablespace into it and then relink the tablespace to the new location. create tablespace tblspc_test location '/home/postgres/test_tblspc'; create table tblspc_table(id int) tablespace tblspc_test ; select * from pg_class where relname = 'tblspc_table'; -[ RECORD 1 ]-------+------------- relname | tblspc_table relnamespace | 2200 reltype | 1836557 reloftype | 0 relowner | 10 relam | 0 relfilenode | 1836555 reltablespace | 1836554 So in $DATA/pg_tblspc: 1836554 -> /home/postgres/test_tblspc/ mkdir /home/postgres/tblspc_1 cd /home/postgres/test_tblspc/ cp -r PG_10_201707211/ ../tblspc_1/ shutdown Postgres cd $DATA/pg_tblspc rm 1836554 ln -s /home/postgres/tblspc_1 1836554 start Postgres select * from pg_class where relname = 'tblspc_table'; -[ RECORD 1 ]-------+------------- relname | tblspc_table relnamespace | 2200 reltype | 1836557 reloftype | 0 relowner | 10 relam | 0 relfilenode | 1836555 reltablespace | 1836554 -- Adrian Klaver adrian.klaver@aklaver.com