PostgreSQL Tools in Cursor - Quick Reference
Last Updated: 2025-10-26
Installed Extensions
Primary Database Tools
- 
SQLTools ( mtxr.sqltools)- Multi-database SQL client
- IntelliSense and autocomplete
- Query history and bookmarks
- Export to CSV/JSON
 
- 
SQLTools PostgreSQL Driver ( mtxr.sqltools-driver-pg)- Native PostgreSQL support
- Connection pooling
- Transaction support
 
- 
PostgreSQL Explorer ( ckolkman.vscode-postgres)- Database tree view in sidebar
- Schema browser
- Table data preview
- JSONB field pretty-printing
 
- 
Database Client ( cweijan.vscode-database-client2)- Universal database manager
- ERD diagram generation
- Import/export utilities
- SSH tunnel support
 
- 
pgFormatter ( bradymholt.pgformatter)- Auto-format SQL files
- Consistent code style
- Format on save enabled
 
Pre-configured Connections
Two connections are configured in .vscode/settings.json:
1. TVL Local (postgres) - Admin Access
- User: postgres
- Password: postgres
- Use for: Schema management, migrations, admin tasks
- Auto-connects: Opens automatically when Cursor starts
2. TVL Local (tvl_user) - Application Access
- User: tvl_user
- Password: tvl_password
- Use for: Testing RLS policies, simulating app queries
Quick Start
1. Open SQLTools Panel
Cmd/Ctrl + Shift + P → SQLTools: Focus on SQLTools View
Or click the database icon in the Activity Bar (left sidebar).
2. Run a Query
Method A: SQL File
- Create/open a .sqlfile
- Write your query
- Right-click → Run on Active Connection
- Or use shortcut: Cmd/Ctrl + E, E
Method B: SQLTools Scratchpad
- Open SQLTools panel
- Click "New SQL File" icon
- Select connection: TVL Local (postgres)
- Write and run query
Method C: PostgreSQL Explorer
- Open PostgreSQL Explorer in sidebar
- Browse to a table
- Right-click → New Query
- Query editor opens pre-filled
3. Browse Database Schema
SQLTools:
- Expand connection → tvl_dev→public→Tables
- Right-click table → Show Table Records(preview data)
- Right-click table → Describe Table(show schema)
PostgreSQL Explorer:
- Expand connection → Schemas → public → Tables
- Click table name to see columns
- Click "Play" icon next to table to query
Common Tasks
View All Tables
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
ORDER BY table_name;
Check RLS Policies
SELECT schemaname, tablename, policyname, permissive, roles, cmd, qual
FROM pg_policies
WHERE schemaname = 'public'
ORDER BY tablename, policyname;
Test RLS as tvl_user
- Switch to TVL Local (tvl_user)connection
- Run query with tenant context:
-- Set tenant context (simulates application login)
SELECT set_config('app.current_org_id', '123e4567-e89b-12d3-a456-426614174000', false);
SELECT set_config('app.current_account_id', '123e4567-e89b-12d3-a456-426614174001', false);
-- Now query will respect RLS
SELECT * FROM properties;
View Query Execution Plan
EXPLAIN ANALYZE
SELECT p.*
FROM properties p
INNER JOIN accounts a ON p.account_id = a.id
WHERE p.org_id = '123e4567-e89b-12d3-a456-426614174000';
Export Query Results
- Run your query
- In results panel, click Export icon
- Choose format: CSV, JSON, or SQL INSERT
Format SQL File
Auto-format on save: Already enabled Manual format:
- Right-click in SQL file → Format Document
- Or: Cmd/Ctrl + Shift + F
View Table Data
SQLTools:
- Right-click table → Show Table Records
- Results appear in panel (default: 50 rows)
PostgreSQL Explorer:
- Click table name
- Click "Show Data" button
Generate ERD (Entity Relationship Diagram)
Database Client Extension:
- Open Database Client panel
- Connect to TVL Local (postgres)
- Right-click database → Generate ERD
- Interactive diagram shows all relationships
Keyboard Shortcuts
| Action | Shortcut | 
|---|---|
| Run SQL query | Cmd/Ctrl + E, E | 
| Run selected SQL | Cmd/Ctrl + E, E(with selection) | 
| Format SQL document | Cmd/Ctrl + Shift + F | 
| Open SQLTools | Cmd/Ctrl + Shift + P→ "SQLTools" | 
| New SQL file | Cmd/Ctrl + N→ Save as.sql | 
Tips & Tricks
1. Query Snippets
Create reusable SQL snippets in SQLTools:
- Write query in scratchpad
- Click bookmark icon
- Name your snippet
- Access from "Bookmarks" tab
2. Multiple Connections
Switch between postgres and tvl_user to test:
- Admin operations (create tables, migrations)
- User-level access (RLS policy enforcement)
3. Transaction Support
BEGIN;
  INSERT INTO properties (org_id, account_id, name) VALUES (...);
  -- Test the insert
  SELECT * FROM properties WHERE name = 'Test Property';
ROLLBACK; -- or COMMIT;
4. Connection Pooling
SQLTools maintains persistent connections:
- Faster query execution
- No repeated authentication
- Configurable timeout (30s in settings)
5. IntelliSense
As you type SQL:
- Table names autocomplete
- Column names suggested after SELECT
- Function signatures shown
- PostgreSQL keywords highlighted
Alternative Tools
Command Line (psql)
# From terminal in Cursor
pnpm psql:connect
# Or directly
docker exec -it the-villa-life-postgres-1 psql -U postgres -d tvl_dev
pgAdmin (Web UI)
Open in browser: http://localhost:5050
- Email: admin@thevillalife.com
- Password: admin
Best for:
- Visual query builder
- Performance tuning (EXPLAIN ANALYZE visualizations)
- Backup/restore operations
Supabase CLI
# Check local instance
supabase status
# View functions
supabase functions list
# Test RLS policies
supabase test db
Troubleshooting
Connection Refused
Issue: connect ECONNREFUSED 127.0.0.1:5432
Fix:
- Ensure PostgreSQL container is running:
docker ps | grep postgres
- Check health:
pnpm psql:debug
- Restart if needed:
docker-compose -f .devcontainer/docker-compose.yml restart postgres
Authentication Failed
Issue: password authentication failed for user "tvl_user"
Fix:
- Verify credentials in .devcontainer/docker-compose.yml
- Check if user exists:
-- Connect as postgres
 SELECT usename FROM pg_user WHERE usename = 'tvl_user';
- Re-run init script if needed:
pnpm db:reset
Query Timeout
Issue: Query runs forever
Fix:
- Kill query in PostgreSQL:
SELECT pg_cancel_backend(pid)
 FROM pg_stat_activity
 WHERE state = 'active' AND pid <> pg_backend_pid();
- Increase timeout in settings (currently 30s)
Extension Not Working
Issue: Extension features not showing
Fix:
- Reload Cursor window:
Cmd/Ctrl + Shift + P → Developer: Reload Window
- Check extension is enabled:
Cmd/Ctrl + Shift + X → Search for extension
- Reinstall extension if needed
Configuration Files
.vscode/extensions.json
Recommended extensions for the team. Cursor prompts to install on first open.
.vscode/settings.json
- SQLTools connections (postgres + tvl_user)
- pgFormatter settings (2 spaces, comma breaks)
- File associations (*.sql → postgres syntax)
- Auto-format on save for SQL files
References
- SQLTools Docs: https://vscode-sqltools.mteixeira.dev/
- PostgreSQL Extension: https://marketplace.visualstudio.com/items?itemName=ckolkman.vscode-postgres
- pgFormatter: https://marketplace.visualstudio.com/items?itemName=bradymholt.pgformatter
- Database Guides: /docs/guides/
- Schema Reference: /docs/reference/database/migrations/
Questions? Check the database troubleshooting guide: /docs/guides/database-troubleshooting.md