Skip to content

Latest commit

 

History

History
83 lines (60 loc) · 3.11 KB

File metadata and controls

83 lines (60 loc) · 3.11 KB

PostgreSQL

GUI Apps

psql shell

Start the psql shell with psql postgres postgres (psql dbname username)`

Administration

Import / Run SQL Code

Two options to execute SQL code:

  • [shell] psql −U app_user −f /full/path/to/create_schema.sql app_database
  • [psql] \i /full/path/to/create_schema.sql

Steps to import the MONDIAL database dump:

  1. Create a user/role called mondial with password mondial and a database called mondial_db owned by the mondial user

    # [bash]
    psql postgres postgres
    # [psql]
    CREATE USER mondial WITH PASSWORD 'mondial';
    CREATE DATABASE mondial_db WITH OWNER mondial;
    # Quit interactive session
    \q
    
  2. Download the schema (create_schema.sql) and input values (insert_inputs.sql) from Canvas

  3. Change directory where the downloaded files are

    # MacOS/Linux uses slashes / for paths
    cd $HOME/Downloads
    # Windows uses backslashes \ for paths
    cd %USERPROFILE%\Downloads
  4. Import the schema and values

    psql −q −f create_schema.sql mondial_db mondial
    psql −q −f insert_inputs.sql mondial_db mondial
  5. Connect to the mondial database with the terminal client psql

    psql mondial_db mondial
  6. Verify whether the following query yields 1318

    SELECT COUNT(iatacode) FROM airport;
    

Tip: You can use dropdb or sql-dropdatabase DROP DATABASE mondial; to destroy your database and start from scratch.