MISSION 115

Command Line PostgreSQL

In the previous lesson, we worked with PostgreSQL — or Postgres — databases, and tables. In this lesson, we'll learn how to work with the PostgreSQL command-line tool: psql.

In this lesson, you will learn about psql while creating a simple `bank_accounts` database. In addition to creating the database, you will become familiar with how to switch databases, create users, add perlessons, and remove perlessons to and from users. You will learn the concept of a superuser and what powers they have when using the database.

psql is similar to the sqlite3 command-line tool in that it allows you to connect to and manage databases. psql connects to a running PostgreSQL server process, then enables you to:

  • Run queries.
  • Manage users and perlessons.
  • Manage databases.
  • See PostgreSQL system information.

The main advantage of using the psql shell is it gives us the ability to quickly test out queries and get results — transactions don't apply, so each command is quickly executed.

As you work through each concept, you’ll get to apply what you’ve learned from within your browser; there's no need to use your own machine to do the exercises. The Python environment inside of this course includes answer-checking to ensure you've fully mastered each concept before learning the next.

Objectives

  • Learn how to work with PostgreSQL from the command line.
  • Learn how to create a user and add perlessons.

Lesson Outline

1. The psql tool
2. Running SQL queries
3. Special PostgreSQL commands
4. Switching databases
5. Creating users
6. Adding perlessons
7. Removing perlessons
8. Superusers
9. Takeaways

Take a Look Inside