Skip to content

Commit

Permalink
docs: Initial pg-stat-analysis project
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjcsmith committed Dec 3, 2024
1 parent f9a3c01 commit a10fdf0
Show file tree
Hide file tree
Showing 6 changed files with 858 additions and 1 deletion.
2 changes: 1 addition & 1 deletion data-connector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ docker run -e INFERABLE_API_SECRET="sk_xxxx" \
2. Rename `.env.example` to `.env` and set your Inferable API secret:

```bash
INFERABLE_SECRET=your_secret_here
INFERABLE_API_SECRET=your_secret_here

# DEMO POSTGRES CONFIG
POSTGRES_URL=postgresql://postgres:postgres@db:5432/postgres
Expand Down
1 change: 1 addition & 0 deletions examples/pg-stat-analysis/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
history.json
61 changes: 61 additions & 0 deletions examples/pg-stat-analysis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<p align="center">
<img src="https://a.inferable.ai/logo-hex.png" width="200" style="border-radius: 10px" />
</p>

# @inferable/pg-stat-analysis

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## Overview

`@inferable/pg-stat-analysis` is an analytical agent designed to evaluate and improve the performance of your PostgreSQL database through recommendations based on access patterns. The agent provides suggestions such as creating indexes or other optimization strategies to enhance query performance. It makes use of the `pg_stat_statements` extension to provide data-driven recommendations.

## Features

- Analyzes PostgreSQL database performance using `pg_stat_statements`.
- Provides suggestions for performance improvements.
- Avoids recommending redundant actions, such as VACUUM suggestions if auto-vacuum is enabled.
- Utilizes type-safety via Zod schema validation.

## Prerequisites

- **Node.js** - Ensure you have Node.js installed.
- **PostgreSQL** - A running PostgreSQL instance with the `pg_stat_statements` [extension enabled](https://www.postgresql.org/docs/current/pgstatstatements.html).
- **Data Connector** - This projects assumes you are runnign the [Inferable Data Connector](https://github.com/inferablehq/data-connector) which provides the connection to your database.

## Installation

1. **Install Dependencies:**

```bash
npm install
```

2. **Environment Setup:**

Create a `.env` file in the project root with the following variable:

```
INFERABLE_API_SECRET=your_inferable_api_secret
```

Replace `your_inferable_api_secret` with your Cluster's [API secret](https://docs.inferable.ai/pages/auth#cluster-api-keys).

## Usage

Once the environment is set up, you can run the project in development mode using the following command:

```bash
npm run dev
```

This will initiate the agent, which will analyze your database and provide performance-enhancing recommendations stored in `history.json`.
Multiple runs will append to the existing data in `history.json`.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## Support

If you have any questions or issues, please open an issue on this repository.
Loading

0 comments on commit a10fdf0

Please sign in to comment.