|
| 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 | + |
0 commit comments