Lesson 3of 5
Fix 'psql' is not recognized on Windows
Solutions to fix the 'psql' is not recognized error on Windows by adding PostgreSQL to PATH or reinstalling PostgreSQL with psql.
✅ Method 1: Using CREATE DATABASE ... WITH TEMPLATE (Easiest)
This is the fastest and recommended way.
Syntax:
CREATE DATABASE new_db_name
WITH TEMPLATE old_db_name
OWNER your_user;Example:
CREATE DATABASE school_copy
WITH TEMPLATE school
OWNER postgres;⚠️ Important Notes:
- No one should be connected to the source database
- You must be a superuser or owner
- Works best for small to medium databases
To disconnect users:
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname = 'school';