You want to know just how \d works
Start psql with the -E option then try \d ref.
You might also want to look at the code for pgAccess or phpPgAdmin - two tools that let you administer a Postgres database in a more visual manner (search on freshmeat.net for details).