All posts
PostgreSQLSeptember 17, 20267 min read

How to Install PostgreSQL & Use psql: Beginner Guide

Learn how to install PostgreSQL on Windows, Mac, and Linux, then run your first commands in psql with this simple, step-by-step guide made for total beginners.

F
Fepiq Team
Fepiq

If you searched for how to install PostgreSQL and use psql, here is the short answer: download the PostgreSQL installer for your operating system, run it and set a password, then open the psql command-line tool that comes with it to type commands and run SQL. This guide walks through every step for Windows, Mac, and Linux, then teaches you the handful of psql commands you actually need as a beginner.

You do not need any prior database experience to follow along. By the end, you will have PostgreSQL running on your machine and you will know how to create a database, create a table, and run your first query in psql.

What Are PostgreSQL and psql?

PostgreSQL (often just called "Postgres") is a free, open source RDBMS. RDBMS stands for Relational Database Management System — it is software that stores data in tables made of rows and columns, and lets you search, sort, and connect that data using SQL (Structured Query Language).

psql is the command-line client that comes bundled with PostgreSQL. It is a small text-based program you type commands into. You use psql to connect to a PostgreSQL server, look at your databases and tables, and run SQL statements. Think of PostgreSQL as the engine and psql as one of the steering wheels you can use to drive it.

Step 1: Install PostgreSQL on Your Computer

PostgreSQL is free to download from the official site at postgresql.org/download. The installer sets up three things at once: the PostgreSQL server (the database itself), pgAdmin (an optional graphical tool), and psql (the command-line tool this guide focuses on).

Installing on Windows

  1. Go to postgresql.org/download/windows and download the installer (it is made by a company called EDB).
  2. Run the downloaded file and click through the setup wizard.
  3. When asked, set a password for the default superuser account, named postgres. Write this password down — you will need it in a moment.
  4. Keep the default port, 5432, unless something else on your computer is already using it.
  5. Finish the install. psql is now available from the Start Menu as "SQL Shell (psql)", or from any terminal.

Installing on Mac

bash
brew install postgresql@16
brew services start postgresql@16

The first line uses Homebrew (a package manager for Mac) to download and install PostgreSQL version 16. The second line starts the PostgreSQL server as a background service, so it keeps running even after you close the terminal. If you don't have Homebrew yet, install it first from brew.sh.

Installing on Linux (Ubuntu or Debian)

bash
sudo apt update
sudo apt install postgresql postgresql-contrib

The first line refreshes your system's list of available software. The second line installs PostgreSQL along with a few extra useful tools (postgresql-contrib). On most Linux systems, the server starts automatically right after installation.

Step 2: Open psql for the First Time

bash
psql -U postgres

This command opens psql and connects as the postgres user. The -U flag means "user". You may be asked for the password you set during installation. Once it works, your prompt changes to something like postgres=#, which means psql is ready and waiting for a command.

On Windows, if you get a message saying psql is not recognized, use the "SQL Shell (psql)" app from the Start Menu instead — it opens psql with the right settings already filled in.

Step 3: Learn the Most Useful psql Commands

psql has two kinds of input. Backslash commands (like \l) are shortcuts built into psql itself and do not end with a semicolon. SQL statements (like SELECT) are sent to the database and must end with a semicolon (;). Here are the backslash commands worth memorizing first:

CommandWhat it does
\lLists all databases on the server
\c dbnameConnects to (switches into) the database named dbname
\dtLists all tables in the current database
\d tablenameShows the columns and types for one table
\duLists all user accounts (roles)
\xToggles a display mode that shows one column per line, useful for wide tables
\qQuits psql and returns to your regular terminal

Step 4: Run Your First SQL Query

sql
CREATE DATABASE practice;
\c practice
CREATE TABLE greetings (id SERIAL PRIMARY KEY, message TEXT);
INSERT INTO greetings (message) VALUES ('Hello, PostgreSQL!');
SELECT * FROM greetings;

Line by line: CREATE DATABASE practice; makes a new, empty database called practice. \c practice switches psql into that database. CREATE TABLE greetings (...) makes a table with an auto-incrementing id column (SERIAL means PostgreSQL fills it in for you) and a message column that holds text. INSERT INTO ... VALUES (...) adds one row of data. Finally, SELECT * FROM greetings; asks PostgreSQL to show every column (*) for every row in the greetings table — you should see your greeting printed back to you.

Common Beginner Problems (and Fixes)

  • "psql: FATAL: password authentication failed" — you typed the wrong password for the postgres user, or none was set; reinstall or reset the password with the pgAdmin tool if unsure.
  • "psql: command not found" — psql is not on your system PATH; on Mac, run brew link postgresql@16, or on Windows use the "SQL Shell (psql)" shortcut instead.
  • "could not connect to server: Connection refused" — the PostgreSQL service is not running; on Mac run brew services start postgresql@16, on Linux run sudo systemctl start postgresql.
  • Forgot to add a semicolon — psql will just sit there waiting on a new line; type ; and press Enter to finish the command.

What to Learn Next

Now that PostgreSQL is installed and you can run commands in psql, the natural next step is learning how to design and create your own tables properly, including choosing the right data types and keys.

Ready to build your own tables? Read our beginner guide to creating tables in PostgreSQL next.

Learn to create tables in PostgreSQL

Frequently asked questions

Do I need to install pgAdmin as well as psql?+

No. pgAdmin is an optional graphical tool for browsing your database with a mouse instead of typing commands. psql is enough to follow this guide and most beginner tutorials, and many developers use only psql day to day.

Is PostgreSQL really free to use?+

Yes. PostgreSQL is free and open source, with no license fees, even for commercial projects. You can install it on your own computer or a server without paying anything.

What is the difference between PostgreSQL and psql?+

PostgreSQL is the actual database server that stores and manages your data. psql is just one tool used to talk to that server by typing commands. You could also connect using pgAdmin or a programming language instead of psql.

Why do SQL commands in psql need a semicolon at the end?+

The semicolon tells psql that your SQL statement is complete and ready to run. Without it, psql assumes you might still be typing, so it waits on a new line until it sees the semicolon.

I installed PostgreSQL but forgot my postgres user password. What now?+

On most systems you can reset it using pgAdmin's user management screen, or by editing the server's authentication settings temporarily to skip the password check. If you just installed it for practice, it is often faster to uninstall and reinstall, setting a password you will remember.

Installing PostgreSQL and getting comfortable in psql is the foundation for everything else you'll do with databases — from writing your first SELECT statement to designing multi-table applications. Take it slowly, practice the commands above a few times, and they will quickly become second nature.

Want help planning or building a database-backed application for your business?

Talk to our team

Get new posts in your inbox

Occasional, no-fluff notes on shipping modern software — startups, automation, Laravel, Shopify and more. No spam, unsubscribe anytime.

Keep reading

Related posts

All posts

Let's build something

Ready to ship your next product with Fepiq?

Book a free discovery call. We'll listen, ask sharp questions, and send you a proposal within 3 business days.