-
-
Notifications
You must be signed in to change notification settings - Fork 2
Linux PostgreSQL Guide
Mattscreative edited this page Dec 5, 2025
·
2 revisions
Complete beginner-friendly guide to PostgreSQL on Linux, covering Arch Linux, CachyOS, and other distributions including installation, configuration, and database management.
Arch/CachyOS:
# Install PostgreSQL
sudo pacman -S postgresql
# Initialize database
sudo -u postgres initdb -D /var/lib/postgres/data
# Enable service
sudo systemctl enable --now postgresqlDebian/Ubuntu:
sudo apt install postgresql postgresql-contribFedora:
sudo dnf install postgresql-server postgresql
sudo postgresql-setup --initdbCheck PostgreSQL:
# Check service
systemctl status postgresql
# Connect to database
sudo -u postgres psqlCreate database user:
-- In psql
CREATE USER myuser WITH PASSWORD 'mypassword';
CREATE DATABASE mydb OWNER myuser;
GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;Edit pg_hba.conf:
# Edit config
sudo vim /var/lib/postgres/data/pg_hba.confConnect:
# As postgres user
sudo -u postgres psql
# As specific user
psql -U myuser -d mydbSQL commands:
-- Create table
CREATE TABLE users (id SERIAL PRIMARY KEY, name VARCHAR(100));
-- Insert data
INSERT INTO users (name) VALUES ('John');
-- Query
SELECT * FROM users;Check logs:
# Check service
systemctl status postgresql
# Check logs
journalctl -u postgresql
# Check data directory
ls -la /var/lib/postgres/dataThis guide covered PostgreSQL installation, configuration, and database management for Arch Linux, CachyOS, and other distributions.
- Database Servers - Database setup
- Development Environment - Development
- PostgreSQL: https://www.postgresql.org/
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.