pg_os
is a PostgreSQL extension that provides operating system-level functionality directly within the database environment. By leveraging SQL procedures and functions, pg_os
enables users to interact with system processes, manage memory, handle inter-process communication (IPC), schedule tasks, and enforce security policies at the OS level.
The extension bridges the gap between the database and the underlying OS, allowing administrators to gain deep insights into system performance and control resource usage efficiently.
- Process Management – Monitor and control OS-level processes directly from PostgreSQL.
- File System Operations – Interact with the file system to read, write, and manipulate files.
- Memory Management – Analyze and manage memory allocations.
- IPC (Inter-Process Communication) – Facilitate communication between processes.
- Scheduler – Schedule jobs and tasks within PostgreSQL.
- Locks – Manage and analyze system and database locks.
- Security – Handle user roles and permissions at the OS level.
- Network Monitoring – Monitor and manage network interfaces and traffic.
- Power Management – Access and control power states of the system.
- I/O Operations – Track and manage input/output processes.
- Signal Management – Send and receive system signals.
- Garbage Collection – Monitor and optimize system garbage collection processes.
- Module Management – Inspect and control system modules.
- PostgreSQL 12+
- PL/pgSQL language extension enabled
- Sufficient OS-level permissions for system interaction
- Clone the repository:
git clone https://github.com/your-repo/pg_os.git
- Copy the SQL files to your PostgreSQL extensions directory:
cp *.sql /usr/share/postgresql/extension/
- Connect to your PostgreSQL instance:
psql -U postgres -d your_database
- Install the extension:
CREATE EXTENSION pg_os;
SELECT * FROM os_processes();
- Lists all current OS processes and their statuses.
SELECT * FROM fs_list('/var/log');
- Retrieves the contents of a directory.
SELECT * FROM os_memory_usage();
- Displays memory consumption statistics.
SELECT ipc_signal(12345, 'SIGTERM');
- Sends a termination signal to the process with PID 12345.
SELECT * FROM os_locks();
- Lists all current locks on system resources.
SELECT * FROM os_schedule_job('backup', '0 3 * * *', 'pg_dump your_database > backup.sql');
- Schedules a nightly backup at 3 AM.
SELECT * FROM os_network_interfaces();
- Lists all network interfaces and their statuses.
SELECT os_power_state('suspend');
- Suspends the system.
SELECT * FROM os_io_stats();
- Displays current I/O statistics.
SELECT os_send_signal(12345, 'SIGHUP');
- Sends a hang-up signal to the process with PID 12345.
SELECT * FROM os_gc_status();
- Monitors garbage collection processes.
SELECT * FROM os_modules();
- Lists all loaded system modules.
SELECT * FROM os_users_roles_permissions();
- Displays user roles and permissions.
audit.sql
– Handles audit logging and tracking.fs.sql
– Implements file system operations.ipc.sql
– Facilitates inter-process communication.locks.sql
– Manages lock operations.memory.sql
– Provides memory management utilities.os.sql
– Core OS interaction functions.processes.sql
– Monitors and manages system processes.scheduler.sql
– Implements job scheduling.usersrolespermissions.sql
– Manages users, roles, and permissions.network.sql
– Handles network monitoring and management.power.sql
– Implements power management functions.io.sql
– Tracks I/O operations.signals.sql
– Manages system signals.gc.sql
– Monitors and controls garbage collection.modules.sql
– Manages system modules.
Contributions are welcome! Please open an issue or submit a pull request with any improvements or bug fixes.
MIT License. See LICENSE
for more details.