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 1pZLW6-0003Qr-US for pgsql-general@arkaria.postgresql.org; Tue, 07 Mar 2023 00:49:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pZLW5-0005I8-Di for pgsql-general@arkaria.postgresql.org; Tue, 07 Mar 2023 00:49:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pZLW5-0005Hz-0O for pgsql-general@lists.postgresql.org; Tue, 07 Mar 2023 00:49:21 +0000 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pZLW1-0006jC-Uq for pgsql-general@lists.postgresql.org; Tue, 07 Mar 2023 00:49:20 +0000 Received: by mail-ot1-x32f.google.com with SMTP id p13-20020a9d744d000000b0069438f0db7eso6376676otk.3 for ; Mon, 06 Mar 2023 16:49:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678150156; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=zHVy2/2afFTkoqlmNatHSePpA1/abY4Nc+xRCdTqMy0=; b=MJCgu5oUpOhyz0ixvmwAuCXRc5rYBUOTAnmoUWTThXMZ31YcKfHV9YMiM4xsoAYe6Q bWi5c221NK7qjGjb/2bZENbZoumhxWqi1repORt2M2iBJeJFWKTtOXGtm11oypvG9chK Qs/LrasiwqcGI4W9u19kbN9iOj6jaKur4zcG4uypVX0xWj45yUHnn6cMkM+3lGteufBk vSYSy/bq+KjyVeop29rw7W3Vn0N1hqyc8BGdPspXa00GyVYvtp39VRLPaDh99Y+MlhHO 45kWS9c3Nc2FHqSt+AKfvcnjNysbvm3D5s8nkEFqkgyCH0TAMTmTdBzTFF0AvX+eUVvT sdtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678150156; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=zHVy2/2afFTkoqlmNatHSePpA1/abY4Nc+xRCdTqMy0=; b=Fr7VvVvHkgQsHtw/7XNWiuUVgIxeskzfw/g4zp/KUGfxjPd/2kw1m18FPkCQZz3jMK XbmAfd0viCtubuOq91jXklq3o3Z0MbH5rw7aUZ/vfIPsiyC4zeRewZn6veV+kg3+l2RA Xq9TMs9vwmHNiK4SPKKb+m69E9VswFY8/Yr61M4dr/ugg2ncVLa3ZZAc5zWAiHpuA14v ssgBTANS3bh9grGZ6wgOi2MeEIZNrFRTugvkS0vEfLsj3Q2nERT5nkACfXE/GEvilk4E j84BiapblC/3h9oTiOkUiwN9QWP1JPDESeOEvKmcSXkuWgj4bh+Wkx+kw7lJuycECX4H M8Sw== X-Gm-Message-State: AO0yUKVIV3ab861d6IjVsG9gvI6HUfhUXTJ5JYEsed7yXkiIdxXHoGDm LyiKkqhQ5WnkvwJYxycZkZ7RKKniGxo= X-Google-Smtp-Source: AK7set8LjpC4MgmDqDJbWJT5/a9sws+efJ1/qb+E68zDRNoUYQhocvCxtWNafoyKqB3am0w+e39kMg== X-Received: by 2002:a9d:2c6:0:b0:693:d5c2:9a92 with SMTP id 64-20020a9d02c6000000b00693d5c29a92mr6351766otl.35.1678150155868; Mon, 06 Mar 2023 16:49:15 -0800 (PST) Received: from ?IPV6:2600:1700:bd2c:b810::43? ([2600:1700:bd2c:b810::43]) by smtp.googlemail.com with ESMTPSA id y14-20020a4ae70e000000b004fd878ef510sm4462571oou.21.2023.03.06.16.49.15 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Mar 2023 16:49:15 -0800 (PST) Content-Type: multipart/alternative; boundary="------------8PKm81SEIU9zqT07p04KRchK" Message-ID: <8e25aeed-b834-8e4e-1d11-2ea00b2d13cb@gmail.com> Date: Mon, 6 Mar 2023 18:49:14 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: How does Postgres store a B-Tree on disk while using the OS file system? Content-Language: en-US To: pgsql-general@lists.postgresql.org References: From: Ron In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------8PKm81SEIU9zqT07p04KRchK Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 3/6/23 18:24, Siddharth Jain wrote: > I am trying to sharpen my understanding of Postgres. As I understand, > Postgres does not write directly to disk blocks. It uses the file system > provided by the OS: > https://dba.stackexchange.com/questions/80036/is-there-a-way-to-store-a-postgresql-database-directly-on-a-block-device-not-fi > My question: How can it then store a B Tree on disk? I would think storing > a B Tree requires storing disk offset addresses and so on (for a node to > navigate to another etc.). For this, one would need to write directly to > the disk using low-level disk access functions and not use file system API. Disk offsets... *file* offsets... one is just a step up on the abstraction layer. How can that be? The OS only knows about Logical Block Addresses, which are a huge list of block numbers (just like userland software sees files as long lists of bytes).  It hasn't see cylinders, heads and platters in almost FORTY (more, probably, for SCSI and mainframe systems) years. -- Born in Arizona, moved to Babylonia. --------------8PKm81SEIU9zqT07p04KRchK Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit On 3/6/23 18:24, Siddharth Jain wrote:
I am trying to sharpen my understanding of Postgres. As I understand, Postgres does not write directly to disk blocks. It uses the file system provided by the OS:
My question: How can it then store a B Tree on disk? I would think storing a B Tree requires storing disk offset addresses and so on (for a node to navigate to another etc.). For this, one would need to write directly to the disk using low-level disk access functions and not use file system API.

Disk offsets... file offsets... one is just a step up on the abstraction layer.

How can that be? The OS only knows about Logical Block Addresses, which are a huge list of block numbers (just like userland software sees files as long lists of bytes).  It hasn't see cylinders, heads and platters in almost FORTY (more, probably, for SCSI and mainframe systems) years.

--
Born in Arizona, moved to Babylonia.
--------------8PKm81SEIU9zqT07p04KRchK--