Thread: How to list and describe tables in psql???
I am using PostgreSQL 9.1 and have boon looking for psql commands to list all tables in the current database as well as how to "describe" a given table. I have come across some info on the web (older mostly) that lists commands like \d, \dt, or \d+ <tablename> but I get results like "no relations found" or "column reltriggers does not exist". Not sure what is going on. Can someone enlighten me on the right commands to use? Thanks - Peter -- View this message in context: http://postgresql.1045698.n5.nabble.com/How-to-list-and-describe-tables-in-psql-tp5785006.html Sent from the PostgreSQL - general mailing list archive at Nabble.com.
On 01/01/2014 05:53 PM, peterlen wrote: > I am using PostgreSQL 9.1 and have boon looking for psql commands to list all > tables in the current database as well as how to "describe" a given table. > I have come across some info on the web (older mostly) that lists commands > like \d, \dt, or \d+ <tablename> but I get results like "no relations found" > or "column reltriggers does not exist". Not sure what is going on. > > Can someone enlighten me on the right commands to use? Fresh from the docs: http://www.postgresql.org/docs/9.3/interactive/app-psql.html Search for: Meta-Commands There will be a copious amount of information available. > > Thanks - Peter > > > > -- > View this message in context: http://postgresql.1045698.n5.nabble.com/How-to-list-and-describe-tables-in-psql-tp5785006.html > Sent from the PostgreSQL - general mailing list archive at Nabble.com. > > -- Adrian Klaver adrian.klaver@gmail.com
014/1/2 peterlen <peteralen@earthlink.net>: > I am using PostgreSQL 9.1 and have boon looking for psql commands to list all > tables in the current database as well as how to "describe" a given table. > I have come across some info on the web (older mostly) that lists commands > like \d, \dt, or \d+ <tablename> but I get results like "no relations found" > or "column reltriggers does not exist". Not sure what is going on. > > Can someone enlighten me on the right commands to use? Those are the correct commands, but it sounds like you're using an older psql version against a newer server. Which psql version (psql -V) are you using? Regards Ian Barwick
Thanks for the responses. I found that I was using an older version of psql (one that got installed when I installed Cygwin on my windows box. I changed it so now the \d+ gives me the description but \d and \dt still gives me "No relations found" so I must be using those incorrectly. Thanks for the info on the old version. -- View this message in context: http://postgresql.1045698.n5.nabble.com/How-to-list-and-describe-tables-in-psql-tp5785006p5785013.html Sent from the PostgreSQL - general mailing list archive at Nabble.com.
2014/1/2 peterlen <peteralen@earthlink.net>: > Thanks for the responses. I found that I was using an older version of psql > (one that got installed when I installed Cygwin on my windows box. I > changed it so now the \d+ > gives me the description but \d and \dt still gives me "No relations > found" so I must be using those incorrectly. Possibly there's an issue with your search path? Check if "\dn" lists schemas not listed by "SHOW search_path", if so you can either explicitly include the schema name (\dt some_schema.*) or adjust your search path. See also: http://www.postgresql.org/docs/current/interactive/ddl-schemas.html#DDL-SCHEMAS-PATH Regards Ian Barwick
On 02/01/2014 01:53, peterlen wrote: > I am using PostgreSQL 9.1 and have boon looking for psql commands to list all > tables in the current database as well as how to "describe" a given table. > I have come across some info on the web (older mostly) that lists commands > like \d, \dt, or \d+ <tablename> but I get results like "no relations found" > or "column reltriggers does not exist". Not sure what is going on. > > Can someone enlighten me on the right commands to use? Possibly a silly question, but are you connected to the correct database? If you don't specify a database on the psql command line, then psql connects to a database with the same name as the username you use to connect, if such a database exists. Ray. -- Raymond O'Donnell :: Galway :: Ireland rod@iol.ie
Hi All,


Below are the details:
Connect to default database:
=====================
bash-4.1$ ./psql -p 5432 postgres
Password:
psql.bin (9.1.7)
Type "help" for help.
postgres=#
To list all available database:
=====================
postgres=# \l+
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges | Size | Tablespace | Description
-----------+----------+----------+-------------+-------------+-----------------------+---------+------------+--------------------------------------------
pem | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | postgres=CTc/postgres+| 29 MB | pg_default |
| | | | | pem_user=Tc/postgres +| | |
| | | | | pem_agent=Tc/postgres | | |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | 6570 kB | pg_default | default administrative connection database
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +| 6457 kB | pg_default | unmodifiable empty database
| | | | | postgres=CTc/postgres | | |
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +| 6457 kB | pg_default | default template for new databases
| | | | | postgres=CTc/postgres | | |
(4 rows)
To change Database:
===============
postgres=# \c edb
You are now connected to database "edb" as user "postgres".
edb=#
To check list of schemas:
===================
postgres=# \dn
List of schemas
Name | Owner
--------+----------
abdul | postgres
public | postgres
(2 rows)
To set a Schema for a session:
=======================
postgres=# set search_path to abdul;
SET
postgres=# show search_path ;
search_path
-------------
abdul
(1 row)
postgres=# create table test (n numeric, Name varchar(10));
CREATE TABLE
postgres=# insert into test values (generate_series(1,10),'TEST');
INSERT 0 10
postgres=# select * from test;
n | name
----+------
1 | TEST
2 | TEST
3 | TEST
4 | TEST
5 | TEST
6 | TEST
7 | TEST
8 | TEST
9 | TEST
10 | TEST
(10 rows)
To list all tables of a current schema:
===========================
postgres=# \dt+
List of relations
Schema | Name | Type | Owner | Size | Description
--------+------+-------+----------+-------+-------------
abdul | test | table | postgres | 16 kB |
(1 row)
Hope this helps.
Thanks & Regards,
Abdul Sayeed
System Engineer

The Postgres Database Company
Are you updated: Latest version of Postgres Plus Advanced Server are 8.4.19.42, 9.0.15.33, 9.1.11.19, 9.2.6.16, 9.3.2.5.
To reach Support Call:
US: +1-732-331-1320 - UK: +44 - 2033719820
Brazil: +55-2139581371 - India: +91-20-32676535

Website: www.enterprisedb.com
EnterpriseDB Blog : http://blogs.enterprisedb.com
Follow us on Twitter : http://www.twitter.com/enterprisedb
____________________________________________________________
CONFIDENTIALITY NOTICE
This e-mail transmission and any documents, files, or previous e-mail messages appended or attached to it, may contain information that is confidential or legally privileged. If you are not the intended recipient, or a person responsible for delivering it to the intended recipient, you are hereby notified that you must not read this transmission and that any disclosure, copying, printing, distribution, or use of the information contained or attached to this transmission is STRICTLY PROHIBITED. If you have received this transmission in error, please immediately notify the sender by telephone or return e-mail message and delete the original transmission, its attachments, and any copies without reading or saving in any manner. Thank you.
On Thu, Jan 2, 2014 at 4:34 PM, Raymond O'Donnell <rod@iol.ie> wrote:
On 02/01/2014 01:53, peterlen wrote:Possibly a silly question, but are you connected to the correct
> I am using PostgreSQL 9.1 and have boon looking for psql commands to list all
> tables in the current database as well as how to "describe" a given table.
> I have come across some info on the web (older mostly) that lists commands
> like \d, \dt, or \d+ <tablename> but I get results like "no relations found"
> or "column reltriggers does not exist". Not sure what is going on.
>
> Can someone enlighten me on the right commands to use?
database? If you don't specify a database on the psql command line, then
psql connects to a database with the same name as the username you use
to connect, if such a database exists.
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie
--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general