Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y7fN5-0007om-2C for pgsql-admin@arkaria.postgresql.org; Sun, 04 Jan 2015 07:13:07 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y7fN4-00080m-IS for pgsql-admin@arkaria.postgresql.org; Sun, 04 Jan 2015 07:13:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Y7fN2-00080c-I8 for pgsql-admin@postgresql.org; Sun, 04 Jan 2015 07:13:04 +0000 Received: from mout.kundenserver.de ([212.227.17.24]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Y7fMy-0000P0-7o for pgsql-admin@postgresql.org; Sun, 04 Jan 2015 07:13:03 +0000 Received: from nara.local ([180.0.149.54]) by mrelayeu.kundenserver.de (mreue102) with ESMTPSA (Nemesis) id 0LymAB-1XnMQ31uXX-0164HJ; Sun, 04 Jan 2015 08:12:57 +0100 Message-ID: <54A8E7F3.8080307@2ndquadrant.com> Date: Sun, 04 Jan 2015 16:12:51 +0900 From: Ian Barwick User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: "Zheng, Wendy" , "pgsql-admin@postgresql.org" Subject: Re: The quickest way to migrate database within the same cluster References: <1F7AF1B52D1DAC439765CCD7F7952AD42CF5BC@MX101CL01.corp.emc.com> In-Reply-To: <1F7AF1B52D1DAC439765CCD7F7952AD42CF5BC@MX101CL01.corp.emc.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K0:ilhZdXWLEjcK8jGatYIu1uHOvvFZU3cJZQhAd9x/ZJknEHVhZLf eskzIoMOR184myo+5xbrhWcskvepCLf47fSsWah1ZFJZQf+AMMu0KkgujY+Hp+x2NkVwynb PhdH+143xax3dq90vOLIupPR/uJwAh5YoF4ou2f8nirRoK8dBxTd27Ofw9bhJQ5AznXo66t WePWUj6XfN/fd/+1uQPbQ== X-UI-Out-Filterresults: notjunk:1; X-Pg-Spam-Score: -2.5 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org On 15/01/04 15:52, Zheng, Wendy wrote: > Hi PgSql experts, > > I’m working on a task to move tables from on database to another within > the same cluster and same server. I try the pg_dump and pg_restore commands > (with –Fc option), and notice that it costs around half an hour which is > not acceptable. Then I try to move the data files directly. I create the > same tables in the new DB, find out the directory stores the data file > and search for the data files by the table name, then move the corresponding > data file in the old DB to the new one. This is very quick, and looks like the > DB still works. But I have a concern that whether there will any other problem > if I doing this? Yes, you'll experience massive data corruption. You can't just manually copy data files around, even though it might seem to work. > Another workaround is to access the old DB in the new DB with dblink > (I created a view with dblink and use it as if the view as if the table > is in the new DB). But we soon notice that even though we specify the > criteria in the select command, dblink will still retrieve all the > records first, and then apply the search criteria. This brings poor > performance. Do you have any better idea how can I handle this? Which PostgreSQL version are you using? If 9.3 or later you can use a foreign data wrapper (postgres_fdw) to access data in another database (including on the same cluster). Regards Ian Barwick -- Ian Barwick http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, RemoteDBA, Training & Services -- Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-admin