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

后端 未结 3 1113
心在旅途
心在旅途 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.

    0 讨论(0)
  • 2021-01-11 12:06
    select pg_relation_filepath('OID or name of a table, index, sequence, or toast table');
    

    For example:

    select pg_relation_filepath('flush_history');
    Returns base/83780/153211 which you will find in your data directory.
    

    http://www.postgresql.org/docs/current/static/functions-admin.html

    0 讨论(0)
  • 2021-01-11 12:15

    To check how much space the table takes use:

    SELECT pg_size_pretty(pg_total_relation_size('table_name_here'))
    

    It will give you the size of a table with its indexes and "toast" tables. Details here.

    0 讨论(0)
提交回复
热议问题