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 permissions, and remove permissions 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 permissions.
  • 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.


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

Mission Outline

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


Course Info:


The median completion time for this course is 6.1 hours. View Details

This course requires a basic subscription. This course includes four missions and one installation tutorial.  It is the 13th course in the Data Analyst in Python path and Data Scientist in Python path.


Take a Look Inside