Getting Started with Databases (PostgreSQL on Ubuntu)
A database stores your application’s data. PostgreSQL is a powerful, open-source relational database. This guide installs it and creates your first database and user.
1. Install PostgreSQL
sudo apt update
sudo apt install -y postgresql postgresql-contrib2. Verify the service
sudo systemctl enable --now postgresql
sudo systemctl status postgresql3. Create a database and user
sudo -u postgres psql
CREATE DATABASE myapp;
CREATE USER myuser WITH ENCRYPTED PASSWORD 'strong_password';
GRANT ALL PRIVILEGES ON DATABASE myapp TO myuser;
\q4. Connect to your database
psql -h localhost -U myuser -d myappRelational databases (PostgreSQL, MySQL) use tables and SQL; NoSQL databases (MongoDB, Redis) store documents or key-value pairs. Choose based on your data structure and query needs.