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 1khw4R-0006ny-3F for pgsql-admin@arkaria.postgresql.org; Wed, 25 Nov 2020 14:46:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1khw4Q-00017K-1s for pgsql-admin@arkaria.postgresql.org; Wed, 25 Nov 2020 14:46:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1khw4P-00017D-Qm for pgsql-admin@lists.postgresql.org; Wed, 25 Nov 2020 14:46:57 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1khw47-0005D3-Vm for pgsql-admin@postgresql.org; Wed, 25 Nov 2020 14:46:56 +0000 Received: by mail-ej1-x631.google.com with SMTP id a16so3366131ejj.5 for ; Wed, 25 Nov 2020 06:46:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=S1C46J1tDiNf0+q+tYtut7uhRbU5ctsCkgJ+58TDbO4=; b=FBL0DmmerbzM2+Ai4SXieTaRHu2zpnppL2NxOSOUsLZJ0dreVZAJvkIIHfm6FPJ9wW ezQwXLl8H85gAHxzsGypDF1dYrBtookuhzZcAzkl/569GFQCGeqL4ISZM+v+wMK3iGkU we8u+yJuJNc0VOPThGyFoKsSggqdNZckCAf9n1VRMpvKHNnAq4uwQsrH45pOz4XYoMkD rSnu5kEy726vjfJwoPSOhomRdxU9OdAh94r4VnIyrClVap4LKxNUp+4aZsd0avg8pJUd 5k8MoUG9iiiraEJ8bKHgOl6k/boirfUzlX6jIlirJILlvIEvQbHZ+ulrU2uCyfUXvjd3 tjkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=S1C46J1tDiNf0+q+tYtut7uhRbU5ctsCkgJ+58TDbO4=; b=X9TOK2EA/O/U4HUpAWKkU8ca1cyAMnBppjLrA89ww8fadAU32igQtIdI+RWOEmvI0X rtXd7RDBLZG+YuZntjHxhyqaixLe0vLkz+tt5m2pAciKU/d7FzHhEOBDJq6nMCmmv8Bj qPfQHICeKIU0LKP5JzzwXhcI3YZYVWyuZlXxSpZIewat4h3KN8f+QJTtLvR33E1lOBqa OWQnHzNuLD68CRVsoIdft2OPcWPPRR6mgU5BSvTqUatIr5oQjJCTEJwXAsFdxDVBommt SpodIoNpG38K5tOZKWW6xSqE2kUmKRPKcvUguHlG4O6CjckVQPUQ2kTgvy1bi+Vh+Icy w1iQ== X-Gm-Message-State: AOAM533zCc7z2lveCw5iqCQRp9+yUnI0pgoASZ+/RK9tbPkVjH/WrjJF U0A+Y417EPWpQKkgvjHs8yOWS/DvGeSh9g== X-Google-Smtp-Source: ABdhPJw7J1U35AqbO5sN1ecaqXxQR88fDz7BorJRBuFyevJUY775DiHjyuJQgm2+7fGQ/McbluJP2Q== X-Received: by 2002:a17:906:1282:: with SMTP id k2mr3309425ejb.554.1606315598394; Wed, 25 Nov 2020 06:46:38 -0800 (PST) Received: from dynamic-dz4fdwzsoyt52ud39-pd01.res.v6.highway.a1.net (dynamic-dz4fdwzsoyt52ud39-pd01.res.v6.highway.a1.net. [2001:871:5c:14f:d00f:1a25:faaf:63c5]) by smtp.gmail.com with ESMTPSA id j6sm1424844edy.87.2020.11.25.06.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 06:46:37 -0800 (PST) Message-ID: <09ff8c81a3ecb764bbfec33baf432295a884c19e.camel@cybertec.at> Subject: Re: Hot standby with hot_standny_feedback enabled: cancelling statement issues From: Laurenz Albe To: =?UTF-8?Q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C_?= =?UTF-8?Q?=D0=92=D1=8B=D1=81=D0=BA=D0=BE=D1=80=D0=BA=D0=BE?= , "pgsql-admin@postgresql.org" Date: Wed, 25 Nov 2020 15:46:37 +0100 In-Reply-To: <6184231606295846@mail.yandex.ru> References: <6184231606295846@mail.yandex.ru> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-1.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, 2020-11-25 at 16:46 +0700, Игорь Выскорко wrote: > I'm trying to configure hot standby replica for analytics and simple backup purposes. So, I have long queries which constantly cancelled without proper configuring. > I do not want large lag on replica (more than 30 mins) so setting max_standby_streaming_delay to -1 is not my choice. I have to avoid large lag because of analytic queries which must be run on > almost fresh copy of data. > I found the panacea (I thought I found actually) in setting hot_standby_feedback = on (I know about possible master bloating) but it also doesn't help. > Just to clarify about "simple backup purposes": it means run pg_dump in daily basis. Our database is about 250Gb > > 2 test run of pg_dump failed with: > pg_dump: Dumping the contents of table "table" failed: PQgetResult() failed. > pg_dump: Error message from server: ERROR: canceling statement due to conflict with recovery > DETAIL: User was holding a relation lock for too long. > pg_dump: The command was: COPY... > > postgres=# select * from pg_stat_database_conflicts ; > datid | datname | confl_tablespace | confl_lock | confl_snapshot | confl_bufferpin | confl_deadlock > -----------+---------------+------------------+------------+----------------+-----------------+---------------- > 12445 | dbname | 0 | 2 | 0 | 0 | 0 > > Not sure about what kind of lock was holding too long... > > So, my questions are: > 1. Why "hot_standby_feedback = on" is not helping? Because is was not a conflict with a tuple deleted by VACUUM ("snapshot conflict"), but with a lock. ACCESS EXCLUSIVE locks are replicated, because they are necessary for safe replication of commands like TRUNCATE or ALTER TABLE. If you ran none of these commands on the primary, you probably have fallen prey to "vacuum truncation", where a brief ACCESS EXCLUSIVE lock is taken on a table so that VACUUM can truncate some empty pages from a table. These locks don't disrupt operation on the primary, but they can conflict with queries on the standby. > 2. What is proper way to use replica for tasks as mine? The best thing is to have two standbys: one for high availability that does not lag (hot_standby = off), and one for pg_dump and queries. You may want to read my blog on the topic: https://www.cybertec-postgresql.com/en/streaming-replication-conflicts-in-postgresql/ Yours, Laurenz Albe