macOS:
pg_isready
# Should output: /tmp/.s.PGSQL.5432: accepting connections
Windows:
# Check if service is running
Get-Service postgresql*
# Or test connection
psql -U postgres -c "SELECT version();"
Docker:
# Check if container is running
docker-compose ps
# Or if using docker run:
docker ps | grep postgres
# Test connection
docker exec -it zooly-postgres pg_isready -U postgres
# Or if using docker run:
docker exec -it postgres-pgvector pg_isready -U postgres
# Test connection with psql
docker exec -it zooly-postgres psql -U postgres -c "SELECT version();"
If you encounter an error like role "your_username" does not exist when running createdb, you need to create a PostgreSQL user that matches your macOS username. You have two options:
Option 1: Create a PostgreSQL role matching your macOS username (Recommended)
This allows you to use createdb without specifying -U postgres:
# Connect to PostgreSQL as the postgres superuser
psql -U postgres
# Create a role matching your macOS username (replace 'your_username' with your actual macOS username)
CREATE ROLE your_username WITH LOGIN SUPERUSER CREATEDB CREATEROLE;
# Exit psql
\q
# Now you can use createdb without the -U flag
createdb zooly2_local
Option 2: Use the postgres user directly
Alternatively, you can always use the postgres user when creating databases:
createdb -U postgres zooly2_local
Or use psql directly:
psql -U postgres -c "CREATE DATABASE zooly2_local;"
Note: On macOS with Homebrew, PostgreSQL typically creates a default superuser matching your macOS username. If this role doesn't exist, you'll need to create it using Option 1 above. The postgres user always exists and can be used as an alternative.
macOS:
# If you created a role matching your username (Option 1):
createdb zooly2_local
# Or if using the postgres user (Option 2):
createdb -U postgres zooly2_local
Windows:
# Using psql
psql -U postgres -c "CREATE DATABASE zooly2_local;"
# Or using createdb (if in PATH)
createdb -U postgres zooly2_local
Docker:
# If using docker-compose with POSTGRES_DB set, database is created automatically
# Otherwise, create it manually:
docker exec -it zooly-postgres psql -U postgres -c "CREATE DATABASE zooly2_local;"
# Or if using docker run:
docker exec -it postgres-pgvector psql -U postgres -c "CREATE DATABASE zooly2_local;"
Note: On Windows, you may need to add PostgreSQL to your PATH or use the full path:
"C:\Program Files\PostgreSQL\17\bin\createdb.exe" -U postgres zooly2_local
Docker Note: If you set POSTGRES_DB: zooly2_local in your docker-compose.yml, the database will be created automatically when the container starts for the first time.
After creating the database, enable the pgvector extension:
macOS:
psql -U postgres -d zooly2_local -c "CREATE EXTENSION IF NOT EXISTS vector;"
Windows:
psql -U postgres -d zooly2_local -c "CREATE EXTENSION IF NOT EXISTS vector;"
Docker:
docker exec -it zooly-postgres psql -U postgres -d zooly2_local -c "CREATE EXTENSION IF NOT EXISTS vector;"
# Or if using docker run:
docker exec -it postgres-pgvector psql -U postgres -d zooly2_local -c "CREATE EXTENSION IF NOT EXISTS vector;"
Or connect to the database and run:
CREATE EXTENSION IF NOT EXISTS vector;
Docker Note: If you created an init-db.sql file and mounted it to /docker-entrypoint-initdb.d/init-db.sql, the pgvector extension will be enabled automatically when the container is first created.
# macOS
psql -l | grep zooly2_local
# Windows
psql -U postgres -l | findstr zooly2_local
List all databases:
# macOS
psql -l
# Windows
psql -U postgres -l
# Docker
docker exec -it zooly-postgres psql -U postgres -l
# Or if using docker run:
docker exec -it postgres-pgvector psql -U postgres -l
Update your .env.local file with the correct connection string:
# macOS (no password required for local user with Homebrew)
DATABASE_URL="postgres://postgres:password@localhost:5432/zooly2_local?sslmode=disable"
# Windows (use the password you set during installation)
DATABASE_URL="postgres://postgres:YOUR_PASSWORD@localhost:5432/zooly2_local?sslmode=disable"
# Docker (uses password from docker-compose.yml or docker run command)
DATABASE_URL="postgres://postgres:password@localhost:5432/zooly2_local?sslmode=disable"
Security: Replace YOUR_PASSWORD with the actual password you set during PostgreSQL installation on Windows. On macOS with Homebrew, the default user is your macOS username and typically doesn't require a password for local connections. For Docker, use the password specified in your POSTGRES_PASSWORD environment variable.
Docker Connection: When using Docker, PostgreSQL is accessible on localhost:5432 (or the port you mapped). The connection string is the same as native installations since Docker maps the container port to your host machine.
# Navigate to the app that manages the database
cd apps/zooly-app
npm run migrate