Skip to content

Refactor pg_os into single SQL file and improve documentation - #67

Merged
seanwevans merged 1 commit into
mainfrom
claude/project-cleanup-testing-7e97st
Jun 26, 2026
Merged

Refactor pg_os into single SQL file and improve documentation#67
seanwevans merged 1 commit into
mainfrom
claude/project-cleanup-testing-7e97st

Conversation

@seanwevans

Copy link
Copy Markdown
Owner

Summary

This PR consolidates the modular SQL files into a single pg_os--1.0.sql extension file, updates the README with clearer project description and usage examples, and fixes several bugs and inconsistencies in the codebase.

Key Changes

  • Consolidated SQL modules: Merged all separate SQL files (usersrolespermissions.sql, processes.sql, scheduler.sql, locks.sql, signals.sql, memory.sql, fs.sql, ipc.sql, audit.sql, gc.sql, io.sql, network.sql, modules.sql, power.sql) into a single pg_os--1.0.sql file for simpler installation and maintenance.

  • Renamed admin role: Changed pg_os_admin to pgos_admin throughout the codebase for consistency.

  • Fixed scheduler bug: Modified schedule_threads() to mark threads as terminated instead of ready after execution, preventing infinite loops in the scheduler.

  • Fixed type casting: Added explicit ::INTEGER cast in process_count_by_state() to resolve type inference issues.

  • Improved README:

    • Rewrote overview to clarify that pg_os is a teaching/experimentation toy that models OS concepts in SQL, not a way to control the host OS
    • Updated feature list to be more concise and accurate
    • Added concrete usage examples showing typical workflow (user creation, process management, memory allocation, file operations)
    • Clarified installation requirements and steps
    • Updated repository URL
  • Updated CI workflow: Changed PostgreSQL development headers package from postgresql-server-dev-16 to postgresql-server-dev-all for better compatibility across versions.

  • Updated test expectations: Fixed expected output files to match actual function behavior and formatting.

  • Updated Makefile: Reformatted REGRESS variable for better readability.

  • Updated .gitignore: Added regression test output files.

Notable Implementation Details

  • The single SQL file approach simplifies the extension build process while maintaining all functionality
  • Security DEFINER functions continue to be owned by pgos_admin role
  • All permission checks and locking mechanisms remain intact
  • The scheduler fix ensures proper thread state transitions and prevents busy-waiting

https://claude.ai/code/session_01Ty3Rkif9Vfe95w8TMiKB4b

The extension failed to install at all and CI never actually ran the
regression tests, so a number of real defects had gone unnoticed. This
makes `CREATE EXTENSION pg_os` work, gets the full suite passing, and
removes the divergent duplicate sources.

Correctness fixes (pg_os--1.0.sql):
- Rename the reserved-prefix roles pg_os_admin/pg_os_limited to
  pgos_admin/pgos_limited. CREATE ROLE rejects the reserved "pg_"
  prefix, which aborted CREATE EXTENSION entirely.
- Qualify ambiguous column references that errored under the default
  plpgsql.variable_conflict=error: create_file, version_file,
  unlock_file, process_count_by_state, handle_signals, free_memory.
- Point the SECURITY DEFINER lock/semaphore helpers' search_path at
  @extschema@ instead of pg_catalog so they can see the extension's
  own tables, and grant pgos_admin the privileges those helpers need
  so an unprivileged role can use the API without direct table access.
- Stop schedule_threads() from looping forever by terminating threads
  after they run instead of returning them to 'ready'.

Tests:
- Regenerate the stale expected output for create_file, file_versioning,
  lock_file and locks_security to match the corrected behaviour.
- Add the orphaned allocate_page test to REGRESS and drop the duplicate
  create_process entry.

CI:
- Build, install and actually run `make installcheck` (the previous
  workflow only started PostgreSQL), with a superuser role for the
  runner and regression diffs printed on failure.

Cleanup:
- Make pg_os--1.0.sql the single source of truth and remove the unused,
  drifted root-level module fragments (os.sql, fs.sql, processes.sql, …).
- Rewrite README to document the real API instead of nonexistent
  functions, and drop the empty resultmap file.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ty3Rkif9Vfe95w8TMiKB4b
@seanwevans
seanwevans merged commit d1b9169 into main Jun 26, 2026
0 of 2 checks passed
@seanwevans
seanwevans deleted the claude/project-cleanup-testing-7e97st branch June 26, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants