]> begriffs open source - ai-pg/blob - full-docs/txt/oid2name.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / oid2name.txt
1
2 oid2name
3
4    oid2name — resolve OIDs and file nodes in a PostgreSQL data directory
5
6 Synopsis
7
8    oid2name [option...]
9
10 Description
11
12    oid2name is a utility program that helps administrators to examine the
13    file structure used by PostgreSQL. To make use of it, you need to be
14    familiar with the database file structure, which is described in
15    Chapter 66.
16
17 Note
18
19    The name “oid2name” is historical, and is actually rather misleading,
20    since most of the time when you use it, you will really be concerned
21    with tables' filenode numbers (which are the file names visible in the
22    database directories). Be sure you understand the difference between
23    table OIDs and table filenodes!
24
25    oid2name connects to a target database and extracts OID, filenode,
26    and/or table name information. You can also have it show database OIDs
27    or tablespace OIDs.
28
29 Options
30
31    oid2name accepts the following command-line arguments:
32
33    -f filenode
34           --filenode=filenode
35           show info for table with filenode filenode.
36
37    -i
38           --indexes
39           include indexes and sequences in the listing.
40
41    -o oid
42           --oid=oid
43           show info for table with OID oid.
44
45    -q
46           --quiet
47           omit headers (useful for scripting).
48
49    -s
50           --tablespaces
51           show tablespace OIDs.
52
53    -S
54           --system-objects
55           include system objects (those in information_schema, pg_toast
56           and pg_catalog schemas).
57
58    -t tablename_pattern
59           --table=tablename_pattern
60           show info for table(s) matching tablename_pattern.
61
62    -V
63           --version
64           Print the oid2name version and exit.
65
66    -x
67           --extended
68           display more information about each object shown: tablespace
69           name, schema name, and OID.
70
71    -?
72           --help
73           Show help about oid2name command line arguments, and exit.
74
75    oid2name also accepts the following command-line arguments for
76    connection parameters:
77
78    -d database
79           --dbname=database
80           database to connect to.
81
82    -h host
83           --host=host
84           database server's host.
85
86    -H host
87           database server's host. Use of this parameter is deprecated as
88           of PostgreSQL 12.
89
90    -p port
91           --port=port
92           database server's port.
93
94    -U username
95           --username=username
96           user name to connect as.
97
98    To display specific tables, select which tables to show by using -o, -f
99    and/or -t. -o takes an OID, -f takes a filenode, and -t takes a table
100    name (actually, it's a LIKE pattern, so you can use things like foo%).
101    You can use as many of these options as you like, and the listing will
102    include all objects matched by any of the options. But note that these
103    options can only show objects in the database given by -d.
104
105    If you don't give any of -o, -f or -t, but do give -d, it will list all
106    tables in the database named by -d. In this mode, the -S and -i options
107    control what gets listed.
108
109    If you don't give -d either, it will show a listing of database OIDs.
110    Alternatively you can give -s to get a tablespace listing.
111
112 Environment
113
114    PGHOST
115           PGPORT
116           PGUSER
117           Default connection parameters.
118
119    This utility, like most other PostgreSQL utilities, also uses the
120    environment variables supported by libpq (see Section 32.15).
121
122    The environment variable PG_COLOR specifies whether to use color in
123    diagnostic messages. Possible values are always, auto and never.
124
125 Notes
126
127    oid2name requires a running database server with non-corrupt system
128    catalogs. It is therefore of only limited use for recovering from
129    catastrophic database corruption situations.
130
131 Examples
132
133 $ # what's in this database server, anyway?
134 $ oid2name
135 All databases:
136     Oid  Database Name  Tablespace
137 ----------------------------------
138   17228       alvherre  pg_default
139   17255     regression  pg_default
140   17227      template0  pg_default
141       1      template1  pg_default
142
143 $ oid2name -s
144 All tablespaces:
145      Oid  Tablespace Name
146 -------------------------
147     1663       pg_default
148     1664        pg_global
149   155151         fastdisk
150   155152          bigdisk
151
152 $ # OK, let's look into database alvherre
153 $ cd $PGDATA/base/17228
154
155 $ # get top 10 db objects in the default tablespace, ordered by size
156 $ ls -lS * | head -10
157 -rw-------  1 alvherre alvherre 136536064 sep 14 09:51 155173
158 -rw-------  1 alvherre alvherre  17965056 sep 14 09:51 1155291
159 -rw-------  1 alvherre alvherre   1204224 sep 14 09:51 16717
160 -rw-------  1 alvherre alvherre    581632 sep  6 17:51 1255
161 -rw-------  1 alvherre alvherre    237568 sep 14 09:50 16674
162 -rw-------  1 alvherre alvherre    212992 sep 14 09:51 1249
163 -rw-------  1 alvherre alvherre    204800 sep 14 09:51 16684
164 -rw-------  1 alvherre alvherre    196608 sep 14 09:50 16700
165 -rw-------  1 alvherre alvherre    163840 sep 14 09:50 16699
166 -rw-------  1 alvherre alvherre    122880 sep  6 17:51 16751
167
168 $ # What file is 155173?
169 $ oid2name -d alvherre -f 155173
170 From database "alvherre":
171   Filenode  Table Name
172 ----------------------
173     155173    accounts
174
175 $ # you can ask for more than one object
176 $ oid2name -d alvherre -f 155173 -f 1155291
177 From database "alvherre":
178   Filenode     Table Name
179 -------------------------
180     155173       accounts
181    1155291  accounts_pkey
182
183 $ # you can mix the options, and get more details with -x
184 $ oid2name -d alvherre -t accounts -f 1155291 -x
185 From database "alvherre":
186   Filenode     Table Name      Oid  Schema  Tablespace
187 ------------------------------------------------------
188     155173       accounts   155173  public  pg_default
189    1155291  accounts_pkey  1155291  public  pg_default
190
191 $ # show disk space for every db object
192 $ du [0-9]* |
193 > while read SIZE FILENODE
194 > do
195 >   echo "$SIZE       `oid2name -q -d alvherre -i -f $FILENODE`"
196 > done
197 16            1155287  branches_pkey
198 16            1155289  tellers_pkey
199 17561            1155291  accounts_pkey
200 ...
201
202 $ # same, but sort by size
203 $ du [0-9]* | sort -rn | while read SIZE FN
204 > do
205 >   echo "$SIZE   `oid2name -q -d alvherre -f $FN`"
206 > done
207 133466             155173    accounts
208 17561            1155291  accounts_pkey
209 1177              16717  pg_proc_proname_args_nsp_index
210 ...
211
212 $ # If you want to see what's in tablespaces, use the pg_tblspc directory
213 $ cd $PGDATA/pg_tblspc
214 $ oid2name -s
215 All tablespaces:
216      Oid  Tablespace Name
217 -------------------------
218     1663       pg_default
219     1664        pg_global
220   155151         fastdisk
221   155152          bigdisk
222
223 $ # what databases have objects in tablespace "fastdisk"?
224 $ ls -d 155151/*
225 155151/17228/  155151/PG_VERSION
226
227 $ # Oh, what was database 17228 again?
228 $ oid2name
229 All databases:
230     Oid  Database Name  Tablespace
231 ----------------------------------
232   17228       alvherre  pg_default
233   17255     regression  pg_default
234   17227      template0  pg_default
235       1      template1  pg_default
236
237 $ # Let's see what objects does this database have in the tablespace.
238 $ cd 155151/17228
239 $ ls -l
240 total 0
241 -rw-------  1 postgres postgres 0 sep 13 23:20 155156
242
243 $ # OK, this is a pretty small table ... but which one is it?
244 $ oid2name -d alvherre -f 155156
245 From database "alvherre":
246   Filenode  Table Name
247 ----------------------
248     155156         foo
249
250 Author
251
252    B. Palmer <bpalmer@crimelabs.net>