Skip to content

Commit 0d80fcd

Browse files
Postgres 18 support (#154)
1 parent f3e21a7 commit 0d80fcd

File tree

8 files changed

+103
-51
lines changed

8 files changed

+103
-51
lines changed

.devcontainer/Dockerfile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@ FROM ubuntu:22.04
33
ENV DEBIAN_FRONTEND="noninteractive"
44
ENV TZ="Europe/Istanbul"
55

6-
ARG PG_MAJOR=17
6+
ARG PG_MAJOR=18
77

88
# install deps
99
RUN apt-get update && apt-get -y install build-essential libreadline-dev zlib1g-dev \
1010
flex bison libxml2-dev libxslt-dev libssl-dev \
1111
libxml2-utils xsltproc ccache pkg-config wget \
1212
curl lsb-release ca-certificates gnupg sudo git \
13-
nano net-tools awscli
13+
nano net-tools awscli libkrb5-dev
1414

1515
# install azure-cli
1616
RUN curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /etc/apt/keyrings/microsoft.gpg > /dev/null
1717
RUN echo "deb [arch=`dpkg --print-architecture` signed-by=/etc/apt/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/azure-cli/ `lsb_release -cs` main" | tee /etc/apt/sources.list.d/azure-cli.list
1818
RUN apt-get update && apt-get install -y azure-cli
1919

2020
# install Postgres
21-
RUN sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
21+
RUN sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' && \
22+
sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg 18" >> /etc/apt/sources.list.d/pgdg.list'
2223
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
2324
RUN apt-get update && apt-get -y install postgresql-${PG_MAJOR}-postgis-3 \
2425
postgresql-server-dev-${PG_MAJOR} \
@@ -27,11 +28,17 @@ RUN apt-get update && apt-get -y install postgresql-${PG_MAJOR}-postgis-3 \
2728

2829
# set up permissions so that rust user can create extensions
2930
RUN chmod a+rwx `pg_config --pkglibdir` \
31+
`pg_config --pkglibdir`/bitcode \
3032
`pg_config --sharedir`/extension \
3133
/var/run/postgresql/
3234

33-
# install pgaudit
34-
RUN apt-get update && apt-get -y install postgresql-${PG_MAJOR}-pgaudit
35+
# install pgaudit extension
36+
RUN if [ ${PG_MAJOR} != "18" ]; then \
37+
apt-get -y install postgresql-${PG_MAJOR}-pgaudit; \
38+
else \
39+
git clone --branch integration https://github.com/pgaudit/pgaudit.git /tmp/pgaudit && \
40+
cd /tmp/pgaudit && make install USE_PGXS=1 PG_CONFIG=pg_config; \
41+
fi
3542

3643
# initdb requires non-root user. This will also be the user that runs the container.
3744
ARG USERNAME=rust

.github/workflows/ci.yml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
build-and-test:
2020
strategy:
2121
matrix:
22-
postgres: [ 14, 15, 16, 17 ]
22+
postgres: [ 14, 15, 16, 17, 18 ]
2323
runs_on: [ 'ubuntu-22.04', 'ubuntu-22.04-arm' ]
2424
include:
2525
- runs_on: ubuntu-22.04
@@ -91,24 +91,21 @@ jobs:
9191
curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python
9292
pipenv install --dev
9393
94-
- name: Install PostgreSQL
94+
- name: Install PostgreSQL and postgis
9595
run: |
9696
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
97+
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg 18" >> /etc/apt/sources.list.d/pgdg.list'
9798
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
9899
sudo apt-get update
99100
sudo apt-get -y install build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev \
100101
libxslt-dev libssl-dev libxml2-utils xsltproc ccache pkg-config \
101-
gnupg ca-certificates
102-
sudo apt-get -y install postgresql-${{ env.PG_MAJOR }}-postgis-3 \
102+
gnupg ca-certificates libkrb5-dev
103+
sudo apt-get -y install postgresql-${{ env.PG_MAJOR }}-postgis-3 \
103104
postgresql-server-dev-${{ env.PG_MAJOR }} \
104-
postgresql-client-${{ env.PG_MAJOR }} \
105+
postgresql-client-${{ env.PG_MAJOR }} \
105106
libpq-dev
106107
echo "export PG_MAJOR=${{ env.PG_MAJOR }}" >> $GITHUB_ENV
107108
108-
- name: Install pgaudit extension
109-
run: |
110-
sudo apt-get install -y postgresql-${{ env.PG_MAJOR }}-pgaudit
111-
112109
- name: Install azure-cli
113110
run: |
114111
curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo tee /etc/apt/keyrings/microsoft.gpg > /dev/null
@@ -124,27 +121,45 @@ jobs:
124121

125122
- name: Set up permissions for PostgreSQL
126123
run: |
127-
sudo chmod a+rwx $(/usr/lib/postgresql/${{ env.PG_MAJOR }}/bin/pg_config --pkglibdir) \
128-
$(/usr/lib/postgresql/${{ env.PG_MAJOR }}/bin/pg_config --sharedir)/extension \
124+
sudo chmod a+rwx $(${{ env.PG_CONFIG }} --pkglibdir) \
125+
$(${{ env.PG_CONFIG }} --pkglibdir)/bitcode \
126+
$(${{ env.PG_CONFIG }} --sharedir)/extension \
129127
/var/run/postgresql/
130128
129+
- uses: actions/checkout@v4
130+
if: ${{ env.PG_MAJOR == '18' }}
131+
with:
132+
repository: 'pgaudit/pgaudit'
133+
ref: 'integration'
134+
path: pgaudit
135+
136+
- name: Install pgaudit extension for pg18
137+
if: ${{ env.PG_MAJOR == '18' }}
138+
run: |
139+
cd pgaudit && make install USE_PGXS=1 PG_CONFIG=${{ env.PG_CONFIG }}
140+
141+
- name: Install pgaudit extension for < pg18
142+
if: ${{ env.PG_MAJOR != '18' }}
143+
run: |
144+
sudo apt-get -y install postgresql-${{ env.PG_MAJOR }}-pgaudit
145+
131146
- name: Check format and lint
132147
run: |
133148
make check-format
134149
make check-lint
135150
136151
- name: Run tests without coverage
137-
if: ${{ env.PG_MAJOR != '17' || matrix.arch != 'x86_64' }}
152+
if: ${{ env.PG_MAJOR != '18' || matrix.arch != 'x86_64' }}
138153
run: |
139154
make check
140155
141156
- name: Run tests with coverage
142-
if: ${{ env.PG_MAJOR == '17' && matrix.arch == 'x86_64' }}
157+
if: ${{ env.PG_MAJOR == '18' && matrix.arch == 'x86_64' }}
143158
run: |
144159
make check-with-coverage
145160
146161
- name: Upload coverage report to Codecov
147-
if: ${{ env.PG_MAJOR == '17' && matrix.arch == 'x86_64' }}
162+
if: ${{ env.PG_MAJOR == '18' && matrix.arch == 'x86_64' }}
148163
uses: codecov/codecov-action@v4
149164
with:
150165
fail_ci_if_error: true

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ name = "pgrx_embed_pg_parquet"
1212
path = "./src/bin/pgrx_embed.rs"
1313

1414
[features]
15-
default = ["pg17"]
15+
default = ["pg18"]
16+
pg18 = ["pgrx/pg18", "pgrx-tests/pg18"]
1617
pg17 = ["pgrx/pg17", "pgrx-tests/pg17"]
1718
pg16 = ["pgrx/pg16", "pgrx-tests/pg16"]
1819
pg15 = ["pgrx/pg15", "pgrx-tests/pg15"]
@@ -51,6 +52,9 @@ url = "2"
5152
[dev-dependencies]
5253
pgrx-tests = "=0.16.0"
5354

55+
[build-dependencies]
56+
cfg_aliases = "0.2"
57+
5458
[profile.dev]
5559
panic = "unwind"
5660

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ After installing `Postgres`, you need to set up `rustup`, `cargo-pgrx` to build
4242

4343
# set cargo-pgrx (should be the same as pgrx dep in Cargo.toml) and pg versions
4444
> export CARGO_PGRX_VERSION=0.16.0
45-
> export PG_MAJOR=17
45+
> export PG_MAJOR=18
4646

4747
# install cargo-pgrx
4848
> cargo install --force --locked cargo-pgrx@"${CARGO_PGRX_VERSION}"
@@ -385,3 +385,4 @@ There is currently only one GUC parameter to enable/disable the `pg_parquet`:
385385
| 15 ||
386386
| 16 ||
387387
| 17 ||
388+
| 18 ||

build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::process::Command;
22

3+
use cfg_aliases::cfg_aliases;
4+
35
fn main() {
46
println!("cargo::rustc-check-cfg=cfg(rhel8)");
57
let output = Command::new("cat")
@@ -12,4 +14,11 @@ fn main() {
1214
if os_info.contains("platform:el8") {
1315
println!("cargo::rustc-cfg=rhel8");
1416
}
17+
18+
cfg_aliases! {
19+
pre_pg18: { any(feature = "pg14", feature = "pg15", feature = "pg16", feature = "pg17") },
20+
pre_pg17: { any(feature = "pg14", feature = "pg15", feature = "pg16") },
21+
pre_pg16: { any(feature = "pg14", feature = "pg15") },
22+
pre_pg15: { any(feature = "pg14") },
23+
}
1524
}

src/parquet_copy_hook/copy_to.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ pub(crate) fn execute_copy_to_with_dest_receiver(
9696
portal.as_ptr(),
9797
i64::MAX,
9898
false,
99-
true,
99+
#[cfg(pre_pg18)]
100+
true, // run_once
100101
parquet_dest.as_ptr(),
101102
parquet_dest.as_ptr(),
102103
&mut completion_tag as _,
@@ -214,6 +215,20 @@ fn copy_to_stmt_ensure_table_kind(relation: &PgRelation) {
214215
"Try the COPY (SELECT ...) TO variant.",
215216
);
216217
} else if relation_kind == RELKIND_MATVIEW as c_char {
218+
#[cfg(not(pre_pg18))]
219+
if !(unsafe { *relation.rd_rel }).relispopulated {
220+
ereport!(
221+
PgLogLevel::ERROR,
222+
PgSqlErrorCode::ERRCODE_FEATURE_NOT_SUPPORTED,
223+
format!(
224+
"cannot copy from unpopulated materialized view \"{}\"",
225+
relation.name()
226+
),
227+
"Use the REFRESH MATERIALIZED VIEW command.",
228+
);
229+
}
230+
231+
#[cfg(pre_pg18)]
217232
ereport!(
218233
PgLogLevel::ERROR,
219234
PgSqlErrorCode::ERRCODE_WRONG_OBJECT_TYPE,

src/parquet_copy_hook/pg_compat.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(crate) fn pg_analyze_and_rewrite(
1515
query_string: *const c_char,
1616
query_env: *mut QueryEnvironment,
1717
) -> *mut List {
18-
#[cfg(feature = "pg14")]
18+
#[cfg(pre_pg15)]
1919
unsafe {
2020
pgrx::pg_sys::pg_analyze_and_rewrite(
2121
raw_stmt,
@@ -26,7 +26,7 @@ pub(crate) fn pg_analyze_and_rewrite(
2626
)
2727
}
2828

29-
#[cfg(any(feature = "pg15", feature = "pg16", feature = "pg17"))]
29+
#[cfg(not(pre_pg15))]
3030
unsafe {
3131
pgrx::pg_sys::pg_analyze_and_rewrite_fixedparams(
3232
raw_stmt,
@@ -40,7 +40,7 @@ pub(crate) fn pg_analyze_and_rewrite(
4040

4141
#[allow(non_snake_case)]
4242
pub(crate) fn strVal(val: *mut Node) -> String {
43-
#[cfg(feature = "pg14")]
43+
#[cfg(pre_pg15)]
4444
unsafe {
4545
let val = (*(val as *mut pgrx::pg_sys::Value)).val.str_;
4646

@@ -50,7 +50,7 @@ pub(crate) fn strVal(val: *mut Node) -> String {
5050
.to_string()
5151
}
5252

53-
#[cfg(any(feature = "pg15", feature = "pg16", feature = "pg17"))]
53+
#[cfg(not(pre_pg15))]
5454
unsafe {
5555
let val = (*(val as *mut pgrx::pg_sys::String)).sval;
5656

@@ -63,20 +63,20 @@ pub(crate) fn strVal(val: *mut Node) -> String {
6363

6464
#[allow(non_snake_case)]
6565
pub(crate) fn MarkGUCPrefixReserved(guc_prefix: &str) {
66-
#[cfg(feature = "pg14")]
66+
#[cfg(pre_pg15)]
6767
unsafe {
6868
pgrx::pg_sys::EmitWarningsOnPlaceholders(guc_prefix.as_pg_cstr())
6969
}
7070

71-
#[cfg(any(feature = "pg15", feature = "pg16", feature = "pg17"))]
71+
#[cfg(not(pre_pg15))]
7272
unsafe {
7373
pgrx::pg_sys::MarkGUCPrefixReserved(guc_prefix.as_pg_cstr())
7474
}
7575
}
7676

7777
/// check_copy_table_permission checks if the user has permission to copy from/to the table.
7878
/// This is taken from the original PostgreSQL DoCopy function.
79-
#[cfg(any(feature = "pg16", feature = "pg17"))]
79+
#[cfg(not(pre_pg16))]
8080
pub(crate) fn check_copy_table_permission(
8181
p_stmt: &PgBox<PlannedStmt>,
8282
p_state: &PgBox<ParseState>,
@@ -134,28 +134,7 @@ pub(crate) fn check_copy_table_permission(
134134
unsafe { reset_pgaudit(guc_level) };
135135
}
136136

137-
unsafe fn disable_pgaudit() -> i32 {
138-
let guc_level = NewGUCNestLevel();
139-
140-
set_config_option(
141-
"pgaudit.log".as_pg_cstr(),
142-
"none".as_pg_cstr(),
143-
PGC_SUSET,
144-
PGC_S_SESSION,
145-
GUC_ACTION_SAVE,
146-
true,
147-
0,
148-
false,
149-
);
150-
151-
guc_level
152-
}
153-
154-
unsafe fn reset_pgaudit(guc_level: i32) {
155-
AtEOXact_GUC(true, guc_level);
156-
}
157-
158-
#[cfg(any(feature = "pg14", feature = "pg15"))]
137+
#[cfg(pre_pg16)]
159138
pub(crate) fn check_copy_table_permission(
160139
p_stmt: &PgBox<PlannedStmt>,
161140
p_state: &PgBox<ParseState>,
@@ -198,3 +177,24 @@ pub(crate) fn check_copy_table_permission(
198177

199178
unsafe { reset_pgaudit(guc_level) };
200179
}
180+
181+
unsafe fn disable_pgaudit() -> i32 {
182+
let guc_level = NewGUCNestLevel();
183+
184+
set_config_option(
185+
"pgaudit.log".as_pg_cstr(),
186+
"none".as_pg_cstr(),
187+
PGC_SUSET,
188+
PGC_S_SESSION,
189+
GUC_ACTION_SAVE,
190+
true,
191+
0,
192+
false,
193+
);
194+
195+
guc_level
196+
}
197+
198+
unsafe fn reset_pgaudit(guc_level: i32) {
199+
AtEOXact_GUC(true, guc_level);
200+
}

0 commit comments

Comments
 (0)