The quickest supported installation is sudo apt update followed by sudo apt install postgresql. Ubuntu supplies a PostgreSQL server with a cluster, service, and viable defaults already configured. Use that package when the version bundled with your Ubuntu release meets your application’s requirement; use the PostgreSQL Global Development Group (PGDG) APT repository when you need a different supported major version, such as PostgreSQL 18.
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
This guide covers both installation paths, explains what the package creates, shows how to make the first local connection, and walks through password authentication and secure remote access. The important decision comes before the first command: choose the repository that matches your version and maintenance requirements.
As an Amazon Associate I earn from qualifying purchases.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Choose the installation path first
Ubuntu and PostgreSQL document two sensible paths. The standard Ubuntu package is simpler and follows the PostgreSQL major version selected for your Ubuntu release. PGDG is the alternative when your application, extension, or migration plan requires another supported major version.
| Consideration | Ubuntu repository | PGDG repository |
|---|---|---|
| Version control | One PostgreSQL server major version is selected for the Ubuntu release and retained for that release’s lifetime. | Install a chosen supported major version with a versioned package such as postgresql-18. |
| Patch integration | Updates arrive through normal Ubuntu package and security-management workflows. | Packages integrate with APT but are supplied through the PostgreSQL project’s repository. |
| Setup effort | One repository refresh and one package command. | Install postgresql-common, run the PGDG setup script, then install the selected version. |
| Best fit | Most new servers and applications that do not require a particular major version. | Applications that explicitly require a major version different from Ubuntu’s bundled one. |
The PGDG FAQ’s rule is straightforward: Debian and Ubuntu normally ship one PostgreSQL server version per release. Do not add PGDG merely because it sounds newer; add it when version selection is an actual requirement. Repository support and CPU architecture vary by Ubuntu release, so verify your release codename and architecture before enabling PGDG.
#1 Best Overall
- BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
- EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
- COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
- LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
- WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.
Adding an external repository also adds an operational responsibility. You must know which repository supplies each package, keep its signing configuration intact, and document the major version selected. If the Ubuntu package already meets the application requirement, the simpler source usually reduces future troubleshooting.
Install the PostgreSQL version bundled with Ubuntu
Refresh APT metadata
Start with the package index refresh so APT sees the current packages configured for the server:
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemssudo apt update
If the command reports unreachable repositories or signature errors, fix those APT problems before installing PostgreSQL. Installing while the package index is stale can produce an older or unavailable package result. The refresh does not install PostgreSQL; it only updates APT’s view of available package metadata.
Install the server package
sudo apt install postgresql
Ubuntu states that PostgreSQL is available in all Ubuntu versions by default. The distribution package normally creates the initial database cluster and configures the service with viable defaults. It is integrated with Ubuntu’s regular patch management, so this is the least complicated operational path.
The unversioned package name is intentional on Ubuntu: it represents the PostgreSQL server series selected for that Ubuntu release. It does not mean that every Ubuntu release provides the same major version. Before deploying an application, confirm that its supported PostgreSQL range includes the version supplied by your particular release.
What installation creates
- A PostgreSQL server package managed by APT.
- An initialized cluster suitable for first connections.
- A system service configured to run with Ubuntu’s packaged defaults.
- Authentication rules that distinguish local operating-system connections from TCP host connections.
Package installation normally performs cluster creation for you. You generally do not need to run initdb for a first installation. PostgreSQL’s initdb documentation is still important when designing a manually initialized cluster: the selected authentication method determines the initial pg_hba.conf entries.
That distinction matters if you later build a nonstandard cluster or automate initialization. Authentication is not an afterthought added independently of cluster creation; the initialization process writes host-based authentication entries according to the method selected. Plan the intended local and network authentication model before exposing a manually initialized server.
Install a specific major version with PGDG
When PGDG is justified
Choose PGDG if Ubuntu’s bundled major version does not satisfy an application compatibility requirement, a migration target, or an operational standard. PGDG supplies versioned packages, allowing an administrator to stay on a selected major version rather than automatically following an unversioned package’s newest supported series.
This is useful when a vendor certifies only a particular major release, when a migration must reproduce the destination version, or when an organization standardizes several servers on one supported series. It is not a general requirement for every Ubuntu installation. If no such requirement exists, the Ubuntu repository avoids the additional repository setup and compatibility checks.
Add the repository using the documented setup
Install the common package and run the PostgreSQL project’s automated repository setup:
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
The setup adds the PGDG APT source and handles its signing-key configuration. Confirm that the repository recognizes your Ubuntu codename and architecture. At the time covered by the PostgreSQL repository documentation, supported Ubuntu codenames included jammy (22.04), noble (24.04), resolute (26.04), and stonking (26.10), with architecture support differing by release.
Do not assume that a repository supporting one Ubuntu release or processor architecture automatically supports another. A codename mismatch can leave APT without the package you need, while an unsupported architecture can prevent installation even when the command and version are correct. Verify those two values before diagnosing the PostgreSQL package itself.
Install the selected server series
sudo apt update
sudo apt install postgresql-18
Replace 18 with the supported major version your application requires. PGDG’s unversioned postgresql and postgresql-client packages are meta-packages that follow the latest supported version; versioned packages such as postgresql-15 and postgresql-18 are the deliberate choice when you need to remain on a particular major release.
Rank #2
- WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
- AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
- PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
- ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
- COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed
Do not mix an unversioned package into a version-pinning strategy by accident. Record the major version in your deployment documentation and make sure extensions and application drivers support that version before creating production databases. The package name is part of the version decision: an unversioned meta-package can move its dependency target as PGDG’s supported latest series changes, while a versioned package expresses the series you selected.
Free tools Windows power users keep installed
One-click scans. No signup required.
PGDG’s published package lines at the time of this guide included supported PostgreSQL series from 13 through 18, along with development lines. Availability still depends on the Ubuntu release and architecture, so treat the repository’s current support list as the authority when selecting a version.
Make the first local connection
Use the operating-system postgres account
Ubuntu’s normal starting point is a local connection made as the operating-system account named postgres:
sudo -u postgres psql template1
This connects to the default template1 database through the local Unix socket. Ubuntu uses peer authentication for local connections by default, so the operating-system identity is what permits this administrative entry; a database password is not required for this local command.
The command has two identities that should not be confused. sudo -u postgres changes the Linux account used to launch the client, while postgres inside PostgreSQL is a database role. Peer authentication compares the operating-system identity with the database role permitted by the local rule. A successful local connection therefore does not demonstrate that a TCP password login is configured.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchUsing template1 is a documented, predictable first connection because it is the default template database present in a newly created cluster. Once connected, perform administrative work deliberately and create application-specific databases and roles according to your deployment plan rather than using the superuser role for routine application traffic.
Set a database password only when you need one
At the psql prompt, set a password for the database role if clients will authenticate with a password:
ALTER USER postgres with encrypted password 'your_password';
Use a strong, unique secret and treat it as a credential. Do not paste a real password into shell history, tickets, documentation, or public examples. The SQL statement changes the database role’s password; it does not change the Linux account password.
If your administration is entirely local and peer authentication meets your process, setting a password is optional. A password becomes relevant when a client connects through a host rule, including a remote application connection. Setting a password alone does not open a network listener, authorize a source address, or force clients to use encryption.
When a password is required, provide it interactively or through your organization’s protected secret-management process. Avoid putting it directly in a shell command or a published connection string. The example value your_password is a placeholder, not a safe production secret.
Understand Ubuntu’s authentication defaults
Local connections: peer
Ubuntu’s current guidance uses peer for local connections. PostgreSQL checks the operating-system user associated with the connection instead of asking for a database password. This is why sudo -u postgres psql template1 works immediately after installation.
Peer authentication is limited to local socket connections. If a script changes from a local socket to a host name or IP address, it may match a host rule instead and require SCRAM credentials. Treat that change in connection method as an authentication change, not merely a networking detail.
TCP connections: SCRAM
For host connections, Ubuntu documents scram-sha-256 as the default authentication method. A client connecting over TCP therefore needs a matching database role and password, and the server-side rule must allow that client’s source address and database.
Rank #3
- Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
- Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
- Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
- ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
- Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)
SCRAM verifies the password without sending it as plain text during authentication, but it does not by itself encrypt every part of the connection. For connections that must be encrypted, use a hostssl rule and configure the client to use SSL. Authentication method and transport protection are related choices, but they solve different problems.
Authentication is controlled by host-based rules in /etc/postgresql/*/main/pg_hba.conf. The asterisk represents the installed cluster’s major-version directory, so use the path belonging to your actual installation rather than copying a version number from another machine.
Allow remote connections securely
Write a narrow rule in pg_hba.conf
Do not open every database to every address. Define the specific database, role, and source network that your application needs. Ubuntu’s documented example is:
hostssl template1 postgres 192.168.122.1/24 scram-sha-256
This rule means that the role postgres may reach template1 from the stated CIDR range, using SCRAM authentication over an SSL-enforced host connection. The hostssl form rejects TCP connections that do not use SSL.
Recommended Free Tools
The example network is illustrative, not a value to copy blindly. Replace the database name, role, and CIDR range with the real application values. A narrower source range reduces the number of systems that can attempt authentication. Likewise, a rule for an application role and application database is preferable to granting a broad network rule to the postgres superuser.
Check the rule before testing
- Confirm that the role exists and has a password if the rule uses password authentication.
- Confirm that the requested database name is the one in the rule.
- Confirm that the client address falls within the CIDR range.
- Use
hostsslwhen the connection must be encrypted rather than accepting unencrypted host connections. - Keep more-specific rules in the correct order; PostgreSQL evaluates the matching host-based rule, so an earlier broad rule can prevent a later narrow rule from being used.
Only change the authentication file after deciding which clients should connect and whether SSL is mandatory. PostgreSQL’s initialization documentation emphasizes that authentication choices belong in the design before a server is exposed. A permissive temporary rule can become a permanent exposure if it is not replaced and reviewed.
Remember that a pg_hba.conf rule controls authentication authorization; it is not a substitute for network-level access controls. Restrict the source CIDR to the application network and apply the surrounding firewall and routing policy required by your environment.
Apply the configuration
After editing pg_hba.conf or other server settings, restart the PostgreSQL service:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
sudo systemctl restart postgresql.service
A restart applies authentication and server-configuration changes. If a client still fails afterward, check the rule’s database, role, source network, authentication method, and SSL requirement in that order. Make sure the edited file belongs to the active cluster; the wildcard path can contain more than one version directory on a server that has hosted multiple clusters.
Test from a client
Ubuntu documents this client-side test form:
psql --host your-servers-dns-or-ip --username postgres --password --dbname template1
Replace the host placeholder with the server’s DNS name or IP address. The --password option prompts for the role password instead of putting the secret in the command line. If the test succeeds, the client reached the intended host rule and authenticated as the requested role.
Run the test from a client whose address should be permitted by the CIDR rule. Testing from the database server itself may match a different local or loopback rule than the application will use. If the result differs between clients, compare their source addresses, connection transport, requested database, and requested role rather than changing the password repeatedly.
Common installation and connection problems
APT cannot find the requested version
If postgresql-18 or another versioned package is unavailable, you may still be using only Ubuntu’s repository, the PGDG setup may not have completed, or the repository may not support your codename or architecture. Recheck the release identity, rerun sudo apt update, and verify that the requested major version is supported for that release.
Do not solve this by substituting the unversioned package unless you have confirmed that its selected series is acceptable. The unversioned package can install a different major version from the one your application requested.
Rank #4
- Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
- Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
- 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
- Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
- USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC
The package installed a different major version than expected
The unversioned Ubuntu package follows the major version selected by that Ubuntu release. With PGDG, the unversioned postgresql package follows the latest supported series. If a specific major version matters, install its versioned package explicitly and record that choice in the deployment configuration.
Local psql access asks for a password
Local Ubuntu guidance normally uses peer authentication, so first try the operating-system account form exactly:
sudo -u postgres psql template1
If you are connecting as a different Linux user or through a host-style connection, the applicable pg_hba.conf rule may require a database password. Use the rule’s authentication method rather than repeatedly guessing credentials. A password prompt can indicate that the connection is no longer using the local peer rule.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Remote login is rejected
Inspect the matching host rule conceptually: database, role, source CIDR, authentication method, and SSL mode must all agree with the client request. A hostssl rule requires an SSL connection; a non-SSL attempt will not match it. After correcting the file, restart postgresql.service and rerun the documented psql test.
Check rule order as well. PostgreSQL uses the first applicable host-based rule, so an earlier rule can determine the result before a later rule is considered. A narrow rule placed after a broad rule may never be reached.
A password works locally but not remotely
Setting the role password is only one part of remote access. The client must also match an allowed host rule, come from an allowed network, and satisfy the rule’s SSL requirement. Peer authentication for local sockets does not prove that a remote SCRAM connection is configured.
The repository setup works on one server but not another
Compare the Ubuntu codename and CPU architecture first. PGDG support varies by both, and the setup script cannot provide a package series that is not published for the target combination. Keep the repository choice and selected major version recorded with the server’s deployment details so a replacement host is built consistently.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Operational checklist after installation
- Decide whether Ubuntu’s bundled major version is acceptable before adding any external repository.
- If using PGDG, verify the Ubuntu codename and architecture and install a versioned package when version control matters.
- Confirm that the initial cluster was created by the package; do not run a second initialization over an existing cluster.
- Use
sudo -u postgres psql template1for the first local administrative connection. - Set the
postgresrole password only when password authentication is required, and keep it secret. - Review
/etc/postgresql/*/main/pg_hba.confbefore allowing network clients. - Prefer narrow
hostsslrules withscram-sha-256for remote access. - Restart with
sudo systemctl restart postgresql.serviceafter authentication or server-setting changes. - Validate the final path using
psql --host ... --username ... --password --dbname ...from an appropriate client. - Document the Ubuntu release, repository source, PostgreSQL major version, authentication method, and permitted source networks.
Which method should you use?
Use Ubuntu’s package when simplicity is the priority
For a new Ubuntu server without a strict major-version requirement, the distribution package is the cleanest choice. It is a two-command installation, receives Ubuntu’s normal package updates, and supplies a cluster and service with viable defaults. It also keeps package support within the Ubuntu release’s ordinary maintenance workflow.
Use PGDG when compatibility requires a different major version
For an application that requires a particular supported PostgreSQL series, PGDG provides the versioned package needed to make that choice explicit. Accept the additional repository and support-scope work: check codename and architecture compatibility, understand which package series you are installing, and keep the selected major version documented.
The practical decision is therefore simple: use Ubuntu’s repository by default, and introduce PGDG for a concrete version requirement. Whichever path you choose, the secure completion criteria are the same: an initialized cluster, a deliberate authentication design, a secret-managed password when needed, narrowly scoped host rules, and a successful client test.
Frequently asked questions
Is PostgreSQL already available in Ubuntu?
Yes. PostgreSQL is available in all Ubuntu versions by default through Ubuntu’s standard repositories. Run sudo apt update and then sudo apt install postgresql.
Should I use Ubuntu’s package or PGDG?
Use Ubuntu’s package unless your application or migration requires a different supported major version. Use PGDG when you need explicit version selection, such as postgresql-18. Debian and Ubuntu normally ship one PostgreSQL server version per release.
Do I need to run initdb after installing the package?
No, not for a normal first installation. The package normally creates the initial cluster and service. initdb is relevant when you intentionally initialize a cluster yourself, in which case its authentication choices determine the initial pg_hba.conf entries.
Best Value
- Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
- Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
- Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
- Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
- Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.
How do I connect immediately after installation?
Use sudo -u postgres psql template1. Ubuntu’s default peer rule permits the operating-system postgres account to connect locally without a database password.
How do I set the postgres password?
At the psql prompt, run ALTER USER postgres with encrypted password 'your_password';. Set it only when password authentication is required, and never expose the real secret in shell history or documentation.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
How do I allow remote connections securely?
Edit the active cluster’s /etc/postgresql/*/main/pg_hba.conf and create a narrow rule for the required database, role, and source CIDR. Prefer hostssl with scram-sha-256, then restart with sudo systemctl restart postgresql.service.
Why does a remote connection fail even though the password is correct?
The password is only one condition. The request must match the database, role, source CIDR, authentication method, and SSL requirement of the first applicable host rule. A local peer login does not validate remote SCRAM access.
What does PGDG’s unversioned postgresql package do?
In PGDG, unversioned postgresql and postgresql-client are meta-packages that follow the latest supported version. Install a versioned package when remaining on a specific major series matters.
Frequently Asked Questions
Is PostgreSQL already available in Ubuntu?
Yes. PostgreSQL is available in all Ubuntu versions by default through Ubuntu’s standard repositories. Run sudo apt update and sudo apt install postgresql.
Should I use Ubuntu’s package or PGDG?
Use Ubuntu’s package unless your application requires a different supported major version. Choose PGDG for explicit version selection, such as postgresql-18.
Do I need to run initdb after installation?
No. A normal package installation creates the initial cluster. Use initdb only for an intentional manual cluster initialization.
How do I connect immediately after installation?
Run sudo -u postgres psql template1. Ubuntu’s peer authentication normally permits this local connection without a database password.
How do I allow remote connections securely?
Add a narrow hostssl rule in the active pg_hba.conf for the required database, role, and CIDR range, use scram-sha-256, and restart PostgreSQL.
Recommended Free Tools
Why does a remote login fail with the correct password?
The request may not match the database, role, source network, SSL requirement, or first applicable host rule. A local peer login does not prove remote SCRAM access.
The Bottom Line
Install postgresql from Ubuntu unless you have a concrete reason to select another supported major version. Use PGDG’s versioned package when that requirement exists, then review peer and SCRAM authentication, set a password only when needed, restrict remote access with narrow hostssl rules, and restart the service after configuration changes.
Quick Recap
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.




