oid2name

oid2name — resolve OIDs and file nodes in a PostgreSQL data directory

Synopsis

oid2name [option…]

Description

oid2name is a utility program that helps administrators to examine the file structure used by PostgreSQL. To make use of it, you need to be familiar with the database file structure, which is described in Chapter 66.

Note

The name “oid2name” is historical, and is actually rather misleading, since most of the time when you use it, you will really be concerned with tables’ filenode numbers (which are the file names visible in the database directories). Be sure you understand the difference between table OIDs and table filenodes!

oid2name connects to a target database and extracts OID, filenode, and/or table name information. You can also have it show database OIDs or tablespace OIDs.

Options

oid2name accepts the following command-line arguments:-f filenode

show info for table with filenode filenode-i

include indexes and sequences in the listing-o oid

show info for table with OID oid-q

omit headers (useful for scripting)-s

show tablespace OIDs-S

include system objects (those in information_schema, pg_toast and pg_catalog schemas)-t tablename_pattern

show info for table(s) matching tablename_pattern-V
--version

Print the oid2name version and exit.-x

display more information about each object shown: tablespace name, schema name, and OID-?
--help

Show help about oid2name command line arguments, and exit.

oid2name also accepts the following command-line arguments for connection parameters:-d database

database to connect to-H host

database server’s host-p port

database server’s port-U username

user name to connect as-P password

password (deprecated — putting this on the command line is a security hazard)

To display specific tables, select which tables to show by using -o, -f and/or -t. -o takes an OID, -f takes a filenode, and -t takes a table name (actually, it’s a LIKE pattern, so you can use things like foo%). You can use as many of these options as you like, and the listing will include all objects matched by any of the options. But note that these options can only show objects in the database given by -d.

If you don’t give any of -o, -f or -t, but do give -d, it will list all tables in the database named by -d. In this mode, the -S and -i options control what gets listed.

If you don’t give -d either, it will show a listing of database OIDs. Alternatively you can give -s to get a tablespace listing.

Notes

oid2name requires a running database server with non-corrupt system catalogs. It is therefore of only limited use for recovering from catastrophic database corruption situations.

Examples

  1. $ # what's in this database server, anyway?
  2. $ oid2name
  3. All databases:
  4. Oid Database Name Tablespace
  5. ----------------------------------
  6. 17228 alvherre pg_default
  7. 17255 regression pg_default
  8. 17227 template0 pg_default
  9. 1 template1 pg_default
  10. $ oid2name -s
  11. All tablespaces:
  12. Oid Tablespace Name
  13. -------------------------
  14. 1663 pg_default
  15. 1664 pg_global
  16. 155151 fastdisk
  17. 155152 bigdisk
  18. $ # OK, let's look into database alvherre
  19. $ cd $PGDATA/base/17228
  20. $ # get top 10 db objects in the default tablespace, ordered by size
  21. $ ls -lS * | head -10
  22. -rw------- 1 alvherre alvherre 136536064 sep 14 09:51 155173
  23. -rw------- 1 alvherre alvherre 17965056 sep 14 09:51 1155291
  24. -rw------- 1 alvherre alvherre 1204224 sep 14 09:51 16717
  25. -rw------- 1 alvherre alvherre 581632 sep 6 17:51 1255
  26. -rw------- 1 alvherre alvherre 237568 sep 14 09:50 16674
  27. -rw------- 1 alvherre alvherre 212992 sep 14 09:51 1249
  28. -rw------- 1 alvherre alvherre 204800 sep 14 09:51 16684
  29. -rw------- 1 alvherre alvherre 196608 sep 14 09:50 16700
  30. -rw------- 1 alvherre alvherre 163840 sep 14 09:50 16699
  31. -rw------- 1 alvherre alvherre 122880 sep 6 17:51 16751
  32. $ # I wonder what file 155173 is ...
  33. $ oid2name -d alvherre -f 155173
  34. From database "alvherre":
  35. Filenode Table Name
  36. ----------------------
  37. 155173 accounts
  38. $ # you can ask for more than one object
  39. $ oid2name -d alvherre -f 155173 -f 1155291
  40. From database "alvherre":
  41. Filenode Table Name
  42. -------------------------
  43. 155173 accounts
  44. 1155291 accounts_pkey
  45. $ # you can mix the options, and get more details with -x
  46. $ oid2name -d alvherre -t accounts -f 1155291 -x
  47. From database "alvherre":
  48. Filenode Table Name Oid Schema Tablespace
  49. ------------------------------------------------------
  50. 155173 accounts 155173 public pg_default
  51. 1155291 accounts_pkey 1155291 public pg_default
  52. $ # show disk space for every db object
  53. $ du [0-9]* |
  54. > while read SIZE FILENODE
  55. > do
  56. > echo "$SIZE `oid2name -q -d alvherre -i -f $FILENODE`"
  57. > done
  58. 16 1155287 branches_pkey
  59. 16 1155289 tellers_pkey
  60. 17561 1155291 accounts_pkey
  61. ...
  62. $ # same, but sort by size
  63. $ du [0-9]* | sort -rn | while read SIZE FN
  64. > do
  65. > echo "$SIZE `oid2name -q -d alvherre -f $FN`"
  66. > done
  67. 133466 155173 accounts
  68. 17561 1155291 accounts_pkey
  69. 1177 16717 pg_proc_proname_args_nsp_index
  70. ...
  71. $ # If you want to see what's in tablespaces, use the pg_tblspc directory
  72. $ cd $PGDATA/pg_tblspc
  73. $ oid2name -s
  74. All tablespaces:
  75. Oid Tablespace Name
  76. -------------------------
  77. 1663 pg_default
  78. 1664 pg_global
  79. 155151 fastdisk
  80. 155152 bigdisk
  81. $ # what databases have objects in tablespace "fastdisk"?
  82. $ ls -d 155151/*
  83. 155151/17228/ 155151/PG_VERSION
  84. $ # Oh, what was database 17228 again?
  85. $ oid2name
  86. All databases:
  87. Oid Database Name Tablespace
  88. ----------------------------------
  89. 17228 alvherre pg_default
  90. 17255 regression pg_default
  91. 17227 template0 pg_default
  92. 1 template1 pg_default
  93. $ # Let's see what objects does this database have in the tablespace.
  94. $ cd 155151/17228
  95. $ ls -l
  96. total 0
  97. -rw------- 1 postgres postgres 0 sep 13 23:20 155156
  98. $ # OK, this is a pretty small table ... but which one is it?
  99. $ oid2name -d alvherre -f 155156
  100. From database "alvherre":
  101. Filenode Table Name
  102. ----------------------
  103. 155156 foo

Author

B. Palmer <bpalmer@crimelabs.net>