PostgreSQL Install & Get Started
To follow this course you don't need to install anything: every playground runs a real PostgreSQL 18 server inside your browser. Sooner or later, though, you will want Postgres on your own machine or server. This lesson explains the options and the tools you will meet, then gets you running your first statements here.
Installing PostgreSQL (for later)
| Platform | Typical way to install |
|---|---|
| Windows | The installer from postgresql.org (includes pgAdmin and psql) |
| macOS | Postgres.app, or Homebrew: brew install postgresql@18 |
| Debian / Ubuntu | sudo apt install postgresql (or the PGDG apt repository for the newest version) |
| Any OS with Docker | docker run -e POSTGRES_PASSWORD=secret -p 5432:5432 postgres:18 |
| Cloud | Managed services such as Amazon RDS, Google Cloud SQL, Azure, Neon or Supabase |
After installation a server process listens on port 5432. Programs connect to it as clients. The most important client is psql, the command-line shell that ships with PostgreSQL. A typical session looks like this (not runnable here):
$ psql -U postgres -d postgres
psql (18.0)
Type "help" for help.
postgres=# CREATE DATABASE bookshop;
CREATE DATABASE
postgres=# \c bookshop
You are now connected to database "bookshop" as user "postgres".
bookshop=# \dt
Did not find any relations.Commands that start with a backslash (\c, \dt, \d books, \q) are psql meta-commands: they are handled by psql itself, not by the server. They are not available in the playgrounds, but later lessons show how to get the same information with plain SQL. Graphical tools such as pgAdmin or DBeaver are popular too.
Your first statements
Which server are we talking to? version() returns a long description, so we take just the first two words:
SELECT split_part(version(), ' ', 1) AS product,
split_part(version(), ' ', 2) AS version; product | version
------------+---------
PostgreSQL | 18.6
(1 row)
A few built-in functions tell you about the current session:
SELECT current_database() AS database,
current_user AS user_name,
current_schema() AS schema; database | user_name | schema
----------+-----------+--------
postgres | postgres | public
(1 row)
Tables live inside schemas (namespaces) inside a database. The default schema is called public, and that is where the sample tables are.
Finding the tables (instead of \dt)
The SQL-standard catalogue information_schema describes every table and column. This is how you list the tables of the sample database without psql:
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
ORDER BY table_name; table_name
-------------
authors
books
categories
customers
employees
order_items
orders
(7 rows)
Reading the output
| What you see | Meaning |
|---|---|
A table with (n rows) |
A query returned rows |
CREATE TABLE, INSERT 0 3, UPDATE 2 |
The command tag: what a statement did and how many rows it touched |
NOTICE: … |
An informational message from the server |
ERROR: … |
The statement failed; the rest of the script still runs |
Try it: the second statement below has a typo (SELEC), but the third still runs.
SELECT 'first' AS step;
SELEC 'second' AS step;
SELECT 'third' AS step; step
-------
first
(1 row)
ERROR: syntax error at or near "SELEC"
LINE 1: SELEC 'second' AS step;
^
step
-------
third
(1 row)
Tip: The
LINE 1:and^marker point at the exact place where PostgreSQL stopped understanding you. Read error messages carefully; they are usually precise.
Test yourself
On which TCP port does a PostgreSQL server listen by default?
- 3306
- 5432
- 8080
- 1433
What is \dt?
- An SQL keyword
- A psql meta-command that lists tables
- A data type
- A PostgreSQL function
What is the name of the default schema where new tables are created?
- main
- dbo
- public
- default