Here are some common psql commands that you can use in the PostgreSQL interactive terminal:
-
Connect to a Database:
\c database_name -
List Databases:
\l -
List Tables:
\dt -
Describe a Table:
\d table_name -
Execute SQL Queries:
SELECT * FROM table_name; -
Insert Data:
INSERT INTO table_name (column1, column2) VALUES (value1, value2); -
Update Data:
UPDATE table_name SET column1 = value1 WHERE condition; -
Delete Data:
DELETE FROM table_name WHERE condition; -
Quit psql:
\q -
Show Current User:
SELECT current_user; -
Show Current Database:
SELECT current_database(); -
List All Users:
\du
These commands provide a foundation for interacting with PostgreSQL databases using the psql command-line interface.
