Re: Viewing Database Scheme

Поиск
Список
Период
Сортировка
От Doug McNaught
Тема Re: Viewing Database Scheme
Дата
Msg-id 87psmcark6.fsf@asmodeus.mcnaught.org
обсуждение исходный текст
Ответ на Re: Viewing Database Scheme  (Rich Shepard <rshepard@appl-ecosys.com>)
Список pgsql-general
Rich Shepard <rshepard@appl-ecosys.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@salmo ~]$ psql -c contacts "\dt" > xrms.tables
> psql: FATAL:  database "\dt" does not exist
>
> [rshepard@salmo ~]$ psql "-c contacts \dt" > xrms.tables
> psql: FATAL:  database "rshepard" does not exist
>
> [rshepard@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@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.  :)

-Doug

В списке pgsql-general по дате отправления:

Предыдущее
От: "Ken Winter"
Дата:
Сообщение: Re: Seeking a better PL/pgSQL editor-debugger
Следующее
От: Karsten Hilbert
Дата:
Сообщение: Re: creating users per database