Start using PostgreSQL
Navigate psql
Use psql meta-commands to inspect the current connection without confusing them with SQL.
Inside psql you type two different languages, and telling them apart saves you a lot of confusion.
SQL statements such as SELECT current_database(); go to the server. They end with a semicolon.
Commands beginning with a backslash belong to psql itself. They are called meta-commands, they run locally, and they need no semicolon. Try \conninfo, \l, \dt, \d notes, and \q.
The meta-commands you need first
A handful covers daily work:
\conninfo current database, role, host, and port
\l list databases
\dt list tables in the current search path
\d notes describe the notes table: columns, types, indexes
\du list roles
\q quit
\d is the one you will run most. Point it at a table and it shows every column, its type, its constraints, and the indexes on the table:
\d notes
Table "public.notes"
Column | Type | Collation | Nullable | Default
--------+--------+-----------+----------+------------------------------
id | bigint | | not null | generated by default as identity
title | text | | not null |
When the prompt looks stuck
Forget the semicolon on a SQL statement and psql waits for more input:
postgres=# SELECT current_database()
postgres-#
The prompt changed from =# to -#. That means the statement is not finished. Type ; and press enter to run it, or \r to throw the unfinished statement away. This is the single most common way beginners think psql froze.
The reverse mistake is harmless but worth knowing: meta-commands take effect immediately, so \dt runs the moment you press enter, semicolon or not.
Getting help without leaving the session
Two help commands cover both languages. Use \? for psql help: it lists every meta-command. Use \h SELECT for SQL help: it shows the syntax of the SELECT statement straight from the documentation. Swap in any SQL command name, like \h CREATE TABLE.
My advice is to keep one psql session open while you work through this course and check every change with a meta-command right after you make it.
Lesson completed