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

Re: SQL query: List all the databases in the server

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tom Ivar Helbekkmo <tih(at)kpnQwest(dot)no>
Cc: Vince Vielhaber <vev(at)michvhf(dot)com>, Roman Smirnov <smirnov(at)dresearch(dot)de>, PostgreSQL conferention <pgsql-docs(at)postgresql(dot)org>
Subject: Re: SQL query: List all the databases in the server
Date: 2001-07-03 14:45:49
Message-ID: 18380.994171549@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-docs
Tom Ivar Helbekkmo <tih(at)kpnQwest(dot)no> writes:
> The above SELECT is extensively reformatted from the strings it's
> built from in the source file, of course.

An even easier way to see what queries psql emits for its backslash
commands is to start psql with -E option, then do the backslash
commands.  This gives me, for example,

regression=# \l
********* QUERY **********
SELECT pg_database.datname as "Database",
       pg_user.usename as "Owner"FROM pg_database, pg_user
WHERE pg_database.datdba = pg_user.usesysid

UNION

SELECT pg_database.datname as "Database",
       NULL as "Owner"FROM pg_database
WHERE pg_database.datdba NOT IN (SELECT usesysid FROM pg_user)
ORDER BY "Database"
**************************

   List of databases
  Database  |  Owner
------------+----------
 regression | postgres
 template0  | postgres
 template1  | postgres
(3 rows)

regression=#

			regards, tom lane

In response to

Responses

pgsql-docs by date

Next:From: Roman SmirnovDate: 2001-07-03 15:33:03
Subject: Re: SQL query: List all the databases in the server
Previous:From: Tom Ivar HelbekkmoDate: 2001-07-03 12:35:28
Subject: Re: SQL query: List all the databases in the server

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