Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres 16beta1 Support #1169

Merged
merged 22 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f260928
Get `cargo-pgrx` capable of downloading/installing v16beta1. `build.…
eeeebbbbrrrr Jun 13, 2023
8533092
pg16 bindings generate and repo passes `cargo check --all` without er…
eeeebbbbrrrr Jun 13, 2023
79a8410
Fix all test failures for pg16
eeeebbbbrrrr Jun 15, 2023
1a9214f
trying to get postgres 16 into CI.
eeeebbbbrrrr Jun 15, 2023
37100fe
Sets up development vs. release versionf of PostgresSQL
BradyBonnette Jun 15, 2023
d20102c
Remove incorrect apt installs for Postgres
BradyBonnette Jun 15, 2023
9499b2b
Disable crossbuilds for now
BradyBonnette Jun 15, 2023
45a1310
I do not have autocomplete to save me
BradyBonnette Jun 15, 2023
7772560
Find out exactly what is installable
BradyBonnette Jun 15, 2023
588dec3
Add repository the correct way
BradyBonnette Jun 15, 2023
557cf01
Add keys
BradyBonnette Jun 15, 2023
631e45b
Address code review issues raised by @workingjubilee
eeeebbbbrrrr Jun 16, 2023
03a926d
Merge remote-tracking branch 'origin/pg16-support' into pg16-support
eeeebbbbrrrr Jun 16, 2023
6561325
Add regular pgdg repo
BradyBonnette Jun 16, 2023
dbcd877
Adds pg16 support to pgrx init
BradyBonnette Jun 16, 2023
64918c4
more pg16 changes
eeeebbbbrrrr Jun 16, 2023
df81574
Merge remote-tracking branch 'origin/pg16-support' into pg16-support
eeeebbbbrrrr Jun 16, 2023
5be300f
re-add cross-compile
BradyBonnette Jun 16, 2023
edd7071
trying out --fix-missing
BradyBonnette Jun 16, 2023
3d56009
Update apt
BradyBonnette Jun 16, 2023
7544296
Forgot sudo
BradyBonnette Jun 16, 2023
bd68ff0
Remove useless apt search
BradyBonnette Jun 16, 2023
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
66 changes: 43 additions & 23 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

strategy:
matrix:
version: ["postgres-11", "postgres-12", "postgres-13", "postgres-14", "postgres-15"]
version: ["postgres-11", "postgres-12", "postgres-13", "postgres-14", "postgres-15", "postgres-16"]
os: ["ubuntu-20.04"]

steps:
Expand Down Expand Up @@ -59,13 +59,6 @@ jobs:
sudo apt remove -y '^postgres.*' '^libpq.*'
echo ""

echo "----- Set up PostgreSQL Apt repository -----"
sudo apt-get install -y wget gnupg
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update -y -qq --fix-missing
echo ""

echo "----- Install system dependencies and PostgreSQL version $PG_VER -----"
sudo apt-get install -y \
clang-10 \
Expand All @@ -78,23 +71,15 @@ jobs:
zlib1g-dev \
strace \
libssl-dev \
pkg-config \
postgresql-$PG_VER \
postgresql-server-dev-$PG_VER

echo "----- Set up cross compilation -----"
sudo apt-get install -y crossbuild-essential-arm64
rustup target add aarch64-unknown-linux-gnu

echo 'CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc' >> $GITHUB_ENV
# TODO: not all of these should be needed, but for now it's likely fine.
echo 'BINDGEN_EXTRA_CLANG_ARGS_aarch64-unknown-linux-gnu=-target aarch64-unknown-linux-gnu -isystem /usr/aarch64-linux-gnu/include/ -ccc-gcc-name aarch64-linux-gnu-gcc' >> $GITHUB_ENV
pkg-config

echo ""
# echo "----- Set up cross compilation -----"
# sudo apt-get install -y crossbuild-essential-arm64
# rustup target add aarch64-unknown-linux-gnu

echo "----- Set up Postgres permissions -----"
sudo chmod a+rwx `/usr/lib/postgresql/$PG_VER/bin/pg_config --pkglibdir` `/usr/lib/postgresql/$PG_VER/bin/pg_config --sharedir`/extension /var/run/postgresql/
echo ""
# echo 'CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc' >> $GITHUB_ENV
# # TODO: not all of these should be needed, but for now it's likely fine.
# echo 'BINDGEN_EXTRA_CLANG_ARGS_aarch64-unknown-linux-gnu=-target aarch64-unknown-linux-gnu -isystem /usr/aarch64-linux-gnu/include/ -ccc-gcc-name aarch64-linux-gnu-gcc' >> $GITHUB_ENV

echo "----- Print env -----"
env
Expand All @@ -104,6 +89,41 @@ jobs:
cargo --version
echo ""

- name: Install release version of PostgreSQL
if: matrix.version != 'postgres-16'
run: |
echo "----- Set up PostgreSQL Apt repository -----"
sudo apt-get install -y wget gnupg
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update -y -qq --fix-missing
echo ""

sudo apt-get install -y \
postgresql-$PG_VER \
postgresql-server-dev-$PG_VER


- name: Install develoment version of PostgreSQL
if: matrix.version == 'postgres-16'
run: |
echo "----- Set up PostgreSQL Apt repository -----"
sudo apt-get install -y wget gnupg
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7FCC7D46ACCC4CF8
sudo add-apt-repository "deb https://apt.postgresql.org/pub/repos/apt/ $(lsb_release -s -c)-pgdg-snapshot main 16"
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update -y -qq --fix-missing
echo ""

sudo apt search postgresql

sudo apt-get install -y \
postgresql-$PG_VER \
postgresql-server-dev-$PG_VER

- name: Set up PostgreSQL permissions
run: sudo chmod a+rwx `/usr/lib/postgresql/$PG_VER/bin/pg_config --pkglibdir` `/usr/lib/postgresql/$PG_VER/bin/pg_config --sharedir`/extension /var/run/postgresql/

- name: Cache cargo registry
uses: actions/cache@v3
continue-on-error: false
Expand Down
39 changes: 12 additions & 27 deletions cargo-pgrx/src/command/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use eyre::{eyre, WrapErr};
use owo_colors::OwoColorize;
use pgrx_pg_config::{
get_c_locale_flags, prefix_path, PgConfig, PgConfigSelector, Pgrx, PgrxHomeError,
SUPPORTED_MAJOR_VERSIONS,
};
use rayon::prelude::*;

Expand Down Expand Up @@ -93,7 +92,7 @@ impl CommandExecute for Init {

if versions.is_empty() {
// no arguments specified, so we'll just install our defaults
init_pgrx(&pgrx_default(SUPPORTED_MAJOR_VERSIONS)?, &self)
init_pgrx(&pgrx_default()?, &self)
} else {
// user specified arguments, so we'll only install those versions of Postgres
let mut default_pgrx = None;
Expand All @@ -102,7 +101,7 @@ impl CommandExecute for Init {
for (pgver, pg_config_path) in versions {
let config = if pg_config_path == "download" {
if default_pgrx.is_none() {
default_pgrx = Some(pgrx_default(SUPPORTED_MAJOR_VERSIONS)?);
default_pgrx = Some(pgrx_default()?);
}
default_pgrx
.as_ref()
Expand Down Expand Up @@ -174,8 +173,7 @@ pub(crate) fn init_pgrx(pgrx: &Pgrx, init: &Init) -> eyre::Result<()> {

output_configs.sort_by(|a, b| {
a.major_version()
.ok()
.expect("could not determine major version")
.unwrap_or_else(|e| panic!("{e}: could not determine major version for: `{:?}`", a))
.cmp(&b.major_version().ok().expect("could not determine major version"))
});
for pg_config in output_configs.iter() {
Expand Down Expand Up @@ -205,10 +203,9 @@ fn download_postgres(
use crate::command::build_agent_for_url;

println!(
"{} Postgres v{}.{} from {}",
"{} Postgres v{} from {}",
" Downloading".bold().green(),
pg_config.major_version()?,
pg_config.minor_version()?,
pg_config.version()?,
pg_config.url().expect("no url"),
);
let url = pg_config.url().expect("no url for pg_config").as_str();
Expand All @@ -234,7 +231,7 @@ fn download_postgres(

fn untar(bytes: &[u8], pgrxdir: &PathBuf, pg_config: &PgConfig) -> eyre::Result<PathBuf> {
let mut pgdir = pgrxdir.clone();
pgdir.push(format!("{}.{}", pg_config.major_version()?, pg_config.minor_version()?));
pgdir.push(format!("{}", pg_config.version()?));
eeeebbbbrrrr marked this conversation as resolved.
Show resolved Hide resolved
if pgdir.exists() {
// delete everything at this path if it already exists
println!("{} {}", " Removing".bold().green(), pgdir.display());
Expand All @@ -243,10 +240,9 @@ fn untar(bytes: &[u8], pgrxdir: &PathBuf, pg_config: &PgConfig) -> eyre::Result<
std::fs::create_dir_all(&pgdir)?;

println!(
"{} Postgres v{}.{} to {}",
"{} Postgres v{} to {}",
" Untarring".bold().green(),
pg_config.major_version()?,
pg_config.minor_version()?,
pg_config.version()?,
pgdir.display()
);
let mut child = std::process::Command::new("tar")
Expand Down Expand Up @@ -274,12 +270,7 @@ fn untar(bytes: &[u8], pgrxdir: &PathBuf, pg_config: &PgConfig) -> eyre::Result<
}

fn configure_postgres(pg_config: &PgConfig, pgdir: &PathBuf, init: &Init) -> eyre::Result<()> {
println!(
"{} Postgres v{}.{}",
" Configuring".bold().green(),
pg_config.major_version()?,
pg_config.minor_version()?
);
println!("{} Postgres v{}", " Configuring".bold().green(), pg_config.version()?);
let mut configure_path = pgdir.clone();
configure_path.push("configure");
let mut command = std::process::Command::new(configure_path);
Expand Down Expand Up @@ -325,12 +316,7 @@ fn configure_postgres(pg_config: &PgConfig, pgdir: &PathBuf, init: &Init) -> eyr

fn make_postgres(pg_config: &PgConfig, pgdir: &PathBuf) -> eyre::Result<()> {
let num_cpus = 1.max(num_cpus::get() / 3);
println!(
"{} Postgres v{}.{}",
" Compiling".bold().green(),
pg_config.major_version()?,
pg_config.minor_version()?
);
println!("{} Postgres v{}", " Compiling".bold().green(), pg_config.version()?);
let mut command = std::process::Command::new("make");

command
Expand Down Expand Up @@ -366,10 +352,9 @@ fn make_postgres(pg_config: &PgConfig, pgdir: &PathBuf) -> eyre::Result<()> {

fn make_install_postgres(version: &PgConfig, pgdir: &PathBuf) -> eyre::Result<PgConfig> {
println!(
"{} Postgres v{}.{} to {}",
"{} Postgres v{} to {}",
" Installing".bold().green(),
version.major_version()?,
version.minor_version()?,
version.version()?,
get_pg_installdir(pgdir).display()
);
let mut command = std::process::Command::new("make");
Expand Down
39 changes: 21 additions & 18 deletions cargo-pgrx/src/command/version.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use pgrx_pg_config::{PgConfig, Pgrx};
use pgrx_pg_config::{PgConfig, Pgrx, SUPPORTED_VERSIONS};

pub(crate) fn pgrx_default(supported_major_versions: &[u16]) -> eyre::Result<Pgrx> {
pub(crate) fn pgrx_default() -> eyre::Result<Pgrx> {
let mut pgrx = Pgrx::default();
rss::PostgreSQLVersionRss::new(supported_major_versions)?

rss::PostgreSQLVersionRss::new(&SUPPORTED_VERSIONS())?
.into_iter()
.for_each(|version| pgrx.push(PgConfig::from(version)));

Expand All @@ -12,16 +13,17 @@ pub(crate) fn pgrx_default(supported_major_versions: &[u16]) -> eyre::Result<Pgr
mod rss {
use eyre::WrapErr;
use owo_colors::OwoColorize;
use pgrx_pg_config::PgVersion;
use pgrx_pg_config::{PgMinorVersion, PgVersion};
use serde_derive::Deserialize;
use std::collections::BTreeMap;
use url::Url;

use crate::command::build_agent_for_url;

pub(super) struct PostgreSQLVersionRss;

impl PostgreSQLVersionRss {
pub(super) fn new(supported_major_versions: &[u16]) -> eyre::Result<Vec<PgVersion>> {
pub(super) fn new(supported_verions: &[PgVersion]) -> eyre::Result<Vec<PgVersion>> {
eeeebbbbrrrr marked this conversation as resolved.
Show resolved Hide resolved
static VERSIONS_RSS_URL: &str = "https://www.postgresql.org/versions.rss";

let http_client = build_agent_for_url(VERSIONS_RSS_URL)?;
Expand All @@ -35,7 +37,10 @@ mod rss {
Err(e) => return Err(e.into()),
};

let mut versions = Vec::new();
let mut versions: BTreeMap<u16, PgVersion> = BTreeMap::from_iter(
supported_verions.iter().map(|pgver| (pgver.major, pgver.clone())),
eeeebbbbrrrr marked this conversation as resolved.
Show resolved Hide resolved
);

for item in rss.channel.item {
let title = item.title.trim();
let mut parts = title.split('.');
Expand All @@ -47,27 +52,25 @@ mod rss {
let major = major.unwrap().parse::<u16>().unwrap_or_default();
let minor = minor.unwrap().parse::<u16>().unwrap_or_default();

if supported_major_versions.contains(&major) {
versions.push(
PgVersion::new(
major,
minor,
Url::parse(
if let Some(known_pgver) = versions.get_mut(&major) {
if matches!(known_pgver.minor, PgMinorVersion::Latest) {
// fill in the latest minor version number and its url
known_pgver.minor = PgMinorVersion::Release(minor);
known_pgver.url = Some(Url::parse(
&format!("https://ftp.postgresql.org/pub/source/v{major}.{minor}/postgresql-{major}.{minor}.tar.bz2",
major = major, minor = minor)
).expect("invalid url")
),
)
)?);
}
}
}

println!(
"{} Postgres {}",
" Discovered".white().bold(),
versions.iter().map(|ver| format!("v{ver}")).collect::<Vec<_>>().join(", ")
" Discovered".white().bold(),
versions.iter().map(|ver| format!("v{}", ver.1)).collect::<Vec<_>>().join(", ")
);

Ok(versions)
Ok(versions.into_values().collect())
}
}

Expand Down
1 change: 1 addition & 0 deletions cargo-pgrx/src/templates/cargo_toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pg12 = ["pgrx/pg12", "pgrx-tests/pg12" ]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13" ]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14" ]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15" ]
pg16 = ["pgrx/pg16", "pgrx-tests/pg16" ]
pg_test = []

[dependencies]
Expand Down
1 change: 1 addition & 0 deletions nix/templates/default/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pg12 = ["pgrx/pg12", "pgrx-tests/pg12" ]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13" ]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14" ]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15" ]
pg16 = ["pgrx/pg16", "pgrx-tests/pg16" ]
pg_test = []

[dependencies]
Expand Down
1 change: 1 addition & 0 deletions pgrx-examples/aggregate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pg12 = ["pgrx/pg12", "pgrx-tests/pg12" ]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13" ]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14" ]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15" ]
pg16 = ["pgrx/pg16", "pgrx-tests/pg16" ]
pg_test = []
bob = []

Expand Down
1 change: 1 addition & 0 deletions pgrx-examples/arrays/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pg12 = ["pgrx/pg12", "pgrx-tests/pg12" ]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13" ]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14" ]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15" ]
pg16 = ["pgrx/pg16", "pgrx-tests/pg16" ]
pg_test = []

[dependencies]
Expand Down
1 change: 1 addition & 0 deletions pgrx-examples/bad_ideas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pg12 = ["pgrx/pg12", "pgrx-tests/pg12" ]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13" ]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14" ]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15" ]
pg16 = ["pgrx/pg16", "pgrx-tests/pg16" ]
pg_test = []

[dependencies]
Expand Down
1 change: 1 addition & 0 deletions pgrx-examples/bgworker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pg12 = ["pgrx/pg12", "pgrx-tests/pg12" ]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13" ]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14" ]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15" ]
pg16 = ["pgrx/pg16", "pgrx-tests/pg16" ]
pg_test = []

[dependencies]
Expand Down
1 change: 1 addition & 0 deletions pgrx-examples/bytea/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pg12 = ["pgrx/pg12", "pgrx-tests/pg12" ]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13" ]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14" ]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15" ]
pg16 = ["pgrx/pg16", "pgrx-tests/pg16" ]
pg_test = []

[dependencies]
Expand Down
1 change: 1 addition & 0 deletions pgrx-examples/composite_type/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pg12 = ["pgrx/pg12", "pgrx-tests/pg12" ]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13" ]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14" ]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15" ]
pg16 = ["pgrx/pg16", "pgrx-tests/pg16" ]
pg_test = []

[dependencies]
Expand Down
1 change: 1 addition & 0 deletions pgrx-examples/custom_libname/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pg12 = ["pgrx/pg12", "pgrx-tests/pg12" ]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13" ]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14" ]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15" ]
pg16 = ["pgrx/pg16", "pgrx-tests/pg16" ]
pg_test = []

[dependencies]
Expand Down
1 change: 1 addition & 0 deletions pgrx-examples/custom_sql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pg12 = ["pgrx/pg12", "pgrx-tests/pg12" ]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13" ]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14" ]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15" ]
pg16 = ["pgrx/pg16", "pgrx-tests/pg16" ]
pg_test = []

[dependencies]
Expand Down
1 change: 1 addition & 0 deletions pgrx-examples/custom_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pg12 = ["pgrx/pg12", "pgrx-tests/pg12" ]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13" ]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14" ]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15" ]
pg16 = ["pgrx/pg16", "pgrx-tests/pg16" ]
pg_test = []
no-schema-generation = [ "pgrx/no-schema-generation", "pgrx-tests/no-schema-generation" ]

Expand Down
1 change: 1 addition & 0 deletions pgrx-examples/datetime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pg12 = ["pgrx/pg12", "pgrx-tests/pg12" ]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13" ]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14" ]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15" ]
pg16 = ["pgrx/pg16", "pgrx-tests/pg16" ]
pg_test = []

[dependencies]
Expand Down
1 change: 1 addition & 0 deletions pgrx-examples/errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pg12 = ["pgrx/pg12", "pgrx-tests/pg12" ]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13" ]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14" ]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15" ]
pg16 = ["pgrx/pg16", "pgrx-tests/pg16" ]
pg_test = []

[dependencies]
Expand Down
Loading