π Section: Setting Up PostgreSQL for Production
Now that we have:
PostgreSQL installed
pgAdmin installed
Weβre going to create our production database for our Todo Application.
Up until now, we were using SQLite.
Now weβre moving to a real production-ready database system.
π₯ Step 1 β Register a Server in pgAdmin
When you first install PostgreSQL and open pgAdmin, you will see the server group called Servers:

This Servers group is created by default.
If you donβt see it:
Right-click β Create β Server Group
But normally itβs already there.
Register a New Server
Right-click on:
Servers β Register β Serverπ General Tab
Name:
TodoAppServerServer Group:
Serversπ Connection Tab
Set:
Host name/address β
localhostPort β
5432(default)Username β
postgresPassword β (your Postgres password)
Click Save
Now under:
Servers
βββ TodoApplicationServerThis server will host:
Databases
Tables
Roles
Permissions
π Step 2 β Verify Superuser
Inside TodoApplicationServer Open:
Login/Group RolesYou should see:
postgresRight-click (postgres)β Properties β Privileges
Make sure:
Superuser = β True
If you donβt have a superuser:
Right-click (Login/Group Rules) β Create β Login/Group Role
Set all privilege flags to True
This account will own our production database with all access.
π Step 3 β Create the Production Database
Under: TodoApplicationServer
Databases β Right-click β Create β DatabaseName:
TodoAppOwner:
postgresClick Save.
By default, pgAdmin connects automatically.
If not:
Right-click(TodoApp) β Connect to Database.
π§± Step 4 β Create Tables Using SQL
Inside the new database:
Click the Query Tool (top-left icon) β
This allows us to run raw SQL.
π SQL Script
We now recreate the same tables we had in SQLite.
DROP TABLE IF EXISTS users;
CREATE TABLE users (
id SERIAL,
email varchar(200) DEFAULT NULL,
username varchar(45) DEFAULT NULL,
first_name varchar(45) DEFAULT NULL,
last_name varchar(45) DEFAULT NULL,
hashed_password varchar(200) DEFAULT NULL,
is_active boolean DEFAULT NULL,
role varchar(45) DEFAULT NULL,
PRIMARY KEY (id));
DROP TABLE IF EXISTS todos;
CREATE TABLE todos (
id SERIAL,
title varchar(200) DEFAULT NULL,
description varchar(200) DEFAULT NULL,
priority integer DEFAULT NULL,
complete boolean DEFAULT NULL,
owner_id integer DEFAULT NULL,
PRIMARY KEY (id),
FOREIGN KEY (owner_id) REFERENCES users(id));
π§ Important Backend Concepts
What is SERIAL?
In PostgreSQL:
SERIALMeans:
Auto-incrementing integer
Similar to
INTEGER PRIMARY KEY AUTOINCREMENTin SQLite
What is FOREIGN KEY?
FOREIGN KEY (owner_id) REFERENCES users(id)This creates a relationship:
Each todo belongs to a user
Enforces referential integrity
Prevents orphan records
This is real relational database design.
π Execute the Script
Click the Execute button.

You may see:
NOTICE: table does not exist, skipping
Thatβs normal.
It just means it didnβt previously exist.
π Refresh Tables
Right-click: TodoApp β Schemas β Tables β Refresh
You should now see:
users
todos
π Step 5 β Verify Tables
Run:
SELECT * FROM todos;You should see:
Columns:
id
title
description
priority
complete
owner_id
No records yet.
Then:
SELECT * FROM users;Columns:
id
email
username
first_name
last_name
hashed_password
is_active
role
Still no records.
π What We Just Built
We now have:
β A PostgreSQL production database
β Two relational tables
β Foreign key relationship
β Proper primary keys
β Superuser ownership
This is now production-level infrastructure.