postgres db files - which file represents the specific table/index?

后端 未结 3 1114
心在旅途
心在旅途 2021-01-11 11:23

when i go into sql-8.2/base/ to check how much space does my table take, there are plenty of files named by a number. how can i find the specific file which sto

3条回答
  •  花落未央
    2021-01-11 12:03

    Each directory represents a database (created via create database). The number is the oid of the database. To see the oid and its name, run the following statement:

    select oid, datname
    from pg_database;
    

    Inside each directory each file corresponds to the an entry in pg_class where the oid matches the number of the file in the directory:

    You can see the oids and to which relation they relate by running the statement:

    select cl.relfilenode, nsp.nspname as schema_name, cl.relname, cl.relkind
    from pg_class cl
      join pg_namespace nsp on cl.relnamespace = nsp.oid;
    

    You might also want to check out the manual

    • Determining Disk Usage
    • Database File Layout
    • System catalogs

    Btw: if you are really still running 8.2 you should upgrade as soon as possible.

提交回复
热议问题