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 1lo95e-0006Bv-86 for pgsql-general@arkaria.postgresql.org; Tue, 01 Jun 2021 18:26:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lo95d-0005At-30 for pgsql-general@arkaria.postgresql.org; Tue, 01 Jun 2021 18:26:09 +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 1lo95c-0005Ak-PG for pgsql-general@lists.postgresql.org; Tue, 01 Jun 2021 18:26:08 +0000 Received: from mail-qv1-xf36.google.com ([2607:f8b0:4864:20::f36]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lo95X-0000Gv-9X for pgsql-general@lists.postgresql.org; Tue, 01 Jun 2021 18:26:07 +0000 Received: by mail-qv1-xf36.google.com with SMTP id k2so7722881qvc.5 for ; Tue, 01 Jun 2021 11:26:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=americanefficient-com.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=gGhrKaZ+FAF9xdNOhqU7fOMDyQSiy5k+noaM/swaLaY=; b=H9gBpP3RYxW6QW4eWTRcQ7Yt3jjSGJDY5CCW6fzrVuiZyUFK3Ld37qh18wCzDVNIjj I/9Po8VDYYyvP0qFhLkAaq08Y1ocMkkVcPVsMdPWK7oGHCoGGnhNJ68HW7tcuL1NAziy zX6r+kY/4kmKfMyu5FLa6uWZtv0lwXiOeV2wxW+gk8fM1bZalW7CHfeS+MWriiCc7D8B P/7si8PufHr/eKY3SZ2JmGCQZ3kgkrLmRPqBrAd0M/ewtCqVr5opRJlCyLs7mggRGluU VqPTOo3nHvmGo99h1j8QHefvgnSzWi1tZzxHBD5BnYnssQjuC10N70sgLc9NPk3HV42U Ffgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=gGhrKaZ+FAF9xdNOhqU7fOMDyQSiy5k+noaM/swaLaY=; b=kpHri0auPSdvt9ABzt38zObp3V+2MB5f3bPUO9SqRe2n6a7qvmujlzsNdhoJNKduPl 9UNUaBvz5fEGic7iM3HdEYODJxzNi76ITTV+8fB5mpuzEu/yOt/THLHUTjPlfAKiO2uP /2ye3zum9VJswWFKnOKYgsw4OocDDjsadfHsxpKGtpUPuh15VCANuB7d2S9wfnFc+iE5 mUzazTA4S7uXuGad6cIfJ+6XJpFE+ehTPPYz3XEKFSTRqobmTyXsrhs3S4nZZwftMlht Muq/fXEd0ChK7Rwgedq/2Wzva0gbsUcbzteTh0JH11DqgJ9vItYb1vWDMPjn+PSG5G/B zA3A== X-Gm-Message-State: AOAM53304x1x10V+AYxBdPNyMdkXD5YGGEIlbE3XCpyJkup29O7jRG4U Qm4jxb9vxjXgkwqcPQ9izExoaw== X-Google-Smtp-Source: ABdhPJzhhr0AJ3EsSFqbbd7wtx8yg7wCNVQa7SKuL62CVbPHI0IAMzQk23go5WQGc07OUkHqDeaG4g== X-Received: by 2002:a05:6214:766:: with SMTP id f6mr24000291qvz.17.1622571962426; Tue, 01 Jun 2021 11:26:02 -0700 (PDT) Received: from smtpclient.apple (cpe-98-26-29-163.nc.res.rr.com. [98.26.29.163]) by smtp.gmail.com with ESMTPSA id m128sm11783360qkf.134.2021.06.01.11.26.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Jun 2021 11:26:01 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.100.0.2.22\)) Subject: Re: CREATE/REFRESH MATERIALIZED VIEW planner difference? From: Philip Semanchuk In-Reply-To: Date: Tue, 1 Jun 2021 14:26:00 -0400 Cc: PostgreSQL General Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Vijaykumar Jain X-Mailer: Apple Mail (2.3654.100.0.2.22) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Jun 1, 2021, at 2:20 PM, Vijaykumar Jain = wrote: >=20 > if you are not using it concurrently, can you confirm the there are = *no active* queries on the mv. > refresh requires AccessExclusiveLock and will wait, till it gets one. > just asking if you can rule out the extended time is not due to = waiting for lock. I can confirm that it=E2=80=99s not waiting on a lock. In addition, = through the AWS CPU utilization monitor I can see that the REFRESH uses = one CPU/worker whereas the CREATE uses four. This is consistent with the = EXPLAIN ANALYZE for the CREATE which says it uses four workers. > also, can you share the plans where you see the diff. Unless I misunderstand, there is no plan for a REFRESH. EXPLAIN (ANALYZE, BUFFERS) refresh materialized view my_mat_view +-------------------------------------------+ | QUERY PLAN | |-------------------------------------------| | Utility statements have no plan structure | +-------------------------------------------+ Cheers Philip >=20 > On Tue, 1 Jun 2021 at 23:30, Philip Semanchuk = wrote: > Hi all, > Should I expect a planner difference between CREATE MATERIALIZED VIEW = and REFRESH MATERIALIZED VIEW? We have a materialized view that uses 4 = workers during CREATE but only one worker during REFRESH, and as a = result the refresh takes much longer (~90 minutes vs. 30 minutes for the = CREATE). So far this behavior has been 100% consistent. >=20 > I'm running both the CREATE and REFRESH on the same server (Postgres = 11.9 on AWS Aurora). I don't think the refresh is using one worker in = response to other things happening on the server because we=E2=80=99ve = observed this happening when the server is not busy. We're not using the = CONCURRENTLY option for REFRESH. >=20 > THanks > Philip >=20 >=20 >=20 > --=20 > Thanks, > Vijay > Mumbai, India