This page is a work in progress.You can help improve it. →

PostgreSQL

Helpful PostgreSQL commands

See a list of all my tables

To see a list of all your tables:

\dt

Example:

+----------+-----------------------+--------+---------+
| Schema | Name | Type | Owner |
|----------+-----------------------+--------+---------|
| public | Restaurants | table | student |
| public | Reviews | table | student |
| public | Users | table | student |
| public | __EFMigrationsHistory | table | student |
+----------+-----------------------+--------+---------+

See the details of a specific table

To see the definition of a table, including all of the columns:

\d Users

Example:

+----------------+---------+--------------------------------------------+
| Column | Type | Modifiers |
|----------------+---------+--------------------------------------------|
| Id | integer | not null generated by default as identity |
| FullName | text | not null |
| Email | text | not null |
| HashedPassword | text | |
+----------------+---------+--------------------------------------------+
Indexes:
"PK_Users" PRIMARY KEY, btree ("Id")
"IX_Users_Email" UNIQUE, btree ("Email")

Change databases without exiting

To change the database you are connected to without exiting pgcli or psql:

\connect databasename

List all available databases

\list

Example

+-------------------------------+---------+------------+-----------+---------+---------------------+
| Name | Owner | Encoding | Collate | Ctype | Access privileges |
|-------------------------------+---------+------------+-----------+---------+---------------------|
| BookCollection | student | UTF8 | C | C | <null> |
| CapstoneProjectDatabase | student | UTF8 | C | C | <null> |
| CompanyDatabase | student | UTF8 | C | C | <null> |
| FooBarDatabase | student | UTF8 | C | C | <null> |
| GameDatabaseAPIDatabase | student | UTF8 | C | C | <null> |
| GameNightDatabase | student | UTF8 | C | C | <null> |
|-------------------------------+---------+------------+-----------+---------+---------------------|
© 2017 - 2021; Built with ♥ in St. Petersburg, Florida.