pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Elphick <olly@lfix.co.uk>
To: Hugh Esco <hesco@greens.org>
Cc: pgsql-admin@postgresql.org
Subject: Re: How are postgreSQL database files structured?
Date: 23 Nov 2002 17:08:18 +0000
Message-ID: <1038071298.28188.432.camel@linda.lfix.co.uk> (raw)
In-Reply-To: <5.1.0.14.0.20021122225733.02c20230@petra.cagreens.org>
References: <5.1.0.14.0.20021122225733.02c20230@petra.cagreens.org>

On Sat, 2002-11-23 at 04:12, Hugh Esco wrote:

> But when I take a look at /usr/local/pgsql/data/base, I am baffled by its 
> contents.  I hear that the directory at: /usr/local/pgsql/data/base/1 is 
> the template1 database.  But I do not know where the template0 database 
> is.  And I certainly do not understand how testtest gets named 16555, much 
> less what the numbered directories and files subordinate to that directory 
> have to do with anything real in the world.

The files in $PGDATA/base are named by the oid of the database record in
pg_database, like this:

postgres@linda:~$ cd $PGDATA
postgres@linda:/usr1/postgres/data$ ls -l base
total 33
drwx------    2 postgres postgres     2048 Nov 23 04:01 1
drwx------    2 postgres postgres     2048 Nov 23 04:00 1063179
drwx------    2 postgres postgres     2048 Nov 23 04:00 1063190
drwx------    2 postgres postgres     3072 Nov 23 04:00 1063237
drwx------    2 postgres postgres     3072 Nov 23 04:00 1063515
drwx------    2 postgres postgres     3072 Nov 23 04:01 1064226
drwx------    2 postgres postgres     3072 Nov 23 04:01 1064465
drwx------    2 postgres postgres     2048 Nov 18 22:39 16975
drwx------    2 postgres postgres     2048 Nov 23 04:00 16976
drwx------    2 postgres postgres     3072 Nov 23 04:00 16983
drwx------    3 postgres postgres     6144 Nov 23 04:00 3884888
drwx------    2 postgres postgres     2048 Nov 23 04:01 4989386
postgres@linda:/usr1/postgres/data$ psql template1
Welcome to psql 7.3rc1, the PostgreSQL interactive terminal.
...
template1=# select oid,datname from pg_database order by oid;
   oid   |    datname     
---------+----------------
       1 | template1
   16975 | template0
   16976 | NEUROMR
   16983 | accounts
 1063179 | comanagers
 1063190 | genealogy
 1063237 | junk
 1063515 | lfix
 1064226 | sql_ledger
 1064465 | stjohns
 3884888 | bray
 4989386 | space database
(12 rows)

Similarly, inside $PGDATA/base/<dbdir>, relation files are named by
their oids in pg_class:

stjohns=# select oid,relname from pg_class where oid > 1000000 and oid <
2000000 order by oid limit 5;
   oid   |        relname         
---------+------------------------
 1064466 | members
 1064470 | pg_toast_1064466
 1064472 | pg_toast_1064466_index
 1064473 | members_pkey
 1064475 | perms
(5 rows)

stjohns=# \! cd $PGDATA/base/1064465 ; ls 10* | head -5
1064466
1064470
1064472
1064473
1064475


pg_class has a column, relfilenode, which almost invariably has the same
value as the oid; I'm not sure whether, should they differ, the file
would be named relfilenode or oid, though I would presume the former.

-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight, UK                             http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "The LORD is nigh unto all them that call upon him, to
      all that call upon him in truth."        
                                   Psalms 145:18




view thread (3+ messages)  latest in thread

Message-ID: <1038071298.28188.432.camel@linda.lfix.co.uk>
Permalink:  ../1038071298.28188.432.camel@linda.lfix.co.uk/
Also on:    postgresql.org/message-id/1038071298.28188.432.camel@linda.lfix.co.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: olly@lfix.co.uk, hesco@greens.org
  Subject: Re: How are postgreSQL database files structured?
  In-Reply-To: <1038071298.28188.432.camel@linda.lfix.co.uk>
  References: <5.1.0.14.0.20021122225733.02c20230@petra.cagreens.org> <1038071298.28188.432.camel@linda.lfix.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox