1

I want to describe every table in a postgres database.

Currently I have this:

psql -d db -c "\d *" > db_description.txt

But this also includes all sequences, views, etc.

Is there a command where the * pattern only matches tables?
Or is there another way to do this?

2

How about simply using the \dt command? It's here to list tables only. You can get more help on PostgreSQL inner commands by issuing the \? command.

If you want to know what those commands do behind the scenes, you could also start psql with the -E option, as asked here. You could therefore rewrite this query to get exactly what you want, be it views, sequences, tables... or any combination of the above.

1

You can massage the output of that until you strip everything you don't want:

psql -d db -c '\d *' |\
  sed -n '/^ *Table/,/^\([^T -]\|$\)/p' |\
  grep -v '^\([^T ]\|Tablesp\| *Col\|$\)' |\
  sed 's/^ *Table "\([^"]*\)"/\n\1:/'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.