Hello,
This is my first patch to the project.
I noticed that the oid2name tool does not display the file path of objects.
I thought this could be interesting and that others might find it useful,
so I made a little patch to display the full path of objects retrieved by
the oid2name tool. These will be displayed using the -x --extended option.
$ oid2name -p 5435 -x
All databases:
Oid Database Name Tablespace Filepath
----------------------------------------------
16392 b1 pg_default base/16392
5 postgres pg_default base/5
4 template0 pg_default base/4
1 template1 pg_default base/1
$ oid2name -p 5435 -d b1 -x
>From database "b1":
Filenode Table Name Oid Schema Tablespace Filepath
-------------------------------------------------------------------
16393 t1 16393 public pg_default base/16392/16393
$ oid2name -p 5435 -d b1 -i -x
>From database "b1":
Filenode Table Name Oid Schema Tablespace Filepath
-------------------------------------------------------------------
16393 t1 16393 public pg_default base/16392/16393
16396 t1_c1_idx 16396 public pg_default base/16392/16396
Regards
David Bidoc
diff --git a/contrib/oid2name/oid2name.c b/contrib/oid2name/oid2name.c
index 51802907138..4a985d579b6 100644
--- a/contrib/oid2name/oid2name.c
+++ b/contrib/oid2name/oid2name.c
@@ -452,12 +452,15 @@ void
sql_exec_dumpalldbs(PGconn *conn, struct options *opts)
{
char todo[1024];
+ char *addfields = ",'base/' ||d.oid as \"Filepath\"";
+
/* get the oid and database name from the system pg_database table */
snprintf(todo, sizeof(todo),
"SELECT d.oid AS \"Oid\", datname AS \"Database Name\", "
- "spcname AS \"Tablespace\" FROM pg_catalog.pg_database d JOIN pg_catalog.pg_tablespace t ON "
- "(dattablespace = t.oid) ORDER BY 2");
+ "spcname AS \"Tablespace\" %s FROM pg_catalog.pg_database d JOIN pg_catalog.pg_tablespace t ON "
+ "(dattablespace = t.oid) ORDER BY 2",
+ opts->extended ? addfields : "");
sql_exec(conn, todo, opts->quiet);
}
@@ -469,7 +472,7 @@ void
sql_exec_dumpalltables(PGconn *conn, struct options *opts)
{
char todo[1024];
- char *addfields = ",c.oid AS \"Oid\", nspname AS \"Schema\", spcname as \"Tablespace\" ";
+ char *addfields = ",c.oid AS \"Oid\", nspname AS \"Schema\", spcname as \"Tablespace\", pg_relation_filepath(c.oid) as \"Filepath\" ";
snprintf(todo, sizeof(todo),
"SELECT pg_catalog.pg_relation_filenode(c.oid) as \"Filenode\", relname as \"Table Name\" %s "
@@ -507,7 +510,7 @@ sql_exec_searchtables(PGconn *conn, struct options *opts)
*comma_filenumbers,
*comma_tables;
bool written = false;
- char *addfields = ",c.oid AS \"Oid\", nspname AS \"Schema\", spcname as \"Tablespace\" ";
+ char *addfields = ",c.oid AS \"Oid\", nspname AS \"Schema\", spcname as \"Tablespace\", pg_relation_filepath(c.oid) as \"Filepath\"";
/* get tables qualifiers, whether names, filenumbers, or OIDs */
comma_oids = get_comma_elts(opts->oids);
diff --git a/doc/src/sgml/oid2name.sgml b/doc/src/sgml/oid2name.sgml
index 54cc9be2b82..411950ea0e5 100644
--- a/doc/src/sgml/oid2name.sgml
+++ b/doc/src/sgml/oid2name.sgml
@@ -118,7 +118,7 @@
<term><option>-x</option></term>
<term><option>--extended</option></term>
<listitem><para>display more information about each object shown: tablespace name,
- schema name, and OID.
+ schema name, OID and file path.
</para></listitem>
</varlistentry>