Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oQe47-0004bg-UL for pgsql-general@arkaria.postgresql.org; Wed, 24 Aug 2022 00:16:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oQe45-0002Nn-Be for pgsql-general@arkaria.postgresql.org; Wed, 24 Aug 2022 00:16:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oQe44-0002Kz-Vm for pgsql-general@lists.postgresql.org; Wed, 24 Aug 2022 00:16:13 +0000 Received: from mail-oa1-x36.google.com ([2001:4860:4864:20::36]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oQe3t-0005u3-NB for pgsql-general@lists.postgresql.org; Wed, 24 Aug 2022 00:16:11 +0000 Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-11c5ee9bf43so18779850fac.5 for ; Tue, 23 Aug 2022 17:16:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc; bh=fLB+vaBRLxXpfPrnoVcpWmbdcXiWprUzIL6I41NmyHA=; b=q6lhrauev/HJKLEhhGHPbtb1ePzZ3M9OWctbXY6bSQcktD+p6eTbUg2LtBMrKZ+Wo3 +AneDjR0+TRD5n5YKPZUNWnNZcdOzS1u4uDqjcT+3WKtPHPdSxuKRdmUPYmXYWFjqxHe ZlCgfHyNsHff3VDLdptVGcI+R7VYoM088AkCTD9JNOw6W+yhjPCljEaMFeJFCMB4VyN+ +gpI7O1wdV7I2JeZy+xuNx73zMYMroNBiRqW3RKG17G4beAld2OWIx8rpKcE1svOU4WQ cnB4UPDeHf3hbY71LV3ZItIEhhB7fMqMFmSWdB8FGtGDNlAlunlcKiRX0oPq+vBGJgNP 3xPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc; bh=fLB+vaBRLxXpfPrnoVcpWmbdcXiWprUzIL6I41NmyHA=; b=nEMUB0VRoyLRgQJXm1/LKearrDQndfqHZc//nyDXs2pePI+Y62KRLfx2FeFkbOXQcH bKuHEXGClz7QQ3T1ir55L8N+chaZYidfVqN9gS2jGm9cltdV9wU5FaIRvYWSM7tVyFW+ Fp81ajxYeLWijGAYGpwISoYDsqtoe1dqvFVqQFse4vx/NysrJQZW3Empt4dC6fx6SFr0 xRpyC6VXw0ubV+dJePDnVu7ds9AGrzbk2he5WH9xvxYWAdoVoCu4VRGTnhFrlOvEL4xv MiYQKAeZCmIOtH3Wm3EjFWltSP/MBc9OALg8N5mOb0MDcw2HAwLY56+KVN8way18b8Tl NXNQ== X-Gm-Message-State: ACgBeo0yq4z0DRHDHfEJIE295O/DOiAeaN03ZmNA2Lw9+YfW7J72yT7x o8G7FVmPYrROif0NDiHG6fWSZ9syLQ0= X-Google-Smtp-Source: AA6agR7Qp6+e6QYzW1tLTcUKUoe+PO0lwvWuToAaa97g9YzJyxEXlSAokNXC+gGMFEuFkSEftjBS2g== X-Received: by 2002:a05:6870:600e:b0:115:8100:1947 with SMTP id t14-20020a056870600e00b0011581001947mr2515547oaa.134.1661300159438; Tue, 23 Aug 2022 17:15:59 -0700 (PDT) Received: from [192.168.88.10] (ip68-11-68-85.no.no.cox.net. [68.11.68.85]) by smtp.googlemail.com with ESMTPSA id u19-20020a4a6153000000b0044897475dd0sm3534000ooe.43.2022.08.23.17.15.58 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Aug 2022 17:15:59 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------0Q0nSGjwiN306CdG4bobQ16m" Message-ID: Date: Tue, 23 Aug 2022 19:15:58 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: Setting up a server with previous day data Content-Language: en-US To: pgsql-general@lists.postgresql.org References: From: Ron In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------0Q0nSGjwiN306CdG4bobQ16m Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 7/19/22 02:22, Srinivasa T N wrote: > Hi All, >    I have a primary postgresql 12 server which is being continuously used > for transaction processing.  For reporting purposes, I want to set up a > secondary server which has got previous day data.  Everyday night, I want > the data from primary to be shifted to secondary.  I can achieve this > manually using pg_basebackup on primary and pg_restore on secondary.  Is > there any other automated efficient way to achieve the same?  Any relevant > docs would be helpful. We populated a "reporting" database from the OLTP database (not PostgreSQL) by creating "/X/_log1" and "/X/_log2" tables which had the same columns as relevant "main" tables, plus an ACTION_CODE with values 'I", "U" or "D", and a datetime field which defaults to CURRENT_TIMESTAMP. ON INSERT, ON UPDATE and ON DELETE triggers were added to the "main" tables which inserted into X_log2 on even days, and into X_log1 on odd days. Soon after midnight, a cron job dumped "yesterday's" _log table, loaded it into the reporting table, and then truncated the _log table. That was before someone developed a utility to convert the roll-forward logs into INSERT, UPDATE and DELETE statements. Such a utility for PostgreSQL that would convert yesterday's WAL files into SQL would /really/ solve your problem. -- Angular momentum makes the world go 'round. --------------0Q0nSGjwiN306CdG4bobQ16m Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit On 7/19/22 02:22, Srinivasa T N wrote:
Hi All,
   I have a primary postgresql 12 server which is being continuously used for transaction processing.  For reporting purposes, I want to set up a secondary server which has got previous day data.  Everyday night, I want the data from primary to be shifted to secondary.  I can achieve this manually using pg_basebackup on primary and pg_restore on secondary.  Is there any other automated efficient way to achieve the same?  Any relevant docs would be helpful.

We populated a "reporting" database from the OLTP database (not PostgreSQL) by creating "X_log1" and "X_log2" tables which had the same columns as relevant "main" tables, plus an ACTION_CODE with values 'I", "U" or "D", and a datetime field which defaults to CURRENT_TIMESTAMP.

ON INSERT, ON UPDATE and ON DELETE triggers were added to the "main" tables which inserted into X_log2 on even days, and into X_log1 on odd days.

Soon after midnight, a cron job dumped "yesterday's" _log table, loaded it into the reporting table, and then truncated the _log table.

That was before someone developed a utility to convert the roll-forward logs into INSERT, UPDATE and DELETE statements.

Such a utility for PostgreSQL that would convert yesterday's WAL files into SQL would really solve your problem.

--
Angular momentum makes the world go 'round.
--------------0Q0nSGjwiN306CdG4bobQ16m--