Access the psql Shell: Open your command prompt or terminal and enter the psql command. You might need to provide the necessary credentials, like username and password, to log in. For example:

Copy code
psql -U your_username -d your_database

List of Vital psql Commands: Here are some commonly used psql commands that are vital for working with PostgreSQL from the command line:

Sequel Commands

  1. SELECT: Used to retrieve data from one or more tables.

    sqlCopy code
    SELECT column1, column2 FROM table_name WHERE condition;
    
    
  2. INSERT: Used to add new records (rows) into a table.

    sqlCopy code
    INSERT INTO table_name (column1, column2) VALUES (value1, value2);
    
  3. UPDATE: Used to modify existing records in a table.

    sqlCopy code
    UPDATE table_name SET column1 = new_value WHERE condition;
    
  4. DELETE: Used to remove records from a table.

    sqlCopy code
    DELETE FROM table_name WHERE condition;
    
  5. CREATE TABLE: Used to create a new table with specified columns and data types.

    sqlCopy code
    CREATE TABLE table_name (
        column1 data_type,
        column2 data_type,
        ...
    );
    
  6. ALTER TABLE: Used to modify an existing table structure (e.g., add, modify, or delete columns).

    sqlCopy code
    ALTER TABLE table_name
    ADD column_name data_type;
    
    ALTER TABLE table_name
    ALTER COLUMN column_name TYPE new_data_type;
    
    ALTER TABLE table_name
    DROP COLUMN column_name;