Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ exclude = [
"pgrx-examples/numeric",
"pgrx-examples/pgtrybuilder",
"pgrx-examples/operators",
"pgrx-examples/parallel_scan_lwlock",
"pgrx-examples/range",
"pgrx-examples/schemas",
"pgrx-examples/shmem",
Expand Down
7 changes: 7 additions & 0 deletions pgrx-examples/parallel_scan_lwlock/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
.idea/
/target
*.iml
**/*.rs.bk
Cargo.lock
sql/shmem-1.0.sql
38 changes: 38 additions & 0 deletions pgrx-examples/parallel_scan_lwlock/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "parallel_scan_lwlock"
version = "0.0.0"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib", "lib"]

[[bin]]
name = "pgrx_embed_parallel_scan_lwlock"
path = "./src/bin/pgrx_embed.rs"

[features]
default = ["pg17"]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13"]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14"]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15"]
pg16 = ["pgrx/pg16", "pgrx-tests/pg16"]
pg17 = ["pgrx/pg17", "pgrx-tests/pg17"]
pg18 = ["pgrx/pg18", "pgrx-tests/pg18"]
pg_test = []

[dependencies]
pgrx = { path = "../../pgrx", default-features = false }

[dev-dependencies]
pgrx-tests = { path = "../../pgrx-tests" }

# uncomment these if compiling outside of 'pgrx'
# [profile.dev]
# panic = "unwind"

# [profile.release]
# panic = "unwind"
# opt-level = 3
# lto = "fat"
# codegen-units = 1
10 changes: 10 additions & 0 deletions pgrx-examples/parallel_scan_lwlock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Postgres Dynamic Shared Memory in Parallel Foreign Scans and LWLock Support

Important:
> Extensions that use shared memory **must** be loaded via `postgresql.conf`'s
>`shared_preload_libraries` configuration setting.

The example in [src/lib.rs](src/lib.rs) implements a parallel scan implementation for a "generator" foreign table type
that yields numbers from an integer counter, guarded by a dynamically allocated LWLock. It is meant to illustrate how to
set up a lock for foreign scans, keeping the shared memory handling as simple as possible. Check out the `shmem` example
project for more insights on shared memory handling in `pgrx` extensions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
comment = 'parallel_scan_lwlock: Created by pgrx'
default_version = '@CARGO_VERSION@'
module_pathname = 'parallel_scan_lwlock'
relocatable = false
superuser = false
1 change: 1 addition & 0 deletions pgrx-examples/parallel_scan_lwlock/src/bin/pgrx_embed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::pgrx::pgrx_embed!();
Loading
Loading