Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3xEk-00038G-QB for pgsql-general@arkaria.postgresql.org; Wed, 13 Mar 2019 06:19:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h3xEj-0006Cm-DP for pgsql-general@arkaria.postgresql.org; Wed, 13 Mar 2019 06:19:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3xEj-0006Ce-1c for pgsql-general@lists.postgresql.org; Wed, 13 Mar 2019 06:19:33 +0000 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5] helo=mx0a-001b2d01.pphosted.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3xEg-0007Uf-9n for pgsql-general@postgresql.org; Wed, 13 Mar 2019 06:19:31 +0000 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x2D6EKnA009741 for ; Wed, 13 Mar 2019 02:19:29 -0400 Received: from smtp.notes.na.collabserv.com (smtp.notes.na.collabserv.com [192.155.248.74]) by mx0a-001b2d01.pphosted.com with ESMTP id 2r6v48gy4g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 13 Mar 2019 02:19:29 -0400 Received: from localhost by smtp.notes.na.collabserv.com with smtp.notes.na.collabserv.com ESMTP for from ; Wed, 13 Mar 2019 06:19:28 -0000 Received: from us1a3-smtp07.a3.dal06.isc4sb.com (10.146.103.14) by smtp.notes.na.collabserv.com (10.106.227.92) with smtp.notes.na.collabserv.com ESMTP; Wed, 13 Mar 2019 06:19:25 -0000 Received: from us1a3-mail151.a3.dal06.isc4sb.com ([10.146.38.115]) by us1a3-smtp07.a3.dal06.isc4sb.com with ESMTP id 2019031306192499-86837 ; Wed, 13 Mar 2019 06:19:24 +0000 In-Reply-To: Subject: Re: PostgreSQL logical replication slot LSN values From: "Rashmi V Bharadwaj" To: Andres Freund Cc: pgsql-general@postgresql.org Date: Wed, 13 Mar 2019 06:19:25 +0000 MIME-Version: 1.0 Sensitivity: Importance: Normal X-Priority: 3 (Normal) References: ,<20190312153655.czuj2ewdgwodwtd6@alap3.anarazel.de>, X-Mailer: IBM iNotes ($HaikuForm 1041) | IBM Domino Build SCN1812108_20180501T0841_FP30 February 15, 2019 at 14:01 X-LLNOutbound: False X-Disclaimed: 60103 X-TNEFEvaluated: 1 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 x-cbid: 19031306-7581-0000-0000-00000B4387E6 X-IBM-SpamModules-Scores: BY=0; FL=0; FP=0; FZ=0; HX=0; KW=0; PH=0; SC=0.40962; ST=0; TS=0; UL=0; ISC=; MB=0.003991 X-IBM-SpamModules-Versions: BY=3.00010749; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000281; SDB=6.01173632; UDB=6.00613639; IPR=6.00954295; BA=6.00006257; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00025956; XFM=3.00000015; UTC=2019-03-13 06:19:27 X-IBM-AV-DETECTION: SAVI=unsuspicious REMOTE=unsuspicious XFE=unused X-IBM-AV-VERSION: SAVI=2019-03-13 03:57:39 - 6.00009687 x-cbparentid: 19031306-7582-0000-0000-00007254D325 Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-03-13_04:,, signatures=0 X-Proofpoint-Spam-Reason: safe List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk The PGReplicationStream.setAppliedLSN is only applicable for physical repli= cation, right? So this may not actually make a difference for my logical re= plication program. Periodically running the utility for setting the flush LSN using PGReplicat= ionStream.setFlushedLSN should still work for the feedback mechanism right? Thanks, Rashmi -----"Rashmi V Bharadwaj" wrote: ----- To: Andres Freund From: "Rashmi V Bharadwaj" Date: 13/03/2019 10:59AM Cc: pgsql-general@postgresql.org Subject: Re: PostgreSQL logical replication slot LSN values Hi, > Well, did you consume the logical data, and if so how? When you use the > streaming interface - HIGHLY recommended - you need to send feedback > messages as to where you've received the data. Yes, I am consuming data using the PGReplicationStream.readPending() m= ethod in my program. > Hm, that should not happen. Did you by any chance externally (manually > or by script) delete WAL files? No, I am not deleting the WAL files externally. > You need to send feedback messages confirming up to wher eyou've > consumed the data when using the streaming protocol. When using the SQL > functions the =5Fget=5F function confirms when it returns, the =5Fpeek=5F > function never does so. It's recommended to limit the size of the > resultset a bit using the nchanges paramter so you can call it in > smaller increments. I am sending feedback messages using method PGReplicationStream.setAp= pliedLSN(). I cannot do PGReplicationStream.setFlushedLSN() as I = want the option to go back and read data in case of data loss. I have a sep= arate utility that can be used to set the flush=5Flsn position periodically. Currently since the WAL file was deleted by postgresql, I am not able to mo= ve forward at all - replication thru the SQL or Java API is not happening. = I tried doing a PGReplicationStream.setAppliedLSN and PGReplicationStream.s= etFlushedLSN (to current LSN) thru another Java program for the same replic= ation slot, but that didn't work. It still gives the WAL segment already re= moved error. Could you please suggest a solution for this? Is there a way to set the res= tart=5Flsn and flush=5Flsn of slot? Or is recreating the slot the only poss= ible solution? Thanks, Rashmi -----Andres Freund wrote: ----- To: Rashmi V Bharadwaj From: Andres Freund Date: 12/03/2019 09:07PM Cc: pgsql-general@postgresql.org Subject: Re: PostgreSQL logical replication slot LSN values Hi, (please don't send HTML only emails to this list) On 2019-03-12 11:08:56 +0000, Rashmi V Bharadwaj wrote: > We have an application that uses the PostgreSQL logical replication API t= o read > the changes made to the PostgreSQL database and applies it to a different > database (like Db2 etc). We are using logical replication slots for > this. Cool. > Currently I am facing an issue where the replication slot is pointing to = an > older restart=5Flsn and confirmed=5Fflush=5Flsn (like 10 days back) and t= he > corresponding WAL file is already deleted from the pg=5Fwal directory. Id= eally > this should not happen, right? Well, did you consume the logical data, and if so how? When you use the streaming interface - HIGHLY recommended - you need to send feedback messages as to where you've received the data. > since the slot is holding this LSN the wal file > should not have been deleted. Now when I try to use query like > select * from pg=5Flogical=5Fslot=5Fget=5Fchanges(,, NU= LL) >=20 > or use the logical replication API with a start position as any newer LSN= , I > get the following error: >=20 > ERROR: requested WAL segment pg=5Fwal/000000010000000000000036 has alread= y been > removed > SQL state: 58P01. Hm, that should not happen. Did you by any chance externally (manually or by script) delete WAL files? > How do I get past this issue? I have not enabled log archiving. I would a= lso > like to know how I can modify the restart=5Flsn and confirmed=5Fflush=5Fl= sn positions > of the slot? You need to send feedback messages confirming up to wher eyou've consumed the data when using the streaming protocol. When using the SQL functions the =5Fget=5F function confirms when it returns, the =5Fpeek=5F function never does so. It's recommended to limit the size of the resultset a bit using the nchanges paramter so you can call it in smaller increments. Greetings, Andres Freund