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.
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.
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.
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.
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).
brew install postgresql@16
brew services start postgresql@16The 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.
sudo apt update
sudo apt install postgresql postgresql-contribThe 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.
psql -U postgresThis 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.
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:
| Command | What it does |
|---|---|
| \l | Lists all databases on the server |
| \c dbname | Connects to (switches into) the database named dbname |
| \dt | Lists all tables in the current database |
| \d tablename | Shows the columns and types for one table |
| \du | Lists all user accounts (roles) |
| \x | Toggles a display mode that shows one column per line, useful for wide tables |
| \q | Quits psql and returns to your regular terminal |
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.
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 PostgreSQLNo. 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.
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.
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.
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.
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 teamOccasional, no-fluff notes on shipping modern software — startups, automation, Laravel, Shopify and more. No spam, unsubscribe anytime.
Keep reading
Learn SQL CASE WHEN step by step. This beginner guide shows how to label, group and sort data with simple examples you can copy and run today.
PostgreSQL ILIKE explained for beginners: search text without worrying about case, learn % and _ wildcards, and copy simple examples you can run today.
Let's build something
Book a free discovery call. We'll listen, ask sharp questions, and send you a proposal within 3 business days.