\x auto

You can put this in ~/.psqlrc.


It will open EDITOR and you can enter SQL.


SELECT version();

SELECT current_schema;





\d table
\d+ table





SELECT relname, relpages, reltuples, relallvisible, relkind, relnatts, relhassubclass, reloptions, pg_table_size(oid)
FROM pg_class

$ 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();
 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