Tools: Complete Guide to Installing PostgreSQL on Ubuntu 26.04

Tools: Complete Guide to Installing PostgreSQL on Ubuntu 26.04

Install PostgreSQL

Manage the PostgreSQL Service

Secure PostgreSQL

Create a Database and User

Create a Sample Table

Next Steps PostgreSQL is a powerful open-source relational database known for extensibility, standards compliance, and support for advanced data types including JSON and arrays. The PostgreSQL Global Development Group maintains a dedicated APT repository with the latest releases. This guide installs PostgreSQL from the PGDG repository, secures the installation, and creates a database with a dedicated user. By the end, you'll have a hardened PostgreSQL instance with a working database ready for application use. The PostgreSQL Global Development Group provides an official APT repository with the latest PostgreSQL releases. 1. Update the APT package index: 2. Install the PostgreSQL common package: 3. Run the repository setup script: 4. Install PostgreSQL: 5. Verify the installed version: Enable PostgreSQL to start automatically when the server boots. 1. Enable and start the service: 2. Check the service status: 3. Stop or restart the service when needed: 1. Log in as the postgres superuser: 2. Set a password for the postgres account: 3. Create a new application user: 4. Update the authentication method in pg_hba.conf: Find the lines for local connections and change peer to scram-sha-256: 5. Restart PostgreSQL to apply changes: Log in as the postgres superuser and create a database owned by the application user: Log in as the application user to verify access: All three rows in the query output confirm the database, user, and table are working correctly. PostgreSQL is now installed and accepting connections. From here you can: For the full guide with additional tips, visit the original article on Vultr Docs. Templates let you quickly answer FAQs or store snippets for re-use. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse

Command

Copy

$ -weight: 600;">sudo -weight: 500;">apt -weight: 500;">update $ -weight: 600;">sudo -weight: 500;">apt -weight: 500;">update $ -weight: 600;">sudo -weight: 500;">apt -weight: 500;">update $ -weight: 600;">sudo -weight: 500;">apt -weight: 500;">install postgresql-common -y $ -weight: 600;">sudo -weight: 500;">apt -weight: 500;">install postgresql-common -y $ -weight: 600;">sudo -weight: 500;">apt -weight: 500;">install postgresql-common -y $ -weight: 600;">sudo /usr/share/postgresql-common/pgdg/-weight: 500;">apt.postgresql.org.sh $ -weight: 600;">sudo /usr/share/postgresql-common/pgdg/-weight: 500;">apt.postgresql.org.sh $ -weight: 600;">sudo /usr/share/postgresql-common/pgdg/-weight: 500;">apt.postgresql.org.sh $ -weight: 600;">sudo -weight: 500;">apt -weight: 500;">install postgresql -y $ -weight: 600;">sudo -weight: 500;">apt -weight: 500;">install postgresql -y $ -weight: 600;">sudo -weight: 500;">apt -weight: 500;">install postgresql -y $ psql --version $ psql --version $ psql --version $ -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable postgresql $ -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start postgresql $ -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable postgresql $ -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start postgresql $ -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable postgresql $ -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">start postgresql $ -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">status postgresql $ -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">status postgresql $ -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">status postgresql $ -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">stop postgresql $ -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart postgresql $ -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">stop postgresql $ -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart postgresql $ -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">stop postgresql $ -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart postgresql $ -weight: 600;">sudo -u postgres psql $ -weight: 600;">sudo -u postgres psql $ -weight: 600;">sudo -u postgres psql ALTER USER postgres WITH PASSWORD 'your_strong_password'; ALTER USER postgres WITH PASSWORD 'your_strong_password'; ALTER USER postgres WITH PASSWORD 'your_strong_password'; CREATE USER example_admin WITH PASSWORD 'secure_password'; \q CREATE USER example_admin WITH PASSWORD 'secure_password'; \q CREATE USER example_admin WITH PASSWORD 'secure_password'; \q $ -weight: 600;">sudo nano /etc/postgresql/18/main/pg_hba.conf $ -weight: 600;">sudo nano /etc/postgresql/18/main/pg_hba.conf $ -weight: 600;">sudo nano /etc/postgresql/18/main/pg_hba.conf local all postgres scram-sha-256 local all all scram-sha-256 local all postgres scram-sha-256 local all all scram-sha-256 local all postgres scram-sha-256 local all all scram-sha-256 $ -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart postgresql $ -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart postgresql $ -weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart postgresql $ -weight: 600;">sudo -u postgres psql $ -weight: 600;">sudo -u postgres psql $ -weight: 600;">sudo -u postgres psql CREATE DATABASE example_store OWNER example_admin; GRANT ALL PRIVILEGES ON DATABASE example_store TO example_admin; \q CREATE DATABASE example_store OWNER example_admin; GRANT ALL PRIVILEGES ON DATABASE example_store TO example_admin; \q CREATE DATABASE example_store OWNER example_admin; GRANT ALL PRIVILEGES ON DATABASE example_store TO example_admin; \q $ psql -U example_admin -d example_store -h localhost $ psql -U example_admin -d example_store -h localhost $ psql -U example_admin -d example_store -h localhost CREATE TABLE products ( product_id SERIAL PRIMARY KEY, product_name VARCHAR(100) NOT NULL, category VARCHAR(100), price NUMERIC(10, 2) ); INSERT INTO products (product_name, category, price) VALUES ('Widget A', 'Hardware', 9.99), ('Widget B', 'Software', 29.99), ('Widget C', 'Services', 49.99); SELECT * FROM products; \q CREATE TABLE products ( product_id SERIAL PRIMARY KEY, product_name VARCHAR(100) NOT NULL, category VARCHAR(100), price NUMERIC(10, 2) ); INSERT INTO products (product_name, category, price) VALUES ('Widget A', 'Hardware', 9.99), ('Widget B', 'Software', 29.99), ('Widget C', 'Services', 49.99); SELECT * FROM products; \q CREATE TABLE products ( product_id SERIAL PRIMARY KEY, product_name VARCHAR(100) NOT NULL, category VARCHAR(100), price NUMERIC(10, 2) ); INSERT INTO products (product_name, category, price) VALUES ('Widget A', 'Hardware', 9.99), ('Widget B', 'Software', 29.99), ('Widget C', 'Services', 49.99); SELECT * FROM products; \q - Use PostgreSQL as the database layer in a web application with Django or Rails - Set up streaming replication for high availability - Automate backups with pg_dump and a cron job