Skip to content

Commit 62c885d

Browse files
Merge pull request #31 from rustprooflabs/dev
Partitions, database view, etc.
2 parents b0ddc06 + 0403d66 commit 62c885d

20 files changed

+529
-159
lines changed

.cargo/config

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
# Auto-generated by pgx. You may edit this, or delete it to have a new one created.
22

33
[target.x86_64-unknown-linux-gnu]
4-
linker = "./.cargo/pgx-linker-script.sh"
4+
linker = ".cargo/pgx-linker-script.sh"
55

66
[target.aarch64-unknown-linux-gnu]
7-
linker = "./.cargo/pgx-linker-script.sh"
7+
linker = ".cargo/pgx-linker-script.sh"
8+
9+
[target.x86_64-unknown-linux-musl]
10+
linker = ".cargo/pgx-linker-script.sh"
11+
12+
[target.aarch64-unknown-linux-musl]
13+
linker = ".cargo/pgx-linker-script.sh"
814

915
[target.x86_64-apple-darwin]
10-
linker = "./.cargo/pgx-linker-script.sh"
16+
linker = ".cargo/pgx-linker-script.sh"
1117

1218
[target.aarch64-apple-darwin]
13-
linker = "./.cargo/pgx-linker-script.sh"
19+
linker = ".cargo/pgx-linker-script.sh"
1420

1521
[target.x86_64-unknown-freebsd]
16-
linker = "./.cargo/pgx-linker-script.sh"
22+
linker = ".cargo/pgx-linker-script.sh"

ADVANCED-INSTALL.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,33 +74,34 @@ changes the last two digits of the port!
7474

7575

7676
```bash
77-
cargo pgx run pg13
77+
cargo pgx run pg14
7878
```
7979

80-
Example output.
80+
The output starts with something similar to:
8181

8282
```bash
83-
Stopping Postgres v13
84-
building extension with features `pg13`
85-
"cargo" "build" "--features" "pg13" "--no-default-features"
86-
Finished dev [unoptimized + debuginfo] target(s) in 0.05s
83+
building extension with features `pg14`
84+
"cargo" "build" "--lib" "--features" "pg14" "--no-default-features"
85+
Updating crates.io index
86+
```
87+
8788

88-
installing extension
89-
Copying control file to `/home/username/.pgx/13.4/pgx-install/share/postgresql/extension/pgdd.control`
90-
Copying shared library to `/home/username/.pgx/13.4/pgx-install/lib/postgresql/pgdd.so`
91-
Building SQL generator with features `pg13`
92-
"cargo" "build" "--bin" "sql-generator" "--features" "pg13" "--no-default-features"
93-
Finished dev [unoptimized + debuginfo] target(s) in 0.05s
89+
```bash
90+
Copying control file to `/home/username/.pgx/14.0/pgx-install/share/postgresql/extension/pgdd.control`
91+
Copying shared library to `/home/username/.pgx/14.0/pgx-install/lib/postgresql/pgdd.so`
92+
Building SQL generator with features `pg14`
93+
"cargo" "build" "--bin" "sql-generator" "--features" "pg14" "--no-default-features"
94+
Compiling pgdd v0.4.0 (/home/username/git/pgdd)
95+
Finished dev [unoptimized + debuginfo] target(s) in 13.84s
9496
Discovering SQL entities
9597
Discovered 9 SQL entities: 0 schemas (0 unique), 6 functions, 0 types, 0 enums, 3 sqls, 0 ords, 0 hashes
96-
running SQL generator with features `pg13`
97-
"cargo" "run" "--bin" "sql-generator" "--features" "pg13" "--no-default-features" "--" "--sql" "/home/username/.pgx/13.4/pgx-install/share/postgresql/extension/pgdd--0.4.0-dev.sql"
98+
running SQL generator with features `pg14`
99+
"cargo" "run" "--bin" "sql-generator" "--features" "pg14" "--no-default-features" "--" "--sql" "/home/username/.pgx/14.0/pgx-install/share/postgresql/extension/pgdd--0.4.1-dev.sql"
98100
Finished dev [unoptimized + debuginfo] target(s) in 0.06s
99-
Running `target/debug/sql-generator --sql /home/username/.pgx/13.4/pgx-install/share/postgresql/extension/pgdd--0.4.0-dev.sql`
100-
Copying extension schema file to `/home/username/.pgx/13.4/pgx-install/share/postgresql/extension/pgdd--0.3.1--0.4.0-dev.sql`
101-
Copying extension schema file to `/home/username/.pgx/13.4/pgx-install/share/postgresql/extension/pgdd--0.3--0.3.1.sql`
101+
Running `target/debug/sql-generator --sql /home/username/.pgx/14.0/pgx-install/share/postgresql/extension/pgdd--0.4.1-dev.sql`
102+
Copying extension schema file to `/home/username/.pgx/14.0/pgx-install/share/postgresql/extension/pgdd--0.4.1-dev.sql`
102103
Finished installing pgdd
103-
Starting Postgres v13 on port 28813
104+
Starting Postgres v14 on port 28814
104105
Re-using existing database pgdd
105106
```
106107

@@ -110,6 +111,8 @@ In the test instance of psql, create the extension in database.
110111
CREATE EXTENSION pgdd;
111112
```
112113

114+
> Note: When you see "Re-using existing database pgdd" your previous installed version of `pgdd` will be available. To ensure you are working with the latest version of the `pgdd` extension you must drop/create the extension, quit the psql shell, and re-run the `cargo pgx run` command.
115+
113116

114117
## Build binary packages
115118

@@ -135,10 +138,10 @@ cp ./target/artifacts/* ./standalone/
135138

136139
```bash
137140
cargo pgx schema -d
138-
dot -Goverlap=prism -Gspline=ortho -Tjpg extension.dot > extension.jpg
141+
dot -Goverlap=prism -Gspline=ortho -Tjpg extension.dot > pgdd.jpg
139142
```
140143

141-
![pgx dependencies for pgdd v0.4.0](pgdd--0.4.0.jpg)
144+
![pgx dependencies for pgdd](pgdd.jpg)
142145

143146

144147
## Non-standard dev

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pgdd"
3-
version = "0.4.0"
3+
version = "0.4.1-dev"
44
edition = "2018"
55
description = "In-database (PostgreSQL) data dictionary providing database introspection via standard SQL query syntax."
66

@@ -20,15 +20,15 @@ pg_test = []
2020

2121
#pgx = { git = "https://github.com/zombodb/pgx", branch = "develop" }
2222
#pgx-macros = { git = "https://github.com/zombodb/pgx", branch = "develop" }
23-
pgx = "0.2.5"
24-
pgx-macros = "0.2.5"
23+
pgx = "0.3.3"
24+
pgx-macros = "0.3.3"
2525

2626
#pgx-utils = { git = "https://github.com/zombodb/pgx", branch = "develop" }
27-
pgx-utils = "0.2.5"
27+
pgx-utils = "0.3.3"
2828

2929
[dev-dependencies]
3030
#pgx-tests = { git = "https://github.com/zombodb/pgx", branch = "develop" }
31-
pgx-tests = "0.2.5"
31+
pgx-tests = "0.3.3"
3232

3333

3434
[profile.dev]

README.md

Lines changed: 96 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,6 @@ The extension is built on the Rust [pgx framework](https://github.com/zombodb/pg
1212
PgDD has been tested to work for PostgreSQL 10 through 14.
1313

1414

15-
## Upgrading from <= v0.3
16-
17-
Version 0.4.0 was a complete rewrite of the PgDD extension from a raw-SQL
18-
extension to using the [pgx framework](https://github.com/zombodb/pgx).
19-
20-
21-
22-
Upgrading from Raw SQL version of PgDD (v0.3) to the pgx version (v0.4.0) is done with `DROP EXTENSION pgdd; CREATE EXTENSION pgdd;`
23-
Care has been taken to provide a smooth upgrade experience but
24-
**do not install the upgrade without testing the process on a test server!**
25-
26-
If custom attributes were stored in the `dd` tables you will need to use
27-
`pg_dump` to export the data and reload after recreating the extension
28-
with pgx. If any of the three (3) queries below return a count > 0
29-
this applies to you.
30-
31-
32-
```sql
33-
SELECT COUNT(*)
34-
FROM dd.meta_table
35-
WHERE s_name <> 'dd';
36-
SELECT COUNT(*)
37-
FROM dd.meta_column
38-
WHERE s_name <> 'dd';
39-
SELECT COUNT(*)
40-
FROM dd.meta_schema
41-
WHERE s_name <> 'dd';
42-
```
43-
44-
45-
46-
The last raw SQL version is still available to [download](https://raw.githubusercontent.com/rustprooflabs/pgdd/main/standalone/pgdd_v0_3.sql). This version is no longer maintained and may or may not
47-
work on future Postgres versions.
48-
49-
5015
## Install from binary
5116

5217
Binaries are available for Ubuntu 20.04 (focal) and Ubuntu 21.04 (hirsute).
@@ -209,6 +174,55 @@ SELECT s_name, f_name, argument_data_types, result_data_types
209174
;
210175
```
211176

177+
### Partitioned tables
178+
179+
There are two views, ``dd.partition_parents`` and ``dd.partition_children`` to provide
180+
partition-focused details. Will display partitions for both
181+
declarative partitions and inheritance based partitions
182+
183+
184+
185+
With the test data in this project for declarative partitions.
186+
187+
188+
```sql
189+
SELECT *
190+
FROM dd.partition_parents
191+
WHERE s_name = 'pgdd_test'
192+
;
193+
```
194+
195+
```
196+
┌───────┬───────────┬────────┬────────────────┬────────────┬────────────┬─────────────┬────────────────────┬──────┬────────────────────┬───────────────────────────┬────────────────────┐
197+
│ oid │ s_name │ t_name │ partition_type │ partitions │ size_bytes │ size_pretty │ size_per_partition │ rows │ rows_per_partition │ partitions_never_analyzed │ partitions_no_data │
198+
╞═══════╪═══════════╪════════╪════════════════╪════════════╪════════════╪═════════════╪════════════════════╪══════╪════════════════════╪═══════════════════════════╪════════════════════╡
199+
│ 25090 │ pgdd_test │ parent │ declarative │ 3 │ 40960 │ 40 kB │ 13 kB │ 15 │ 5 │ 0 │ 1 │
200+
└───────┴───────────┴────────┴────────────────┴────────────┴────────────┴─────────────┴────────────────────┴──────┴────────────────────┴───────────────────────────┴────────────────────┘
201+
```
202+
203+
Details for each child partition, including calculated percentages of the single
204+
partition against the totals for the parent partition.
205+
206+
207+
208+
```sql
209+
SELECT *
210+
FROM dd.partition_children
211+
WHERE s_name = 'pgdd_test'
212+
;
213+
```
214+
215+
```
216+
┌───────┬───────────┬─────────────┬────────────┬──────────────────┬──────┬────────────┬─────────────┬───────────────────┬───────────────┬───────────────────────────┬────────────────────────────┐
217+
│ oid │ s_name │ t_name │ parent_oid │ parent_name │ rows │ size_bytes │ size_pretty │ size_plus_indexes │ bytes_per_row │ percent_of_partition_rows │ percent_of_partition_bytes │
218+
╞═══════╪═══════════╪═════════════╪════════════╪══════════════════╪══════╪════════════╪═════════════╪═══════════════════╪═══════════════╪═══════════════════════════╪════════════════════════════╡
219+
│ 25095 │ pgdd_test │ child_0_10 │ 25090 │ pgdd_test.parent │ 9 │ 16384 │ 16 kB │ 32 kB │ 1820 │ 0.6000 │ 0.4000 │
220+
│ 25109 │ pgdd_test │ child_20_30 │ 25090 │ pgdd_test.parent │ 0 │ 8192 │ 8192 bytes │ 16 kB │ ¤ │ 0.0000 │ 0.2000 │
221+
│ 25102 │ pgdd_test │ child_10_20 │ 25090 │ pgdd_test.parent │ 6 │ 16384 │ 16 kB │ 32 kB │ 2731 │ 0.4000 │ 0.4000 │
222+
└───────┴───────────┴─────────────┴────────────┴──────────────────┴──────┴────────────┴─────────────┴───────────────────┴───────────────┴───────────────────────────┴────────────────────────────┘
223+
```
224+
225+
212226

213227

214228

@@ -253,6 +267,46 @@ GRANT dd_readwrite TO <your_login_user>;
253267

254268

255269

270+
## Upgrade extension
271+
272+
Version 0.4.0 was a complete rewrite of the PgDD extension from a raw-SQL
273+
extension to using the [pgx framework](https://github.com/zombodb/pgx).
274+
275+
276+
Upgrading versions currently requires `DROP EXTENSION pgdd; CREATE EXTENSION pgdd;`
277+
to recreate the extension.
278+
This is unlikely to change until [pgx #121 is resolved](https://github.com/zombodb/pgx/issues/121).
279+
280+
281+
282+
If custom attributes were stored in the `dd` tables you will need to use
283+
`pg_dump` to export the data and reload after recreating the extension
284+
with pgx. If any of the three (3) queries below return a count > 0
285+
this applies to you.
286+
287+
288+
```sql
289+
SELECT COUNT(*)
290+
FROM dd.meta_table
291+
WHERE s_name <> 'dd';
292+
SELECT COUNT(*)
293+
FROM dd.meta_column
294+
WHERE s_name <> 'dd';
295+
SELECT COUNT(*)
296+
FROM dd.meta_schema
297+
WHERE s_name <> 'dd';
298+
```
299+
300+
301+
302+
The last raw SQL version (v0.3) is available to [download](https://raw.githubusercontent.com/rustprooflabs/pgdd/main/standalone/pgdd_v0_3.sql). This version is no longer maintained and may or may not
303+
work on future Postgres versions.
304+
305+
306+
307+
----
308+
309+
256310
## PgDD UI
257311

258312
The [PgDD UI](https://github.com/rustprooflabs/pgdd-ui) project provides
@@ -265,6 +319,8 @@ PgDD versioning must conform to
265319
[PEP 440](https://www.python.org/dev/peps/pep-0440/).
266320

267321

322+
----
323+
268324
## Caveats
269325

270326
End user caveats:
@@ -273,6 +329,10 @@ End user caveats:
273329

274330
Extension developer caveats:
275331

276-
* DDL changes made in `src/lib.rs` need to be in version-to-version upgrade (e.g. ``sql/pgdd-0.3.1--0.4.0.sql``)
332+
* DDL changes made in `src/lib.rs` need to be in version-to-version upgrade (e.g. ``sql/pgdd-0.3.1--0.4.0.sql``). This trick is not being used due to
333+
[pgx #121](https://github.com/zombodb/pgx/issues/121). The Pgx functionality is exposed
334+
via functions, and the functions are the core problem here.
335+
336+
277337

278338

build/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ BASE=$(dirname `pwd`)
2121
VERSION=$(cat $BASE/pgdd.control | grep default_version | cut -f2 -d\')
2222
LOGDIR=${BASE}/target/logs
2323
ARTIFACTDIR=${BASE}/target/artifacts
24-
PGXVERSION=0.2.5
24+
PGXVERSION=0.3.3
2525

2626
PG_VERS=("pg10" "pg11" "pg12" "pg13" "pg14")
2727
#PG_VERS=("pg14")

build/docker/pgdd-ubuntu-hirsute/Dockerfile renamed to build/docker/pgdd-ubuntu-impish/Dockerfile

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:hirsute
1+
FROM ubuntu:impish
22

33
LABEL maintainer="PgDD Project - https://github.com/rustprooflabs/pgdd"
44

@@ -12,22 +12,23 @@ RUN useradd -m ${USER} --uid=${UID}
1212

1313
ARG DEBIAN_FRONTEND=noninteractive
1414
RUN apt-get update && apt-get upgrade -y && apt-get install -y make wget curl gnupg git
15-
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ focal-pgdg main" >> /etc/apt/sources.list.d/pgdg.list \
16-
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
17-
RUN apt-get update && apt-get upgrade -y
18-
RUN apt-get install -y \
19-
clang-12 llvm-12 clang libz-dev strace pkg-config \
15+
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ impish-pgdg main" >> /etc/apt/sources.list.d/pgdg.list \
16+
&& curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null
17+
RUN apt-get update && apt-get upgrade -y --fix-missing
18+
RUN apt-get install -y --fix-missing \
19+
clang-13 llvm-13 clang libz-dev strace pkg-config \
2020
libxml2 libxml2-dev libreadline8 libreadline-dev \
2121
flex bison libbison-dev build-essential \
2222
zlib1g-dev libxslt-dev libssl-dev libxml2-utils xsltproc libgss-dev \
23-
libldap2-dev libkrb5-dev gettext tcl-tclreadline tcl-dev libperl-dev \
23+
libldap-dev libkrb5-dev gettext tcl-tclreadline tcl-dev libperl-dev \
2424
libpython3-dev libprotobuf-c-dev libprotobuf-dev gcc \
2525
ruby ruby-dev rubygems \
2626
postgresql-server-dev-10 \
2727
postgresql-server-dev-11 \
2828
postgresql-server-dev-12 \
2929
postgresql-server-dev-13 \
30-
postgresql-server-dev-14
30+
postgresql-server-dev-14 \
31+
&& apt autoremove -y
3132

3233

3334
RUN gem install --no-document fpm
@@ -41,10 +42,6 @@ ENV PATH="/home/${USER}/.cargo/bin:${PATH}"
4142

4243
RUN /bin/bash rustup.sh -y \
4344
&& cargo install cargo-pgx --version ${PGXVERSION}
44-
#RUN /bin/bash rustup.sh -y \
45-
# && cargo install --force --git "https://github.com/zombodb/pgx" \
46-
# --branch "develop" \
47-
# "cargo-pgx"
4845

4946

5047
RUN mkdir -p /home/${USER}/.pgx/data-10 \

pgdd--0.4.0.jpg

-85.3 KB
Binary file not shown.

pgdd.control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
comment = 'An in-database data dictionary providing database introspection via standard SQL query syntax. Developed using pgx (https://github.com/zombodb/pgx).'
2-
default_version = '0.4.0'
2+
default_version = '0.4.1-dev'
33
module_pathname = '$libdir/pgdd'
44
relocatable = false
55
schema = dd

pgdd.jpg

106 KB
Loading

0 commit comments

Comments
 (0)