PSQL

\c

SELECT version()

SELECT current_schema;

\timing

\dv

\dx

\dt

\d table
\d+ table

\df

\du
\du+

\dn

\set

SELECT relname, relpages, reltuples, relallvisible, relkind, relnatts, relhassubclass, reloptions, pg_table_size(oid)
FROM pg_class
WHERE relname='TABLE_NAME';

$ psql postgres
Null display is "[NULL]".
Expanded display is used automatically.
psql (12.3)
Type "help" for help.

In the console you can run SQL queries. The prompt is a # pound sign.

[local] hhh@postgres=# select version();
                                                      version
-------------------------------------------------------------------------------------------------------------------
 PostgreSQL 12.3 on x86_64-apple-darwin19.4.0, compiled by Apple clang version 11.0.3 (clang-1103.0.32.59), 64-bit
(1 row)
SELECT * FROM pg_database;

...

CREATE TABLE training (id int primary key);

will create in database’s public schema’s tables.

For example, check number of indexes on table_name:

\d table_name

-- ~/.psqlrc

\set expa EXPLAIN (ANALYZE)
\set expab EXPLAIN (ANALYZE, BUFFERS)

Then in psql console:

# :expa select 1;
-[ RECORD 1 ]----------------------------------------------------------------------------------
QUERY PLAN | Result  (cost=0.00..0.01 rows=1 width=4) (actual time=0.005..0.006 rows=1 loops=1)
-[ RECORD 2 ]----------------------------------------------------------------------------------
QUERY PLAN | Planning Time: 0.115 ms
-[ RECORD 3 ]----------------------------------------------------------------------------------
QUERY PLAN | Execution Time: 0.052 ms

# :expab select 1;
-[ RECORD 1 ]----------------------------------------------------------------------------------
QUERY PLAN | Result  (cost=0.00..0.01 rows=1 width=4) (actual time=0.008..0.009 rows=1 loops=1)
-[ RECORD 2 ]----------------------------------------------------------------------------------
QUERY PLAN | Planning Time: 0.072 ms
-[ RECORD 3 ]----------------------------------------------------------------------------------
QUERY PLAN | Execution Time: 0.044 ms