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 1n7RVP-0006By-7j for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Jan 2022 00:28:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n7RVN-0003ST-7J for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Jan 2022 00:28:45 +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 1n7RVM-0003Ry-HR for pgsql-hackers@lists.postgresql.org; Wed, 12 Jan 2022 00:28:44 +0000 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1n7RVJ-0003vW-IM for pgsql-hackers@postgresql.org; Wed, 12 Jan 2022 00:28:43 +0000 Received: by mail-ed1-x52e.google.com with SMTP id w16so3004729edc.11 for ; Tue, 11 Jan 2022 16:28:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=2hIkwHD0qU8Mbt/11GmH40qjw+uco7fHYyrUud6u71Q=; b=grC95kzZwcJ6G4gZw4dnZEF4sooX/CjWLBWBL5ac7Vn/D5ByX6t+LJybYeGInmVkh9 Ro2WnyfPoZbSOfHjRBbxyiVf/8nPaUtTyl8Wmw/1S3nni4n987edbaQeeGHj7eYLdhbe 4Q2950j4AhTCNZyyB1h9RjittfG8Cj1SjbvHNZGVBdsseImyuMTjYsHkNethXsFtmF1U ePYW8ff6fy+0l2tWTlQiPC/GvSNSa0nPfx7X1NKxGdWNYLKSm7ssCzpBZXyqe6a4qui4 Q+97mLALBCgM63JIiwQ02RkF3FtsNqRRno9095JbSgt4A+2s9+Simaka5gBXrnEKKiJU yzCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=2hIkwHD0qU8Mbt/11GmH40qjw+uco7fHYyrUud6u71Q=; b=R3d3bEdWS8HBqgJZFhbcEzfgHVT+RidM27XsJySxGpHZkZAEOJlWVNsgx7atAQ7F// ILM+byMC/doN0qNog7xcZSY79EZU4c9CFDHC9zUn3YkuzBq1BDeqNgBxVoCDtoIWUA9n Vibxqytk4QK/6tBwfbVkDy0LWq+Y9IbkP+nLM/whHLJEuGkrMpPh5y6Rk4jgT7ToAuZk HLsL6rQlKHsxysHVXiagCEnB19G2wNC0wBT/ggvfwJiJl/h8dt2pKb/c8kyt2ewI9Tta r7clVnBCmD2PhxH3iqPjoPPMi9q3m4b4dsiZRwL6R0+dOVl2/sykkxmXx/PKBn6zExEw GUFQ== X-Gm-Message-State: AOAM532O1XdWibhlYcByKUuX6ZdNPb2uiqwC+8w2y9f7IrAfh1+vNTkw Nv3k1byk2q0z3tweRf3tXlD/BnT33G+ov0WRp0QC+4Gu9wgohc/FMGNrnf/aAKE0mz9e8mwANze 5P1hRmJIj694gOWSULXU4RsANqvOR/9XXu7t2klDUuI6h+HBvAtG3ptbk/VrEJKEv5AfKMmhLXQ hhem+4iSFoYNylis7g6BOyN6XwK7VwxfjTEx7e X-Google-Smtp-Source: ABdhPJwrcGU0QCpdiq0YT5WM8p4O9GVMJrQsT61PudUe2DzjikZ2saXV0GAu8xsA5iIbUhaa9gDZaw== X-Received: by 2002:a05:6402:11c7:: with SMTP id j7mr2210581edw.315.1641947318978; Tue, 11 Jan 2022 16:28:38 -0800 (PST) Received: from [10.137.0.19] (ip-86-49-251-241.net.upcbroadband.cz. [86.49.251.241]) by smtp.gmail.com with ESMTPSA id j13sm5615853edw.89.2022.01.11.16.28.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Jan 2022 16:28:38 -0800 (PST) Message-ID: <88723fed-9f4a-cf2b-0786-382e70cea7f1@enterprisedb.com> Date: Wed, 12 Jan 2022 01:28:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: More data files / forks Content-Language: en-US To: Chris Cleveland , PostgreSQL Hackers References: From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 1/11/22 19:39, Chris Cleveland wrote: > I'm working on a table access method that stores indexes in a structure > that looks like an LSM tree. Changes get written to small segment files, > which then get merged into larger segment files. > > It's really tough to manage these files using existing fork/buffer/page > files, because when you delete a large segment it leaves a lot of empty > space. It's a lot easier to write the segments into separate files on > disk and then delete them as needed. > And is that empty space actually a problem? You can reuse that for new data, no? It's a bit like empty space in regular data files - we could try keeping it much lower, but it'd be harmful in practice. > I could do that, but then I lose the advantages of having data in native > Postgres files, including support for buffering and locking. > > It's important to have the segments stored contiguously on disk. I've > benchmarked it; it makes a huge performance difference. > Yeah, I'm sure it's beneficial for sequential scans, readahead, etc. But you can get most of that benefit by smart allocation strategy - instead of working with individual pages, allocate larger chunks of pages. So instead of grabbing pages one by one, "reserve" them in e.g. 1MB chunks, or something. Not sure how exactly you do the book-keeping, ofc. I wonder if BRIN might serve as an inspiration, as it maintains revmap and actual index tuples in the same fork. Not the same thing, but perhaps similar? The other thing that comes to mind is logtape.c, which works with multiple "logical tapes" stored in a single file - a bit like the segments you're talking about. But maybe the assumptions about segments being written/read exactly once is too limiting for your use case. > Questions: > > 1. Are there any other disadvantages to storing data in my own files on > disk, instead of in files managed by Postgres? > Well, you simply don't get many of the built-in benefits you mentioned, various tools may not expect that, and so on. > 2. Is it possible to increase the number of forks? I could store each > level of the LSM tree in its own fork very efficiently. Forks could get > truncated as needed. A dozen forks would handle it nicely. > You're right the number of forks is fixed, and it's one of the places that's not extensible. I don't recall any proposals to change that, though, and even if we decided to do that, I doubt we'd allow the number of forks to be entirely dynamic. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company