Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2c591cb

Browse files
committed
Add oid2name. Add streaming option later.
1 parent a8b275e commit 2c591cb

File tree

5 files changed

+555
-0
lines changed

5 files changed

+555
-0
lines changed

contrib/oid2name/Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
#
3+
4+
subdir = contrib/oid2name
5+
top_builddir = /pgtop/
6+
include $(top_builddir)/src/Makefile.global
7+
8+
override CPPFLAGS += -I$(libpq_srcdir)
9+
10+
OBJS = oid2name.o
11+
12+
all: oid2name
13+
14+
oid2name: $(OBJS) $(libpq_builddir)/libpq.a
15+
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) $(libpq) $(LIBS) -o $@ -g
16+
17+
install: all installdirs
18+
$(INSTALL_PROGRAM) oid2name$(X) $(bindir)
19+
$(INSTALL_DATA) README.oid2name $(docdir)/contrib
20+
21+
installdirs:
22+
$(mkinstalldirs) $(bindir) $(docdir)/contrib
23+
24+
uninstall:
25+
rm -f $(bindir)/oid2name$(X) $(docdir)/contrib/README.oid2name
26+
27+
clean distclean maintainer-clean:
28+
rm -f oid2name$(X) $(OBJS)
29+
30+
depend dep:
31+
$(CC) -MM -MG $(CFLAGS) *.c > depend
32+
33+
ifeq (depend,$(wildcard depend))
34+
include depend
35+
endif

contrib/oid2name/README.oid2name

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
With version 7.1 of PostgreSQL server, the old naming scheme for
2+
databases and tables (in $PGDATA/base) has changed. The databases
3+
are put in folders for their OID in pg_database and the tables in
4+
that folder are named for their OIDs in pg_class. This app connects
5+
to the database (you can specify host, port, user, pass etc to
6+
connect to a host other than localhost) and extracts the OID and
7+
table name information. It has 4 ways it can be run:
8+
9+
pg_oid2name
10+
11+
This will connect to the template1 database and display all databases
12+
in the system.
13+
14+
$ ./pg_oid2name
15+
All databases:
16+
---------------------------------
17+
18720 = test1
18+
1 = template1
19+
18719 = template0
20+
18721 = test
21+
18735 = postgres
22+
18736 = cssi
23+
24+
pg_oid2name -d test [-x]
25+
26+
This connects to the database test and shows all tables and their OIDs.
27+
28+
$ ./pg_oid2name -d test
29+
All tables from database "test":
30+
---------------------------------
31+
18766 = dns
32+
18737 = ips
33+
18722 = testdate
34+
35+
pg_oid2name -d test -o 18737 or
36+
pg_oid2name -d test -t testdate
37+
38+
This will connect to the database test and display the table name for oid
39+
18737 and the oid for table name testdate respectivly.
40+
41+
$ ./pg_oid2name -d test -o 18737
42+
Tablename of oid 18737 from database "test":
43+
---------------------------------
44+
18737 = ips
45+
46+
47+
$ ./pg_oid2name -d test -t testdate
48+
Oid of table testdate from database "test":
49+
_______________________________
50+
18722 = testdate
51+
52+
53+
There should be a decent amount of error handling in the app, a lot of it
54+
dealt with via the postgres function calls.
55+
56+
$ ./pg_oid2name -d nothere -t testdate
57+
Oid of table testdate from database "nothere":
58+
_______________________________
59+
Connection to database 'nothere' failed.
60+
FATAL 1: Database "nothere" does not exist in the system catalog.
61+
62+
$ ./pg_oid2name -d test -t nothere
63+
Oid of table nothere from database "test":
64+
_______________________________
65+
No tables with that name found
66+
67+
68+
Mail me with any problems or additions you would like to see. Clearing
69+
house for the code will be at: http://www.crimelabs.net
70+
71+
b. palmer, bpalmer@crimelabs.net
72+

contrib/oid2name/oid2name

17.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)