Skip to content

Commit

Permalink
Add build from source instructions (#19)
Browse files Browse the repository at this point in the history
* Add instructions to install against existing Postgres setup

* Fix link

* Formatting fixes

* More formatting fixes

---------

Co-authored-by: Samay Sharma <[email protected]>
  • Loading branch information
samay-sharma and samay-sharma authored Aug 7, 2023
1 parent 440b504 commit 2c2d807
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 17 deletions.
56 changes: 40 additions & 16 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Postgres Message Queue (PGMQ)
# Contributing to Postgres Message Queue (PGMQ)

## Installation

Expand All @@ -8,44 +8,68 @@ The fastest way to get started is by running the Tembo docker image, where PGMQ
docker run -d --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 quay.io/tembo/pgmq-pg:latest
```

# Development
## Building from source

Setup `pgrx`.
PGMQ is written as a Rust extension and requires [pgrx](https://github.com/pgcentralfoundation/pgrx).

To build pgmq from source, you need
* A toolchain capable of building Postgres
* Rust toolchain
* [pg_partman](https://github.com/pgpartman/pg_partman).

Once you have those pre-requisites, you need to setup `pgrx`.

```bash
cargo install --locked cargo-pgrx
cargo pgrx init
cargo install --locked cargo-pgrx --version 0.9.8
```

Then, clone this repo and change into this directory.
Clone the repo and change into the directory.

```bash
git clone git@https://github.com/tembo-io/pgmq.git
git clone https://github.com/tembo-io/pgmq.git
cd pgmq
```

### Setup dependencies
After this point, the steps differ slightly based on if you'd like to build
and install against an existing Postgres setup or develop against pgrx managed
development environment (which installs and allows you to test against multiple
Postgres versions).

Install:
- [pg_partman](https://github.com/pgpartman/pg_partman), which is required for partitioned tables.
### Install to a pre-existing Postgres

Initialize `cargo-pgrx`, and tell it the path to the your `pg_config`. For example,
if `pg_config` is on your `$PATH` and you have Postgres 15, you can run:

Update postgresql.conf in the development environment.
```bash
cargo pgrx init --pg15=`which pg_config`
```
Then, to install the release build, you can simply run:
```
cargo pgrx install --release
```
# ~/.pgrx/data-14/postgresql.conf
shared_preload_libraries = 'pg_partman_bgw'

### Install against pgrx managed Postgres (Recommended for Development)

Initialize `cargo-pgrx` development environment:

```bash
cargo pgrx init
```

**Note**: Make sure you build and install `pg_partman` against the postgres installation
you want to build against (`PG_CONFIG` in `~/.pgrx/PG_VERSION/pgrx-install/bin/pg_config`
and `PGDATA` in `/Users/samaysharma/.pgrx/data-PG_MAJOR_VERSION`)

Run the dev environment
Then, you can use the run command, which will build and install the extension
and drop you into psql:

```bash
cargo pgrx run pg15
```

Create the extension
Finally, you can create the extension and get started with the example in the [README.md](README.md).

```pql
```psql
CREATE EXTENSION pgmq cascade;
```

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ The fastest way to get started is by running the Tembo docker image, where PGMQ
docker run -d --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 quay.io/tembo/pgmq-pg:latest
```

If you'd like to build from source, you can follow the instructions in [CONTRIBUTING.md](CONTRIBUTING.md)

## Client Libraries


Expand Down Expand Up @@ -222,7 +224,7 @@ Add the following to `postgresql.conf`. Note, changing `shared_preload_libraries
`pg_partman_bgw.interval` sets the interval at which `pg_partman` conducts maintenance. This creates new partitions and dropping of partitions falling out of the `retention_interval`. By default, `pg_partman` will keep 4 partitions "ahead" of the currently active partition.

```
shared_preload_libraries = 'pg_partman_bgw' # requires restart of Postgrs
shared_preload_libraries = 'pg_partman_bgw' # requires restart of Postgres
pg_partman_bgw.interval = 60
pg_partman_bgw.role = 'postgres'
pg_partman_bgw.dbname = 'postgres'
Expand Down

0 comments on commit 2c2d807

Please sign in to comment.