Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sIZiO-00Ga7C-KT for pgsql-general@arkaria.postgresql.org; Sat, 15 Jun 2024 20:09:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sIZiL-00Gq3t-6i for pgsql-general@arkaria.postgresql.org; Sat, 15 Jun 2024 20:09:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sIZiK-00Gq3l-OZ for pgsql-general@lists.postgresql.org; Sat, 15 Jun 2024 20:09:29 +0000 Received: from mail-qv1-xf29.google.com ([2607:f8b0:4864:20::f29]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sIZiI-001qoO-Rl for pgsql-general@lists.postgresql.org; Sat, 15 Jun 2024 20:09:29 +0000 Received: by mail-qv1-xf29.google.com with SMTP id 6a1803df08f44-6b064c4857dso16146996d6.2 for ; Sat, 15 Jun 2024 13:09:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718482163; x=1719086963; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=WYC0SJY0ZrcNvKbrr2ftsrvRyMPrvZpKZxfUMItdY3w=; b=jRlzxb1RfFB+q2PGkwhCQtdSQdVje899bGmpOILzI87IE+QlkYXXCRb2nlfkibwLZ1 p57lq+w0B/G/N2riHZw3hMgBcEzuroL7GQHRGSXKjTkYPsQ6qdpGj57k+QKADdyunJdI Fbrd5MH+Hi7SBCbGoS6+s4LcCEKiCfR/K3NAUadfWOCUDAlXrjhPZDjFoyiUiGwJncW8 9vM/P9v/UazOIRhtpj3NZCco37URw/qrMpdtqLJ7dFZkLyEzjXqYKSY8xxiexU3ukSN5 3KaL+MBw58rTxAadoUAEUjVwfvOvPagPmj70hVoYZnDK9Li0qr6fC2IrGUqS5iWB+/vR HHrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718482163; x=1719086963; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WYC0SJY0ZrcNvKbrr2ftsrvRyMPrvZpKZxfUMItdY3w=; b=a1JSH5mK3yn9QHiZhwDPggYe88a9qmG6887NuaMVfI209Qc30QlkNNPt3hOPrMnDPy 84xkwHRcsxS0DbxTH34Fvq2pxVsbRXQ04Gwm5Hnaof6p2vfvSBCvF+jjIHqwRXAw5zDd UFO7UKKi3jFilRS6XNXH4M+AKpSRN2WM0LDJTUX5QWs2bzJYZAGKDa+eNFia8mmoFvpl kEuuTQlg15z0jb5Cgh7/rEChZq+itppahY8haVdHmNq4o0bv83Cq88ZN1G2XVnG1iEcF xbgtVBNBpGLZXlLLmSo2NhEEiRknN+lfDKespMYSc4YFqtcO1jxdIuERMWJy/MV99tBY 21mA== X-Forwarded-Encrypted: i=1; AJvYcCVEZf0fXcvNPLghlTJ6brdGvkLZYXhrrRybdjL1a+bTurKGrUCQ4FStLOoYE3UF/PlR3KH3kPCFXezCXctKDQlYW4+6PhuW6kWN4ohZVcGp7u+4 X-Gm-Message-State: AOJu0YxVNTxlpN2NWAJ7sqgbRrLsgc5utglygyx8i0oNDodTzytoF1YI 9KaDWLOZSHeBLFg45bWELJ/rp+Qq0RAgFud2lCzLnnlFbBQZGQrZKSGDmP5ZyMlL+E0+rEPznjy pwk7XNgo4GFBSAlEPmtb9ApLIjvI= X-Google-Smtp-Source: AGHT+IF+unyl+cHb5zMQiQv8YgvhfV+Ali/lPCfUI9XuBaTiJUc6ZgGapwaf3FRI2LjwWwuWCfAh3poPy7XjSXiuLeA= X-Received: by 2002:a0c:c203:0:b0:6b0:77fb:8f19 with SMTP id 6a1803df08f44-6b2afd6cb2cmr59787316d6.47.1718482163640; Sat, 15 Jun 2024 13:09:23 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: yudhi s Date: Sun, 16 Jun 2024 01:39:11 +0530 Message-ID: Subject: Re: Design for dashboard query To: Sushrut Shivaswamy Cc: sud , pgsql-general Content-Type: multipart/alternative; boundary="000000000000eab269061af34e25" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000eab269061af34e25 Content-Type: text/plain; charset="UTF-8" > > > On Sat, 15 Jun 2024 at 6:54 PM, sud wrote: > >> Hello All, >> >> Its postgres version 15.4. We are having a requirement in which >> aggregated information for all the users has to be displayed on the UI >> screen. It should show that information on the screen. So basically, it >> would be scanning the full table data which is billions of rows across many >> months and then join with other master tables and aggregate those and then >> display the results based on the input "user id" filter. >> >> In such a scenario we are thinking of using a materialized view on top of >> the base tables which will store the base information and refresh those >> periodically to show the data based on the input user id. However i am >> seeing , postgres not supporting incremental refresh of materialized view >> and full refresh can take longer. So , do we have any other option >> available? Additionally , It should not impact or block the online users >> querying the same materialized view when the refresh is happening. >> >> >> Yes incremental refresh is by default not available but you can do the refresh using "concurrently" keyword which will be online i believe and won't block your ongoing queries if any. And there are some other ways like create another view(say mv_new) with exactly the same definition and refresh that with whatever interval you want and then switch the views with the original one using the rename command. ALTER MATERIALIZED VIEW mv RENAME TO mv_old; ALTER MATERIALIZED VIEW mv_new RENAME TO mv; DROP MATERIALIZED VIEW mv_old; Or have a log table created (say transaction_log) and populate it using triggers with each delta insert/update/delete on the transaction table. And then schedule a cron job which will periodically flush the rows from the transaction_log table to the materialized view. This will achieve your incremental refresh. --000000000000eab269061af34e25 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Sat, 15 Jun 2024 at 6:54 PM, sud <suds1434@gmail.com> wrote:
<= p dir=3D"ltr">Hello All,

Its postgres = version 15.4. We are having a requirement in which aggregated information f= or all the users has to be displayed on the UI screen. It should show that = information on the screen. So basically, it would be scanning the full tabl= e data which is billions of rows across many months and then join with othe= r master tables and aggregate those and then display the results based on t= he input "user id" filter.

In such= a scenario we are thinking of using a materialized view on top of the base= tables which will store the base information and refresh those periodicall= y to show the data based on the input user id. However i am seeing , postg= res not supporting incremental refresh of materialized view and full refres= h can take longer. So , do we have any other option available? Additionally , It should not impact or block the online users querying the= same materialized view when the refresh is happening.



Yes incremental refresh is by default not available but you can do the re= fresh using "concurrently" keyword which will be online i believe= and won't=C2=A0block your=C2=A0ongoing=C2=A0 queries if any.=C2=A0

And there are some other ways like create another vie= w(say mv_new) with exactly the same definition and refresh that with whatev= er interval you want and then switch the views with the original one using = the rename command.


ALTER MATERIALIZED VIEW mv= RENAME TO mv_old;
ALTER MATERIALIZED VIEW mv_new RENAME TO mv;
DROP = MATERIALIZED VIEW mv_old;

Or

have a log table created (say transaction_log) and populate it usin= g triggers with each delta insert/update/delete on the transaction table. A= nd then schedule a cron job which will periodically flush the rows from the= transaction_log table to the materialized view. This will achieve your inc= remental refresh.

--000000000000eab269061af34e25--