|
| 1 | +# PgDD Advanced installation |
| 2 | + |
| 3 | +This page covers installing PgDD from source locally, and the Docker build |
| 4 | +method based on [ZomboDB's build system](https://github.com/zombodb/zombodb) |
| 5 | +used to create the binaries. |
| 6 | + |
| 7 | + |
| 8 | +## Install `pgdd` from source |
| 9 | + |
| 10 | + |
| 11 | +One way to install `pgdd` is to install from source by cloning this repository. |
| 12 | + |
| 13 | +### Prereqs |
| 14 | + |
| 15 | +Pgx and its dependencies are the main prereq for PgDD. |
| 16 | +Install Prereqs and ensure PostgreSQL dev tools are installed. |
| 17 | + |
| 18 | +> See the [Cargo PGX](https://github.com/zombodb/pgx/tree/master/cargo-pgx) |
| 19 | +documentation for more information on using pgx. |
| 20 | + |
| 21 | + |
| 22 | +```bash |
| 23 | +sudo apt install postgresql-server-dev-all libreadline-dev zlib1g-dev curl \ |
| 24 | + libssl-dev llvm-dev libclang-dev clang \ |
| 25 | + graphviz |
| 26 | +``` |
| 27 | + |
| 28 | +[Install Rust](https://www.rust-lang.org/tools/install) and Pgx. |
| 29 | + |
| 30 | +```bash |
| 31 | +curl https://sh.rustup.rs -sSf | sh -s -- -y |
| 32 | +source $HOME/.cargo/env |
| 33 | +``` |
| 34 | + |
| 35 | +Install `cargo-pgx` regularly (see dev steps below for non-standard install). |
| 36 | + |
| 37 | + |
| 38 | +```bash |
| 39 | +cargo install cargo-pgx |
| 40 | +``` |
| 41 | + |
| 42 | + |
| 43 | +Install `cargo-deb` used for packaging binaries. |
| 44 | + |
| 45 | +```bash |
| 46 | +cargo install cargo-deb |
| 47 | +``` |
| 48 | + |
| 49 | + |
| 50 | +Initialize pgx. Need to run this after install AND occasionally to get updates |
| 51 | +to Postgres versions or glibc updates. Not typically required to follow pgx |
| 52 | +developments. |
| 53 | + |
| 54 | + |
| 55 | +```bash |
| 56 | +cargo pgx init |
| 57 | +``` |
| 58 | + |
| 59 | + |
| 60 | +### Clone PgDD repo |
| 61 | + |
| 62 | +```bash |
| 63 | +mkdir ~/git |
| 64 | +cd ~/git |
| 65 | +git clone https://github.com/rustprooflabs/pgdd.git |
| 66 | +cd ~/git/pgdd |
| 67 | +``` |
| 68 | + |
| 69 | +### Test deployment |
| 70 | + |
| 71 | +Specify version, `pg10` through `pg13` are currently supported. This command will |
| 72 | +start a test instance of Postgres on port `28812`. Using a different version |
| 73 | +changes the last two digits of the port! |
| 74 | + |
| 75 | + |
| 76 | +```bash |
| 77 | +cargo pgx run pg13 |
| 78 | +``` |
| 79 | + |
| 80 | +Example output. |
| 81 | + |
| 82 | +```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 |
| 87 | + |
| 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 |
| 94 | + Discovering SQL entities |
| 95 | + 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 | + 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` |
| 102 | + Finished installing pgdd |
| 103 | + Starting Postgres v13 on port 28813 |
| 104 | + Re-using existing database pgdd |
| 105 | +``` |
| 106 | + |
| 107 | +In the test instance of psql, create the extension in database. |
| 108 | + |
| 109 | +```bash |
| 110 | +CREATE EXTENSION pgdd; |
| 111 | +``` |
| 112 | + |
| 113 | + |
| 114 | +## Build binary packages |
| 115 | + |
| 116 | +Debian/Ubuntu Bionic binaries are available for 0.4.0 |
| 117 | +(first [pgx](https://github.com/zombodb/pgx) version) |
| 118 | +and later. More distributions will likely have binaries available in the future. |
| 119 | + |
| 120 | + |
| 121 | +```bash |
| 122 | +cd build/ |
| 123 | +time bash ./build.sh |
| 124 | +``` |
| 125 | + |
| 126 | +Tagged versions will be attached to their [releases](https://github.com/rustprooflabs/pgdd/releases). |
| 127 | + |
| 128 | +During development some versions may be copied to the `./standalone/` directory. |
| 129 | + |
| 130 | +```bash |
| 131 | +cp ./target/artifacts/* ./standalone/ |
| 132 | +``` |
| 133 | + |
| 134 | +## Pgx Generate graphviz |
| 135 | + |
| 136 | +```bash |
| 137 | +cargo pgx schema -d |
| 138 | +dot -Goverlap=prism -Gspline=ortho -Tjpg extension.dot > extension.jpg |
| 139 | +``` |
| 140 | + |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | +## Non-standard dev |
| 145 | + |
| 146 | +When working against Pgx installed from a non-tagged branch, install pgx using: |
| 147 | + |
| 148 | +```bash |
| 149 | +cargo install --force --git "https://github.com/zombodb/pgx" \ |
| 150 | + --branch "develop" \ |
| 151 | + "cargo-pgx" |
| 152 | +``` |
| 153 | + |
| 154 | +Changes to `Cargo.toml` required in `[lib]` and `[dependencies]` sections. |
| 155 | + |
| 156 | + |
| 157 | +```toml |
| 158 | +[lib] |
| 159 | +# rlib added to build against repo instead of crate (I think) |
| 160 | +crate-type = ["cdylib", "rlib"] |
| 161 | +#crate-type = ["cdylib"] |
| 162 | +``` |
| 163 | + |
| 164 | + |
| 165 | +```toml |
| 166 | +[dependencies] |
| 167 | + |
| 168 | +pgx = { git = "https://github.com/zombodb/pgx", branch = "oh-no-type-resolution" } |
| 169 | +pgx-macros = { git = "https://github.com/zombodb/pgx", branch = "develop" } |
| 170 | +#pgx = "0.1.21" |
| 171 | +#pgx-macros = "0.1.21" |
| 172 | + |
| 173 | +# Won't be needed in final version (hopefully!) |
| 174 | +pgx-utils = { git = "https://github.com/zombodb/pgx", branch = "develop" } |
| 175 | + |
| 176 | +[dev-dependencies] |
| 177 | +pgx-tests = { git = "https://github.com/zombodb/pgx", branch = "develop" } |
| 178 | +#pgx-tests = "0.1.21" |
| 179 | +``` |
| 180 | + |
| 181 | + |
| 182 | + |
| 183 | +The following command can be used to force pgx to overwrite the configs it needs to |
| 184 | +for various dev related changes. |
| 185 | + |
| 186 | + |
| 187 | +```bash |
| 188 | +cargo pgx schema -f |
| 189 | +``` |
| 190 | + |
| 191 | +Another option to try. |
| 192 | + |
| 193 | +```bash |
| 194 | +cargo clean |
| 195 | +``` |
| 196 | + |
| 197 | + |
| 198 | +## Non-standard In Docker |
| 199 | + |
| 200 | +If testing this extension against non-standard pgx install, update the |
| 201 | +Dockerfile to install from the specific branch. |
| 202 | + |
| 203 | +Change |
| 204 | + |
| 205 | +```bash |
| 206 | +RUN /bin/bash rustup.sh -y \ |
| 207 | + && cargo install cargo-pgx |
| 208 | +``` |
| 209 | + |
| 210 | +To |
| 211 | + |
| 212 | +```bash |
| 213 | +RUN /bin/bash rustup.sh -y \ |
| 214 | + && cargo install --force --git "https://github.com/zombodb/pgx" \ |
| 215 | + --branch "develop" \ |
| 216 | + "cargo-pgx" |
| 217 | +``` |
| 218 | + |
0 commit comments