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 1fw6uW-0000xt-Uj for pgsql-admin@arkaria.postgresql.org; Sat, 01 Sep 2018 14:30:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fw6uU-0004Qd-RU for pgsql-admin@arkaria.postgresql.org; Sat, 01 Sep 2018 14:29:58 +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 1fw6uU-0004QW-Jr for pgsql-admin@lists.postgresql.org; Sat, 01 Sep 2018 14:29:58 +0000 Received: from st14p37im-asmtp001.me.com ([17.41.209.30]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fw6uS-0006x1-CJ for pgsql-admin@lists.postgresql.org; Sat, 01 Sep 2018 14:29:58 +0000 Received: from process-dkim-sign-daemon.st14p37im-asmtp001.me.com by st14p37im-asmtp001.me.com (Oracle Communications Messaging Server 8.0.2.2.20180531 64bit (built May 31 2018)) id <0PED00700S64LC00@st14p37im-asmtp001.me.com> for pgsql-admin@lists.postgresql.org; Sat, 01 Sep 2018 14:29:53 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mac.com; s=04042017; t=1535812193; bh=vJUFhuW3WcUu4PBIfWSw+vXZYGmpfGs8FLjcjaBajtM=; h=Content-type:MIME-version:Subject:From:Date:Message-id:To; b=KG4/GoIghbfwZXM2OKlZZgOQf4nXx0L0WREr7zj497ozvZArXeD3DcwoMHl4MTaEE xOcZp9Z4WuwDyv8YYJNVf+ujl1cL35UX1klaI++ZFSJhfVbgeBZZWWrN7k/Q2x4S6O 0PVhIRbfYGstbOpPC0aaCR3eaYXLA6aIj8MY6hgmimlNn0wGNbN1zyY/+gCH+WjvMT sVX69F2OlYjOSNkp+BoLsiZ/8VzCSjofH+t3PirMN3QeGkLzV86Ms69F0mDCWB1AxR 052QBrrgSoRIFcKbjR+pUwUbvtWoEZ89F+yzduPQ0X3vm27RagLYN4hpDSZjQqXUVa Udt2MVp3P2K2g== Received: from icloud.com ([127.0.0.1]) by st14p37im-asmtp001.me.com (Oracle Communications Messaging Server 8.0.2.2.20180531 64bit (built May 31 2018)) with ESMTPSA id <0PED00DCQS9RX610@st14p37im-asmtp001.me.com>; Sat, 01 Sep 2018 14:29:53 +0000 (GMT) X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 clxscore=1011 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1809010164 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-09-01_08:,, signatures=0 Content-type: text/plain; charset=utf-8 MIME-version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: Re: Archive to secondary Postgres instance From: Evan Bauer In-reply-to: Date: Sat, 01 Sep 2018 10:29:50 -0400 Cc: pgsql-admin@lists.postgresql.org Content-transfer-encoding: quoted-printable Message-id: <59930584-CF26-46B2-A4C9-B1AE77ED8ECC@mac.com> References: To: David Rydzewski X-Mailer: Apple Mail (2.3445.9.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk David, Your approach #1 is one that has been proven for years in both commerce = and securities trading applications. The pitfalls in approach #2 have = always made it too problematic for me =E2=80=94 regardless of the DBMS = involved. A third approach is to use a change data capture (CDC) tool. These = tools manage rules-based asymmetric replication between databases =E2=80=94= it basically provides your option #1 with a logical definition of the = transfer, provides both seeding and catchup capabilities, but without = having to manage a ton of replication scripts. I=E2=80=99ve used the = approach for large-scale financial services applications where the = =E2=80=9Ctrade=E2=80=9D database of active transactions has to be = incredibly fast (and therefore small with short-lived rows), and the = "trade-history=E2=80=9D database needs to maintain years of data for = compliance and analysis. The asymmetric publisher to subscriber = relationship allows for all kinds of interesting indexing and = aggregation through materialized views in the history database that you = could never afford in the =E2=80=9Clive=E2=80=9D OLTP database. Talend is the commercial open source leader in this area for = database-to-database CDC replication; my limited experience with it = (though not with PostgreSQL) has been good. Debezium is based on Apache = Kafka, looks promising, but requires both an extension for PostgreSQL = publishers and a custom application on the subscriber side. There are a = number of commercial products in this space as well. IBM=E2=80=99s = InfoSphere CDC product is the one I know best, but it is both = proprietary and (when I last looked) had limited PostgreSQL support. = There is a list of other alternatives on the PostgreSQL wiki at: = https://wiki.postgresql.org/wiki/Ecosystem:Replication Cheers, - Evan Evan Bauer eb@evanbauer.com +1 646 641 2973 Skype: evanbauer > On Aug 31, 2018, at 21:57, David Rydzewski = wrote: >=20 > I have a postgres database that is doubling in size each year and = contains many online orders that were delivered long ago and are now = dormant in the database. >=20 > My desire is to offload these dormant orders to a secondary Postgres = instance, so that the information is still available for viewing = purchase history, while keeping the active orders in the main, and = eventually smaller Postgres instance. >=20 > These orders live in a highly normalized model that spans over 30 = tables. >=20 > I have thought of two approaches to handle this "archiving" use case. >=20 > One approach is pull based. As orders naturally go dormant, execute = custom SQL to move this information into the secondary postgres = instance. A separate process would then purge this order information = from the main database after a period of time (e.g., custom deletes). = The upside is that the process is fairly lightweight and = straightforward. The downside is you have to maintain two data models = and the SQL scripts whenever the data model changes. >=20 > Second approach is logical replication. The upside is that you don't = have to maintain two data models separately. The downside is that it = becomes very tricky to differentiate between a "normal" delete, which = you would want to apply on the secondary instance versus an "archive" = delete which you wouldn't want to apply on the secondary. It could also = get complex when replication fails and you have to re-initiate the = stream. >=20 > My question is whether anyone else has solved this and if so, how? I'm = leaning toward pull-based, because replication doesn't feel right with = the complexity around "selective" deletes, and other replication failure = scenarios. >=20 > Thanks! >=20 >=20 >=20 >=20 >=20