Initializing a Workspace for Modular Postgres Development
Dan Lynch
Nov 14, 2025
Previously: In pgpm Workspaces: A New Way to Organize Postgres Projects, we explored how workspaces bring modularity to Postgres. Now let's initialize your first workspace.
Ready to build your first pgpm workspace? In this lesson, you'll scaffold a complete workspace structure, configure it for your project, and prepare for modular database development. By the end, you'll have a working workspace ready for module creation.
Prerequisites
See Prerequisites.
Step 1: Install pgpm
Install pgpm globally:
bashnpm install -g pgpm
This gives you the pgpm command for workspace management, module scaffolding, and deployment.
Step 2: Initialize Your Workspace
Create a new workspace:
bashpgpm init workspace
pgpm prompts for a workspace name:
sh? Enter workspace name: my-database-project
Or, if you're not running interactively (for example, as an agent):
bashpgpm init workspace --no-tty \ --name my-database-project --repoName my-database-project \ --fullName "Ada Lovelace" --email ada@example.com \ --username ada --license MIT
pgpm scaffolds a complete pnpm monorepo:
textmy-database-project/ ├── docker-compose.yml ├── pgpm.json ├── lerna.json ├── LICENSE ├── Makefile ├── package.json ├── packages/ ├── pnpm-workspace.yaml ├── README.md └── tsconfig.json
This structure gives you everything needed for modular database development.
Step 3: Understanding the Workspace Structure
pgpm extends pnpm workspaces by adding a pgpm.json configuration file:
json{ "packages": ["packages/*"] }
This points pgpm to your modules directory, similar to how pnpm-workspace.yaml works for pnpm. You can customize the packages pattern or add additional configuration as needed.
Step 4: Configure Your Environment
First, see what environment variables pgpm will set:
bashpgpm env
This outputs the export statements:
bashexport PGHOST=localhost export PGPORT=5432 export PGUSER=postgres export PGPASSWORD=password export PGDATABASE=postgres
Now inject them into your current shell:
basheval $(pgpm env)
This sets PGHOST, PGUSER, PGPASSWORD, and other connection variables. See Prerequisites if you need help.
Step 5: Verify Your Setup
Check that Postgres is accessible:
bashpsql -c "SELECT version();"
You should see Postgres version information. If not, ensure Docker is running and Postgres is started. See Prerequisites for help.
What's Next
You now have a working pgpm workspace. In the next lesson, we'll create your first database module inside this workspace. You'll learn about module structure, the .control file, and the pgpm.plan file that tracks your migrations.
Key Takeaways
pgpm init workspacescaffolds a complete pnpm monorepo- The
pgpm.jsonfile configures module discovery - Ensure Postgres is running locally before starting
- Environment variables configure Postgres connection
Your workspace is now ready for modular database development. Let's create your first module.

