Skip site navigation (1) Skip section navigation (2)

Re: Viewing Database Scheme

From: Doug McNaught <doug(at)mcnaught(dot)org>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Viewing Database Scheme
Date: 2006-01-28 22:58:01
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general
Rich Shepard <rshepard(at)appl-ecosys(dot)com> writes:

> On Sat, 28 Jan 2006, Eric B. Ridge wrote:
>> Again, you can't use redirection via the psql prompt.  But you can do it
>> via your shell command line:
>> $ psql -c "\dt" > xrms.tables
>    Well, that doesn't seem to be working here, either:
> [rshepard(at)salmo ~]$ psql -c contacts "\dt" > xrms.tables
> psql: FATAL:  database "\dt" does not exist
> [rshepard(at)salmo ~]$ psql "-c contacts \dt" > xrms.tables
> psql: FATAL:  database "rshepard" does not exist
> [rshepard(at)salmo ~]$ psql -c contacts
> psql: FATAL:  database "rshepard" does not exist

Eric left off the database argument (which defaults to your user
name), which was a little misleading, but his syntax does work:

doug(at)blinky:~$ psql -c '\dt' gateway
            List of relations
 Schema |     Name     | Type  |  Owner   

Redirecting to a file is left as an exercise to the reader.

>> Alternatively, you can use psql's "\o [FILE]" command to redirect
>> query results to a file:
>> contacts=# \o /tmp/xrms.tables
>> contacts=# \dt
>> contacts=#
>> That'll send all output to /tmp/xrms.tables.
>    This creates the file, but it's empty.

When I do this, after exiting 'psql' the file is populated.  It may be
a buffering issue, as another poster has said.  What you can also do
is close the file by setting output back to the terminal:

gateway=# \o /tmp/foo
gateway=# \dt
gateway=# \!cat /tmp/foo       <--- empty at this point
gateway=# \o                   <--- switch output to the terminal
gateway=# \!cat /tmp/foo       <--- now it's there
            List of relations
 Schema |     Name     | Type  |  Owner   

I'm really surprised that you managed to think 'pg_dump --schema_only'
is an SQL command.  It's listed nowhere in the SQL syntax reference,
and is listed in the manual as one of the utility commands that are
run from the shell.

Your flailing about, randomly trying different argument combinations,
suggests that you aren't understanding what you read, and aren't
bothering to try to understand the error messages you get.  You could
have figured out the first issue, certainly, by reading manpages and
error messages.  The second one is a bit tricky unless you understand
Unix stdio buffering, which I wouldn't necessarily expect.  So I'll
give you that one.  :)


In response to

pgsql-general by date

Next:From: Karsten HilbertDate: 2006-01-28 23:07:35
Subject: Re: creating users per database
Previous:From: Ken WinterDate: 2006-01-28 22:39:01
Subject: Re: Seeking a better PL/pgSQL editor-debugger

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group