October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Installing and Setting Up PostgreSQL on Ubuntu

How to install PostgreSQL on Ubuntu with apt or the official PGDG repository, make your first psql connection, and enable remote access safely.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

On Ubuntu, the standard way to install PostgreSQL is sudo apt install postgresql. It installs the version shipped with your Ubuntu release and creates a working default cluster. Canonical says the service is “automatically configured with viable defaults, but can be customised based on your specific needs” (Ubuntu Server documentation). This guide covers that route, the PostgreSQL project’s own repository for other versions, your first connection, and what remote access requires.

Which installation source should you use?

There are two real choices. The PostgreSQL project itself recommends installing through your package manager, and PostgreSQL is available in Ubuntu by default.

Source Use it when Trade-off
Ubuntu’s own repositories The packaged version meets your needs. This suits local development, learning, and most first setups. The major version is fixed by your Ubuntu release.
PGDG APT repository (postgresql.org) You need a different or specific major version than Ubuntu provides. It is an extra repository to maintain. Support depends on your Ubuntu release and CPU architecture.

Decide using three questions: does Ubuntu’s version meet your requirement, does PGDG support your release and architecture, and do you need a pinned major version?

Option 1: Install from Ubuntu’s repositories

  1. Refresh package lists: sudo apt update
  2. Install: sudo apt install postgresql
  3. Check the service: systemctl status postgresql
  4. Check the version: psql --version

The install creates a default cluster named main, and the service starts. No further setup is needed for local use.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Option 2: Install a specific version from PGDG

The PostgreSQL Ubuntu download page gives the current repository setup commands. It lists supported Ubuntu codenames, including jammy (22.04), noble (24.04), resolute (26.04) and stonking (26.10). Architecture availability differs by release, so check the live page for your exact combination before relying on it. Follow its steps to add the repository and refresh APT, then install a versioned package such as:

sudo apt install postgresql-18

Naming the major version, rather than the generic postgresql meta-package, keeps you on the major you chose instead of silently following a moving default.

Connect for the first time

Ubuntu defaults to peer authentication for local connections and scram-sha-256 for host (TCP) connections. Peer authentication maps your operating-system username to a PostgreSQL role. The installer creates a postgres superuser role, so the usual first command is:

sudo -u postgres psql

To work under your own account, create a matching role and database from that prompt (replace yourname):

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
CREATE ROLE yourname WITH LOGIN CREATEDB;
CREATE DATABASE yourname OWNER yourname;

Then psql works without sudo. Add a password later with password yourname if you need TCP logins.

Fix common first-connection errors

The Ubuntu Community Help Wiki covers these local problems.

  • Role “yourname” does not exist: no role matches your Unix user. Create one as shown above. This is not a password problem.
  • Peer authentication failed: with peer, the Unix account and the database role must match. Connect as the matching user, or use a password over TCP.
  • Database “yourname” does not exist: clients default to a database named after the user, and it is not created automatically. Create it, or pass a database name with psql -d postgres.

Where configuration lives and how clusters work

Ubuntu’s example configuration path is /etc/postgresql/<version>/main, holding postgresql.conf and pg_hba.conf. Ubuntu’s postgresql-common tooling manages clusters, each identified by version and name. According to the pg_createcluster manpage, a cluster’s start.conf decides whether systemd starts and stops it automatically, whether you control it manually, or whether service control is disabled. Most newcomers never need a second cluster.

After editing configuration, restart the service: sudo systemctl restart postgresql.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Allow remote connections deliberately

By default only connections from the local system are allowed. Remote access needs two coordinated changes:

  1. In postgresql.conf, set listen_addresses to the specific address the server should listen on, rather than every interface.
  2. In pg_hba.conf, add a rule permitting a defined client network. Ubuntu’s documentation example uses a hostssl rule with scram-sha-256 and a restricted network range.
  3. Restart the service.

Ubuntu itself warns that its example is incomplete, so treat this as a separate security task. Don’t open all interfaces or all networks without understanding the exposure. Combine a narrow address range, TLS, strong passwords and a firewall rule limited to trusted clients.

Keep PostgreSQL updated

The PostgreSQL versioning policy recommends running the current minor release of your major version. Minor updates need no dump and restore, and normal apt upgrade delivers them. A major-version upgrade requires dump/reload or pg_upgrade. As of that policy page when checked in 2026, PostgreSQL 18 is supported through November 14, 2030 and PostgreSQL 17 through November 8, 2029. Check the page again when planning a long-lived deployment.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.