Include: * create/drop/alter slot * acquire slot (register PID), flushed on proc exit * save/restore to disk on interval and shutdown * support shared_preload_libraries mode * support backend preload mode (but for LOAD 'slim') * support session backend (no preloading) * allows read/write on any PostgreSQL server, even "read-only" ones. |
||
---|---|---|
expected | ||
sql | ||
t | ||
LICENSE | ||
Makefile | ||
README.slim.md | ||
slim--0.0.1.sql | ||
slim.c | ||
slim.control |
slim Extension for PostgreSQL
THIS EXTENSION IS NOT READY FOR PRODUCTION YET. USE AT YOUR OWN RISK.
PRECISELY, SHMEM MANAGEMENT IN NOT WELL PROTECTED YET.
CAN LEAD TO DATA LOSS.
YOU'VE BEEN WARNED!
heavy locking
4 x 11th Gen Intel(R) Core(TM) i3-1115G4 @ 3.00GHz
create/drop: 30kTPS
create/drop/alter(concurrent): 17kTPS
slim
is a PostgreSQL extension that provides functions for managing slots with lightweight operations. It includes functionality for creating, altering, dropping, listing, saving, and restoring slots with specific attributes such as plugin and last activity.
Purpose
Provides read/write on Primary and Replica servers for managing plugins activity.
A plugin is anything connecting to slot, and acquiring it.
The original needs come from the PostgreQL Cumulative Statistics extention features in PostgreSQL 18.
It offers minimal persistency and locking.
Installation
To install the slim
extension, follow these steps:
-
Compile and Install: Run the following commands in your terminal to build and install the extension:
make sudo make install
-
Load the Extension: After installation, load the
slim
extension into your PostgreSQL database by executing:CREATE EXTENSION slim;
Note: Do not directly source the script into
psql
. Use theCREATE EXTENSION
command instead.
Provided Functions
slim_create_slot
Creates a new slot with the given parameters.
slim_create_slot(
IN name Name
, IN plugin Name
) RETURNS void;
- name: The name of the slot.
- plugin: The name of the plugin registered with this slot.
slim_alter_slot
Alters the plugin
for an existing slot by its name.
slim_alter_slot(name Name, plugin Name) RETURNS void;
- name: The name of the slot.
- plugin: The new plugin name to associate with the slot.
slim_drop_slot
Drops an existing slot by its name.
slim_drop_slot(name Name) RETURNS void;
- name: The name of the slot to be dropped.
slim_get_slots
Lists all existing slots with their attributes.
slim_get_slots() RETURNS TABLE (
name Name
, plugin Name
, active_pid integer
, inactive_since timestamptz
);
- name: The name of the slot.
- plugin: The name of the plugin registered with this slot.
- active_pid: The PID of the process currently using the slot.
- inactive_since: Timestamp indicating the last time the slot was associated with a PID.
slim_save_slots
Saves the current slots into a human-readable file format.
slim_save_slots() RETURNS void;
This file is in a human-readable format that allows for manual editing.
slim_restore_slots
Restores slots from a saved file.
slim_restore_slots() RETURNS void;
The file must be in the format saved by slim_save_slots
.
Usage Examples
-
Create a Slot:
SELECT slim_create_slot('my_slot', 'test_plugin');
-
Alter a Slot Plugin:
SELECT slim_alter_slot('my_slot', 'new_plugin');
-
Drop a Slot:
SELECT slim_drop_slot('my_slot');
-
List All Slots:
SELECT * FROM slim_get_slots();
-
Save Slots:
SELECT slim_save_slots();
-
Restore Slots:
SELECT slim_restore_slots();
Uninstallation
To remove the slim
extension from your PostgreSQL database, run:
DROP EXTENSION slim;
Notes
- Ensure that the
slim
extension is compiled against the same version of PostgreSQL that you are using. - For further information and troubleshooting, refer to the official PostgreSQL documentation: PostgreSQL Official Docs.
License
This extension is released under the PostgreSQL License. See LICENSE
for more details.
Contributions
Contributions are welcome! Please submit pull requests or issues on the project's repository.