postgresql/contrib/oid2name
Bruce Momjian 558fae16e3 The attached patch enables the contrib subtree to build cleanly under
Cygwin with the possible exception of mSQL-interface.  Since I don't
have mSQL installed, I skipped this tool.

Except for dealing with a missing getopt.h (oid2name) and HUGE (seg),
the bulk of the patch uses the standard PostgreSQL approach to deal with
Windows DLL issues.

I tested the build aspect of this patch under Cygwin and Linux without
any ill affects.  Note that I did not actually attempt to test the code
for functionality.

The procedure to apply the patch is as follows:

    $ # save the attachment as /tmp/contrib.patch
    $ # change directory to the top of the PostgreSQL source tree
    $ patch -p0 </tmp/contrib.patch

Jason
2001-06-18 21:38:02 +00:00
..
Makefile Make sure -L and -I's for our source tree are always before system include 2001-02-20 19:20:30 +00:00
oid2name.c The attached patch enables the contrib subtree to build cleanly under 2001-06-18 21:38:02 +00:00
README.oid2name Add oid2name. Add streaming option later. 2001-01-24 00:41:25 +00:00

With version 7.1 of PostgreSQL server,  the old naming scheme for
databases and tables (in $PGDATA/base) has changed.  The databases
are put in folders for their OID in pg_database and the tables in
that folder are named for their OIDs in pg_class.  This app connects
to the database (you can specify host, port, user, pass etc to 
connect to a host other than localhost) and extracts the OID and 
table name information.  It has 4 ways it can be run:

 pg_oid2name

  This will connect to the template1 database and display all databases
   in the system.

  $ ./pg_oid2name                                                                
  All databases:
  ---------------------------------
  18720  = test1
  1      = template1
  18719  = template0
  18721  = test
  18735  = postgres
  18736  = cssi

 pg_oid2name -d test [-x]

  This connects to the database test and shows all tables and their OIDs.

  $ ./pg_oid2name -d test                                                        
  All tables from database "test":
  ---------------------------------
  18766  = dns
  18737  = ips
  18722  = testdate

 pg_oid2name -d test -o 18737      or
 pg_oid2name -d test -t testdate

  This will connect to the database test and display the table name for oid
   18737 and the oid for table name testdate respectivly.

  $ ./pg_oid2name -d test -o 18737
  Tablename of oid 18737 from database "test":
  ---------------------------------
  18737  = ips


  $ ./pg_oid2name -d test -t testdate 
  Oid of table testdate from database "test":
  _______________________________
  18722  = testdate


There should be a decent amount of error handling in the app,  a lot of it
 dealt with via the postgres function calls.

  $ ./pg_oid2name -d nothere -t testdate 
  Oid of table testdate from database "nothere":
  _______________________________
  Connection to database 'nothere' failed.
  FATAL 1:  Database "nothere" does not exist in the system catalog.

  $ ./pg_oid2name -d test -t nothere     
  Oid of table nothere from database "test":
  _______________________________
  No tables with that name found

  
Mail me with any problems or additions you would like to see.  Clearing 
 house for the code will be at:  http://www.crimelabs.net

b. palmer, bpalmer@crimelabs.net