PostgreSQL Get Started
Learn how to install PostgreSQL, start the server, and connect to it using the psql command-line client.
Installing PostgreSQL
PostgreSQL can be installed on Windows, macOS, and Linux using official installers or package managers. On Windows, the EDB installer bundles the server, pgAdmin (a graphical management tool), and command-line tools. On macOS, Homebrew provides a quick installation path, and on Linux, most distributions ship PostgreSQL through their native package managers such as apt or yum.
- Windows: download the installer from postgresql.org and run the setup wizard
- macOS: run brew install postgresql@16
- Ubuntu/Debian: run sudo apt install postgresql postgresql-contrib
- Docker: run a containerized instance without installing anything locally
Starting the PostgreSQL Server
On most systems, PostgreSQL installs as a background service that starts automatically after installation or system boot. You can verify the service status or start it manually depending on your operating system's service manager.
Check service status on Linux
sudo systemctl status postgresqlConnecting with psql
psql is PostgreSQL's official interactive command-line client. It lets you run SQL statements directly against a database, list tables, inspect schemas, and manage users. To connect, you typically specify a username, a database name, and a host.
Connect to the default database
psql -U postgres -d postgres -h localhostList all databases from within psql
\lCreate and switch to a new database
CREATE DATABASE school;
\c schoolExercise: PostgreSQL Get Started
What is the default port PostgreSQL listens on?