SovranCode
Learn
Learn on SovranCodeCourses6 free learning paths→ExercisesPractice with live challenges→GuidesDirect answers for developers→E-booksFocused field guides→
Build
Build on SovranCodeProjectsPortfolio-ready builds→TemplatesSovranCode team marketplace→Developer toolsFast browser utilities→
Connect
Connect on SovranCodeForumQuestions and discussions→JournalPractical development notes→AboutWhy SovranCode exists→PricingFree, Plus, and Student Plus→
Services
SearchCreate account
Explore SovranCodeLearn, practice, and build.
LearnCourses6 free learning paths→ExercisesPractice with live challenges→GuidesDirect answers for developers→E-booksFocused field guides→
BuildProjectsPortfolio-ready builds→TemplatesSovranCode team marketplace→Developer toolsFast browser utilities→
ConnectForumQuestions and discussions→JournalPractical development notes→AboutWhy SovranCode exists→PricingFree, Plus, and Student Plus→
Search
Guides/Developer Setup/How to Install PostgreSQL: Complete Local Setup
All guides
How-to guide

How to Install PostgreSQL: Complete Local Setup

Install PostgreSQL on Windows, macOS, or Linux, create a local database for your app, verify it, and handle the setup details that matter.

Beginner 18 min readUpdated September 15, 2026
LOCAL DATABASE$ psql --versionInstall · create · verify

Your computer Your app

START HERE

Install PostgreSQL for your operating system, start the local server, then run psql --version. Next, create a dedicated role and database for your app, and test the connection with one command. That is all you need for a reliable first local setup.

Before you start

  • A Windows, macOS, or Linux computer that can install software.
  • A terminal: PowerShell, Terminal, or your Linux shell.
  • A safe local password for the database role you will create.
Keep the first setup simple

Use one local PostgreSQL installation. Do not run a native install and Docker on port 5432 at the same time unless you deliberately change a port.

1. Install and start PostgreSQL

  1. 01

    Download the installer

    Open the official Windows download page and choose the EDB installer.

  2. 02

    Install the server

    Keep PostgreSQL Server and Command Line Tools selected. Set a password for the postgres administrator role and keep port 5432 unless it is already in use.

  3. 03

    Open SQL Shell

    Open SQL Shell (psql) from the Start menu, accept the suggested connection settings, then enter the password you chose.

Official Windows download

PostgreSQL for WindowsOfficial download page; it directs you to the supported Windows installer.EDB PostgreSQL installerThe installer used by the official Windows download page.
Check that psql is available
psql --version
# If this is not found, use SQL Shell or add PostgreSQL's bin folder to PATH.

2. Create a database for your app

Inside psql, create a login role and a database it owns. Replace the example password with your own local password.

Create the role and database
CREATE ROLE myapp LOGIN PASSWORD 'choose-a-local-password';
CREATE DATABASE myapp_development OWNER myapp;
\c myapp_development myapp
CREATE TABLE setup_check (message text NOT NULL);
INSERT INTO setup_check VALUES ('PostgreSQL is ready');
SELECT * FROM setup_check;
Use the postgres role only for administration

Your application should connect as myapp, not as the postgres administrator.

3. Verify the connection

Exit psql with \q, then run this command in a fresh terminal. A successful result prints the role and database name.

Connection test
psql 'postgresql://myapp:your-password@localhost:5432/myapp_development' -c 'SELECT current_user, current_database();'

You are ready when

  • psql --version prints a version.
  • The connection test returns myapp and myapp_development.
  • SELECT * FROM setup_check; returns one row.

Connect your application

Put the connection URL in your local environment file, not in source code. Most Node.js, Python, and other database libraries use this format.

.env.local
# Keep this file out of Git
DATABASE_URL=postgresql://myapp:your-password@localhost:5432/myapp_development
Use a separate test database

When your project adds automated tests, give them a different database, such as myapp_test. Tests should not be able to erase development data.

Work with your local database

You can use pgAdmin if you prefer a visual interface, but keep psql available. It is the quickest way to confirm exactly which server, role, and database your application is using.

Useful psql commands
\conninfo                 -- show the current connection
\l                        -- list databases
\du                       -- list roles
\dt                       -- list tables
SELECT version();
\q                        -- quit psql

Optional tools and reference

Download pgAdminOptional graphical tool for browsing databases and running queries.psql referenceOfficial reference for psql commands and connection options.
Use Docker only when the project calls for it

If a repository already includes Docker Compose, follow its PostgreSQL service instead of installing a second server. For a first local setup, the native route above is easier to understand and troubleshoot.

Troubleshoot common errors

Start with the message you see
ProblemTry this
psql: command not foundClose and reopen the terminal. If it still fails, use SQL Shell on Windows or add PostgreSQL's bin folder to PATH.
connection refusedStart the PostgreSQL service, then try again with -h localhost -p 5432.
password authentication failedCheck that the URL uses myapp, then reset that role's password from an administrator connection.
role or database does not existRun \du to list roles and \l to list databases. Create the missing item or correct the URL.
port 5432 is already in useStop the other local database or configure one server to use another port and update the URL.
Do not reinstall first

Most local failures are a stopped service, a wrong password, or a different database name in the URL. Check those three things before reinstalling.

Frequently asked questions

Do I need pgAdmin?

No. pgAdmin is optional. psql is enough to create a role, create a database, and confirm that your application can connect.

Which PostgreSQL version should I install?

Use a supported stable version unless your team or hosting provider requires a specific version.

Should my app use the postgres role?

No. Create a dedicated role for each application, as shown above. It keeps your application connection clear and avoids unnecessary administrator access.

Can I use Docker instead?

Yes, especially when a project already supplies a Docker Compose file. For a first setup, a native installation is often easier because you can focus on one server and one connection.

Can I change port 5432?

Yes. If another service already uses it, choose a different port and make the same change in your DATABASE_URL.

What if my password contains @ or :?

Those characters need URL encoding inside DATABASE_URL. For example, @ becomes %40. A simple local password avoids this extra step while you are learning.

How do I back up my local database?

Use pg_dump -U myapp -d myapp_development > backup.sql from a terminal. Keep the backup somewhere safe; restoring it replaces or adds data depending on the command you use.

How do I stop PostgreSQL?

Stop it through the tool that started it: Windows Services, brew services on macOS, or systemctl on Linux. Do not delete its data directory.

Setup path
Before you start1. Install and start PostgreSQL2. Create a database for your app3. Verify the connectionConnect your applicationWork with your local databaseTroubleshoot common errorsFAQ
CONTINUE LEARNING

Put the answer to work.

COURSEsqlCOURSEPython courseE-BOOKPython: Build Reliable Programs
RELATED GUIDES

Keep moving.

Browse all guides
How-to guideBeginner

How to Install Python: A Safe Setup Guide

Install a current Python release on Windows, macOS, or Linux; prove which interpreter and pip you are using; create an isolated project environment; and fix the common setup failures without damaging your system Python.

18 min readUpdated Sep 2026
Open guide
How-to guideBeginner

How to Install Flutter: Complete Setup Guide

Install Flutter on Windows, macOS, or Linux; choose a first target, configure your editor and platform tooling, run Flutter Doctor, and launch a real app.

16 min readUpdated Sep 2026
Open guide
SOURCES

Official documentation

  • PostgreSQL — Downloads
  • PostgreSQL — Windows installers
  • PostgreSQL — macOS packages
  • PostgreSQL — Linux downloads
  • PostgreSQL — psql reference
  • pgAdmin — Downloads
THE SOVRANCODE PLATFORM

Learn enough to build something real.

Start learning
100Learning modules
39Exercises
9Projects
2Templates
4E-books
5Guides
SovranCode

A free-first programming platform for people who learn best by understanding, practicing, and building.

● Core learning content is free
FollowYouTubePinterestX
LearnHTML courseCSS courseJSJavaScript coursePython courseC courseSQL courseDeveloper guidesAll exercises
BuildProjectsTemplate marketBuyer libraryTemplate licensesDeveloper toolsE-books
CommunityForumJournalContact
CompanyPricing previewAboutServicesPrivacyEnglish edition. Additional languages will be published only after full editorial review.
© 2026 SovranCode · Built for curious minds.Next.js · Node.js · PostgreSQL