Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ffGyk-0008H3-NA for pgsql-www@arkaria.postgresql.org; Tue, 17 Jul 2018 03:48:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ffGyg-0004ZP-Ns for pgsql-www@arkaria.postgresql.org; Tue, 17 Jul 2018 03:48:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ff627-0002kR-WD for pgsql-www@lists.postgresql.org; Mon, 16 Jul 2018 16:07:32 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ff625-0004Ho-EL for pgsql-www@postgresql.org; Mon, 16 Jul 2018 16:07:31 +0000 Received: by mail-wr1-x444.google.com with SMTP id e7-v6so12922058wrs.9 for ; Mon, 16 Jul 2018 09:07:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=wQgArNJn32gi3sfhP+GTWgaLeKuNQK6NI+72OaJCouE=; b=hloWmE5pOdmn+RlV2WklVy84k07QNvCiOdOqBnh8EPS7zyK5OFktAZFm5WAeAMzevF vH0J/rNsh+REMtzlnuqkgIwtNnSFTB2ZPcmHgCFFr/wmtGqWdZ0D3a4ebOGZEhYe6iIn qvzi+fwXp1G7rAl9WlaefkEbKc7+rMt9FqEcCcpg6qt9sJtyFARR5PGqW2vFg+UXKiME 8vsRNp2HaaYx82BkLnwdKKnzI2YWnVGRv2hSbC+mlad9JUJbJAVbUWet3LbcC3Mbz2pO R5NHXCfAC7/BTScZcJC3Vf+8VRN6EpcEyIJP0+Wkn/mwC0x6hIK+FtP9maCvvVwMcwRO /jVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=wQgArNJn32gi3sfhP+GTWgaLeKuNQK6NI+72OaJCouE=; b=DWjRx8nQrih66SWdPjZcJ8GYQGYb3Akcl+H6fq72OOW+o01RF/ttT7SVLMoS3Mi77q pH6I1Rp5kbQcdVdB8ZkCx8F34vtAjDTqmGBtgQrF3vmawmg5uQfBFUEwmqlRhLGFyNv6 mfHLMQtHiF6DD6lpynrADe2sIEoM+g/m2kUy/XIaY9SQGHieMgqtvZ0fUNv6ciWSzz+P GY1crwXWzG6HhNW68+dTIb/lt5Wxf3wc8Eb1zv0+aNAViy8G4r/VkrxfSu7vh+vvuePa vpq3IBve6jllcElmG0py6Ef0glkqSm165E/KYycgkCHIf+Dg8ah/lhIorfAfG9YOZ2xg N1jA== X-Gm-Message-State: AOUpUlGcMqO1fTf6DJmIxk9RNHL2yJoNg7xF/rXSlz3Me40B5lcaZZ3C zYvc7BNFuN0RK6x8+AnkQvkSE8tH X-Google-Smtp-Source: AAOMgpd21uqza9gVJh+dxZh9sCkc6AAtrI7X/iWmLhb1qaLEOiz/1b8k+nVX9XZ35nnLSYx6iIr2xQ== X-Received: by 2002:adf:c383:: with SMTP id p3-v6mr12568011wrf.68.1531757246755; Mon, 16 Jul 2018 09:07:26 -0700 (PDT) Received: from [192.168.0.21] (81-64-113-217.rev.numericable.fr. [81.64.113.217]) by smtp.gmail.com with ESMTPSA id x124-v6sm16053332wmg.38.2018.07.16.09.07.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Jul 2018 09:07:26 -0700 (PDT) Subject: Re: Wiki editor request To: Joe Conway , pgsql-www@postgresql.org References: <9b106c7b-4d27-4211-401e-26c6a7b4d4fb@gmail.com> From: "David M. Kaplan" Message-ID: <73881ed7-0e4d-4818-0bde-44bd9fe477af@gmail.com> Date: Mon, 16 Jul 2018 18:07:18 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, I have a new code snippet that I think would be a useful addition to the website, but I can't see how to create a new page and I am not sure I have the privileges to do so. Could you help me with that, perhaps creating an empty page for me to fill? The code deals with refreshing materialized views. I have a large set of materialized views that depend on each other, but I could find no way to refresh them all in the appropriate order so that you respect dependencies. I googled the problem, but all the solutions I could find just refresh all materialized views without considering dependencies among them. Therefore, I created some code to get the list of materialized views in the proper order so that they are refreshed in the proper order. The code is below. I am using it to refresh all views in a database, but it could also be used to find the dependencies of a single mat view and refresh just that subset. I would put the code in the "works for me" category as my understanding of pg_* tables is limited, but I think it is useful as is. Cheers, David -------------------------------------------------- --- A view giving the list of mat views that depend --- on each mat view -------------------------------------------------- CREATE OR REPLACE VIEW mat_view_dependencies AS WITH RECURSIVE s(start_schemaname,start_mvname,schemaname,mvname,mvoid,depth) AS ( -- List of mat views -- with no dependencies SELECT n.nspname AS start_schemaname, c.relname AS start_mvname, n.nspname AS schemaname, c.relname AS mvname, c.oid AS mvoid, 0 AS depth FROM pg_class c JOIN pg_namespace n ON c.relnamespace=n.oid WHERE c.relkind='m' UNION -- Recursively find all things depending on previous level SELECT s.start_schemaname, s.start_mvname, n.nspname AS schemaname, c.relname AS mvname, c.oid AS mvoid, depth+1 AS depth FROM s JOIN pg_depend d ON s.mvoid=d.refobjid JOIN pg_rewrite r ON d.objid=r.oid JOIN pg_class c ON r.ev_class=c.oid AND c.relkind='m' JOIN pg_namespace n ON n.oid=c.relnamespace WHERE s.mvoid <> c.oid -- exclude the current MV which always depends on itself ) SELECT * FROM s; -------------------------------------------------- --- A view that returns the list of mat views in the --- order they should be refreshed. -------------------------------------------------- CREATE OR REPLACE VIEW mat_view_refresh_order AS WITH b AS ( -- Select the highest depth of each mat view name SELECT DISTINCT ON (schemaname,mvname) schemaname, mvname, depth FROM mat_view_dependencies ORDER BY schemaname, mvname, depth DESC ) -- Reorder appropriately SELECT schemaname, mvname, depth AS refresh_order FROM b ORDER BY depth, schemaname, mvname ; -------------------------------------------------- --- Query to return the code to refresh all mat views in proper order --- Should be a function, but haven't created that yet. --- Instead, put code in a psql variable and then --- execute that. -------------------------------------------------- WITH a AS ( SELECT 'REFRESH MATERIALIZED VIEW "' || schemaname || '"."' || mvname || '";' AS r FROM mat_view_refresh_order WHERE schemaname='dmk' ORDER BY refresh_order ) SELECT string_agg(r,E'\n') AS script FROM a \gset \echo :script -- :script On 04/29/2018 01:18 AM, Joe Conway wrote: > On 04/27/2018 03:19 AM, David M. Kaplan wrote: >> I noticed something that I do not think is correct on the PostgreSQL >> wiki and would like to edit it, but don't have the privileges. Could you >> either edit it for me or give me the privileges? My account is based on >> my gmail dmkaplan2000@gmail.com > Edit privilege granted. > > Joe >