Main Page > Installing and using PostgreSQL on Arch
Posted on: 2023-11-01
Install PostgreSQL
sudo pacman -S postgresql
Check if it is running, start otherwise
sudo systemctl status postgresql
or
sudo systemctl start postgresql
Login into the DB shell to create a database
sudo -u postgres psql postgres
CREATE ROLE username LOGIN PASSWORD 'StRoNgPas$WoRd!';
CREATE DATABASE dbname WITH OWNER username;
\q
To check all DBs, just use "\d" or "\d dbname" to check tables.
Login with the newly added cridentials (username and password), then create a table for storing posts
psql -h localhost -d dbname -U username
CREATE TABLE posts(
post_id SERIAL PRIMARY KEY,
post_date DATE NOT NULL DEFAULT CURRENT_DATE,
post_title TEXT,
post_body TEXT
);
Try inserting and then checking some data
INSERT INTO posts (post_title, post_body) VALUES ('title', 'body');
SELECT * FROM posts;
To clear the table just run this command
DELETE FROM posts [WHERE `condition`];
Arch's wiki has a very detailed page here