diff --git a/.appveyor.yml b/.appveyor.yml index 4652b9e69..e463100f1 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,4 +1,4 @@ -image: Visual Studio 2019 +image: Visual Studio 2022 init: - set PATH=C:/Ruby%ruby_version%/bin;c:/Program Files/Git/cmd;c:/Windows/system32;C:/Windows/System32/WindowsPowerShell/v1.0;C:/Program Files/Mercurial @@ -7,8 +7,11 @@ install: - ps: | if ($env:RUBYDOWNLOAD -ne $null) { $(new-object net.webclient).DownloadFile("https://github.com/oneclick/rubyinstaller2/releases/download/rubyinstaller-head/rubyinstaller-head-$env:RUBYDOWNLOAD.exe", "$pwd/ruby-setup.exe") - cmd /c ruby-setup.exe /verysilent /dir=C:/Ruby$env:ruby_version + cmd /c ruby-setup.exe /currentuser /verysilent /dir=C:/Ruby$env:ruby_version } + - cmd: | + ridk enable + c:/msys64/usr/bin/bash -lc "pacman -S --noconfirm --needed ${MINGW_PACKAGE_PREFIX}-pkgconf ${MINGW_PACKAGE_PREFIX}-libyaml ${MINGW_PACKAGE_PREFIX}-gcc" - ruby --version - gem --version - gem install bundler --conservative @@ -18,19 +21,20 @@ install: { $(new-object net.webclient).DownloadFile('http://get.enterprisedb.com/postgresql/postgresql-' + $env:PGVERSION + '.exe', 'C:/postgresql-setup.exe') cmd /c "C:/postgresql-setup.exe" --mode unattended --extract-only 1 + + $env:PATH = 'C:/Program Files/PostgreSQL/' + $env:PGVER + '/bin;' + $env:PATH + $env:PATH = 'C:/Program Files (x86)/PostgreSQL/' + $env:PGVER + '/bin;' + $env:PATH } - $env:PATH = 'C:/Program Files/PostgreSQL/' + $env:PGVER + '/bin;' + $env:PATH - $env:PATH = 'C:/Program Files (x86)/PostgreSQL/' + $env:PGVER + '/bin;' + $env:PATH + - echo %PATH% + - pg_config build_script: - bundle exec rake -rdevkit compile --trace test_script: - bundle exec rake test PG_DEBUG=0 +on_failure: + - find -name mkmf.log | xargs cat environment: matrix: - ruby_version: "head" - RUBYDOWNLOAD: x86 - PGVERSION: 10.16-1-windows - PGVER: 10 - - ruby_version: "25" - PGVERSION: 9.3.25-1-windows - PGVER: 9.3 + RUBYDOWNLOAD: x64 + - ruby_version: "30-x64" diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..b3906e650 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,25 @@ +root = true + +[*] +indent_style = tab +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +max_line_length = 120 + +[{*.gemspec,rakelib/**.rb}] +indent_style = space +indent_size = 2 + +[*.def] +indent_style = space +indent_size = 2 + +[*.yml] +indent_style = space +indent_size = 2 + +[*.{md,rdoc}] +indent_style = space +indent_size = 4 diff --git a/.github/workflows/binary-gems.yml b/.github/workflows/binary-gems.yml index bbe4bd604..4088892b9 100644 --- a/.github/workflows/binary-gems.yml +++ b/.github/workflows/binary-gems.yml @@ -1,17 +1,39 @@ -name: Build and test binary gems +name: Binary gems -on: [push, pull_request] +on: + workflow_dispatch: + schedule: + - cron: "0 5 * * 3" # At 05:00 on Wednesday # https://crontab.guru/#0_5_*_*_3 + push: + branches: + - master + tags: + - "*.*.*" + pull_request: + types: [opened, synchronize] + branches: + - "*" +permissions: + contents: read jobs: - job_build_x64: - name: build + rcd_build: + name: Build runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - platform: "x64-mingw-ucrt" + - platform: "x64-mingw32" + - platform: "x86-mingw32" + - platform: "x86_64-linux" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: "3.0" + ruby-version: "3.3" - run: bundle install - name: Create a dummy cert to satisfy the build @@ -22,59 +44,153 @@ jobs: cp gem-public_cert.pem ~/.gem/gem-public_cert.pem - name: Build binary gem - run: bundle exec rake gem:windows:x64-mingw32 + run: bundle exec rake gem:native:${{ matrix.platform }} - name: Upload binary gem - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: - name: binary-gem + name: binary-gem-${{ matrix.platform }} path: pkg/*.gem job_test_binary: - name: Test on Windows - needs: job_build_x64 + name: Test + needs: rcd_build strategy: fail-fast: false matrix: include: - - ruby: "3.0" - PGVERSION: 14.0-1-windows-x64 - PGVER: "14" - - ruby: "2.5" - PGVERSION: 10.16-1-windows - PGVER: "10" - - runs-on: windows-latest + - os: windows-latest + ruby: "3.3" + platform: "x64-mingw-ucrt" + - os: windows-latest + ruby: "3.1.4-1" + platform: "x86-mingw32" + PGVERSION: 10.20-1-windows + - os: windows-latest + ruby: "2.7" + platform: "x64-mingw32" + PGVERSION: 16.6-1-windows-x64 + - os: ubuntu-latest + ruby: "3.2" + platform: "x86_64-linux" + + runs-on: ${{ matrix.os }} env: PGVERSION: ${{ matrix.PGVERSION }} - PGVER: ${{ matrix.PGVER }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Ruby - uses: ruby/setup-ruby@v1 + if: matrix.platform != 'x86-mingw32' + uses: ruby/setup-ruby-pkgs@v1 with: ruby-version: ${{ matrix.ruby }} + apt-get: "postgresql" # Ubuntu + brew: "postgresql" # macOS + mingw: "postgresql" # Windows mingw / mswin /ucrt + + - name: Set up 32 bit x86 Ruby + if: matrix.platform == 'x86-mingw32' + run: | + $(new-object net.webclient).DownloadFile("https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-${{ matrix.ruby }}/rubyinstaller-${{ matrix.ruby }}-x86.exe", "$pwd/ruby-setup.exe") + cmd /c ruby-setup.exe /currentuser /verysilent /dir=C:/Ruby-${{ matrix.ruby }} + echo "c:/ruby-${{ matrix.ruby }}/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + + c:/ruby-${{ matrix.ruby }}/bin/ridk enable + c:/msys64/usr/bin/bash -lc "pacman -S --noconfirm --needed make `${MINGW_PACKAGE_PREFIX}-pkgconf `${MINGW_PACKAGE_PREFIX}-libyaml `${MINGW_PACKAGE_PREFIX}-gcc `${MINGW_PACKAGE_PREFIX}-make" + echo "C:/msys64/$env:MSYSTEM_PREFIX/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - name: Download gem from build job - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: - name: binary-gem + name: binary-gem-${{ matrix.platform }} - - name: Download PostgreSQL + - name: Download PostgreSQL 32-bit + if: ${{ matrix.os == 'windows-latest' && matrix.PGVERSION }} run: | Add-Type -AssemblyName System.IO.Compression.FileSystem function Unzip { param([string]$zipfile, [string]$outpath) [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath) } - $(new-object net.webclient).DownloadFile("http://get.enterprisedb.com/postgresql/postgresql-$env:PGVERSION-binaries.zip", "postgresql-binaries.zip") Unzip "postgresql-binaries.zip" "." echo "$pwd/pgsql/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + + - name: set PGUSER + if: ${{ matrix.os == 'windows-latest' }} + run: | echo "PGUSER=$env:USERNAME" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append echo "PGPASSWORD=" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + - run: echo $env:PATH + - run: gem update --system 3.3.26 - run: bundle install - - run: gem install --local *.gem --verbose + - run: gem install --local pg-*${{ matrix.platform }}.gem --verbose + - name: Run specs + if: ${{ matrix.os != 'windows-latest' }} + run: ruby -rpg -S rspec -fd spec/**/*_spec.rb - name: Run specs - run: ruby -rpg -S rspec spec/**/*_spec.rb + if: ${{ matrix.os == 'windows-latest' }} + run: | + ridk enable + ruby -rpg -S rspec -fd spec/**/*_spec.rb + + - name: Print logs if job failed + if: ${{ failure() && matrix.os == 'windows-latest' }} + run: | + ridk enable + find "$(ruby -e"puts RbConfig::CONFIG[%q[libdir]]")" -name mkmf.log -print0 | xargs -0 cat + find -name setup.log -print0 | xargs -0 cat + + + job_binary_multiarch: + name: multiarch (${{matrix.platform}} on ${{matrix.from_image}} ${{matrix.image_platform}}) + needs: rcd_build + strategy: + fail-fast: false + matrix: + include: + - from_image: fedora:39 + image_platform: linux/x86_64 + gem_platform: x86_64-linux + dockerfile: centos + - from_image: alpine + image_platform: linux/x86_64 + gem_platform: x86_64-linux + dockerfile: alpine + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Download gem-${{ matrix.gem_platform }} + uses: actions/download-artifact@v4 + with: + name: binary-gem-${{ matrix.gem_platform }} + - name: Build image and Run tests + run: | + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + docker build --rm --platform ${{matrix.image_platform}} --build-arg from_image=${{matrix.from_image}} -t ruby-test -f spec/env/Dockerfile.${{matrix.dockerfile}} . + docker run --rm -t --network=host -v `pwd`:/build ruby-test + + job_binary_yugabyte: + name: yugabyte (${{matrix.gem_platform}} + needs: rcd_build + strategy: + fail-fast: false + matrix: + include: + - gem_platform: x86_64-linux + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Download gem-${{ matrix.gem_platform }} + uses: actions/download-artifact@v4 + with: + name: binary-gem-${{ matrix.gem_platform }} + - name: Build image and Run tests + run: | + sudo apt-get install -y docker-compose + cp -v pg-*.gem misc/yugabyte/ + cd misc/yugabyte + docker-compose up --abort-on-container-exit --exit-code-from pg diff --git a/.github/workflows/source-gem.yml b/.github/workflows/source-gem.yml index 539458aac..bc29b5e6f 100644 --- a/.github/workflows/source-gem.yml +++ b/.github/workflows/source-gem.yml @@ -1,29 +1,42 @@ -name: Build and test source gem - -on: [push, pull_request] +name: Source gem +on: + workflow_dispatch: + schedule: + - cron: "0 5 * * 3" # At 05:00 on Wednesday # https://crontab.guru/#0_5_*_*_3 + push: + branches: + - master + tags: + - "*.*.*" + pull_request: + types: [opened, synchronize] + branches: + - "*" +permissions: + contents: read jobs: job_build_gem: - name: build + name: Build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: "3.0" + ruby-version: "3.2" - name: Build source gem run: gem build pg.gemspec - name: Upload source gem - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: source-gem path: "*.gem" job_test_gem: - name: Test built gem + name: Test needs: job_build_gem strategy: fail-fast: false @@ -31,51 +44,57 @@ jobs: include: - os: windows ruby: "head" - PGVERSION: 14.0-1-windows-x64 - PGVER: "14" + PGVERSION: 17.0-1-windows-x64 + PGVER: "17" + - os: windows + ruby: "2.7" + PGVERSION: 10.20-1-windows-x64 + PGVER: "10" - os: windows - ruby: "2.5" - PGVERSION: 9.3.25-1-windows-x64 - PGVER: "9.3" + ruby: "mswin" + PGVERSION: 17.0-1-windows-x64 + PGVER: "17" - os: ubuntu ruby: "head" - PGVER: "14" + PGVER: "17" - os: ubuntu - ruby: "3.0" + ruby: "3.2" PGVER: "12" - os: ubuntu - ruby: "2.5" - PGVER: "9.3" + os_ver: "20.04" + ruby: "2.7" + PGVER: "10" - os: ubuntu ruby: "truffleruby" - PGVER: "13" + PGVER: "14" - os: ubuntu ruby: "truffleruby-head" - PGVER: "14" + PGVER: "17" - os: macos ruby: "head" - PGVERSION: 14.0-1-osx - PGVER: "14" + PGVERSION: 17.0-1-osx + PGVER: "17" - runs-on: ${{ matrix.os }}-latest + runs-on: ${{ matrix.os }}-${{ matrix.os_ver || 'latest' }} env: PGVERSION: ${{ matrix.PGVERSION }} PGVER: ${{ matrix.PGVER }} + MAKE: make -j2 V=1 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Ruby - uses: MSP-Greg/ruby-setup-ruby@win-ucrt + uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - name: Download gem from build job - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: name: source-gem - name: Install required packages Windows - if: matrix.os == 'windows' + if: matrix.os == 'windows' && matrix.ruby != 'mswin' shell: cmd run: ridk exec sh -c "pacman --sync --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-gcc" @@ -97,27 +116,31 @@ jobs: - name: Download PostgreSQL Ubuntu if: matrix.os == 'ubuntu' run: | - echo "deb http://apt.postgresql.org/pub/repos/apt/ focal-pgdg main $PGVER" | sudo tee -a /etc/apt/sources.list.d/pgdg.list + echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main $PGVER" | sudo tee -a /etc/apt/sources.list.d/pgdg.list wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - - sudo apt -y update - sudo apt -y --allow-downgrades install postgresql-$PGVER libpq5=$PGVER* libpq-dev=$PGVER* + sudo apt-get -y update + sudo apt-get -y --allow-downgrades install postgresql-$PGVER libpq5=$PGVER* libpq-dev=$PGVER* echo /usr/lib/postgresql/$PGVER/bin >> $GITHUB_PATH - name: Download PostgreSQL Macos if: matrix.os == 'macos' run: | wget https://get.enterprisedb.com/postgresql/postgresql-$PGVERSION-binaries.zip && \ - unzip postgresql-$PGVERSION-binaries.zip && \ - echo `pwd`/pgsql/bin >> $GITHUB_PATH + sudo mkdir -p /Library/PostgreSQL && \ + sudo unzip postgresql-$PGVERSION-binaries.zip -d /Library/PostgreSQL/$PGVER && \ + sudo mv /Library/PostgreSQL/$PGVER/pgsql/* /Library/PostgreSQL/$PGVER/ && \ + echo /Library/PostgreSQL/$PGVER/bin >> $GITHUB_PATH + - run: gem update --system 3.3.26 - run: bundle install - run: gem install --local *.gem --verbose - name: Run specs - continue-on-error: ${{ matrix.ruby == 'truffleruby' }} env: PG_DEBUG: 0 + # Temprary fix only for Truffleruby-24.0.0: + TRUFFLERUBYOPT: --experimental-options --keep-handles-alive run: ruby -rpg -S rspec spec/**/*_spec.rb -cfdoc - name: Print logs if job failed diff --git a/.gitignore b/.gitignore index 94a5f0f53..1de9c8ee9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,23 @@ *.lock +*.orig +*_BACKUP_* +*_BASE_* +*_LOCAL_* +*_REMOTE_* /.test_symlink /build/ +/ext/Makefile +/ext/mkmf.log +/ext/postgresql_lib_path.rb /doc/ /lib/*.bundle /lib/*.so -/lib/2.*/ +/lib/2.?/ +/lib/3.?/ /pkg/ /tmp/ -/tmp_test_specs/ +/tmp_test_*/ /vendor/ /lib/libpq.dll /lib/pg/postgresql_lib_path.rb +/test_trace.out diff --git a/.travis.yml b/.travis.yml index bf74f655a..0d8a36357 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,10 +17,10 @@ matrix: script: | docker run --rm -t --network=host ruby-pg - - rvm: "2.5" + - rvm: "2.7" env: - - "PGVERSION=9.3" - # Use Ubuntu-16.04 since postgresql-9.3 depends on openssl-1.0.0, which isn't available in 20.04 + - "PGVERSION=10" + # Use Ubuntu-16.04 which provides openssl-1.0.0, which isn't available in 20.04 dist: xenial - rvm: ruby-head env: @@ -38,8 +38,8 @@ before_install: # Download and install postgresql version to test against in /opt (for non-cross compile only) - echo "deb http://apt.postgresql.org/pub/repos/apt/ ${TRAVIS_DIST}-pgdg main $PGVERSION" | sudo tee -a /etc/apt/sources.list.d/pgdg.list - wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - - - sudo apt -y update - - sudo apt -y --allow-downgrades install postgresql-$PGVERSION libpq5=$PGVERSION* libpq-dev=$PGVERSION* + - sudo apt-get -y update + - sudo apt-get -y --allow-downgrades install postgresql-$PGVERSION libpq5=$PGVERSION* libpq-dev=$PGVERSION* - export PATH=/usr/lib/postgresql/$PGVERSION/bin:$PATH script: diff --git a/Gemfile b/Gemfile index 4f2d019ee..8395dc1ac 100644 --- a/Gemfile +++ b/Gemfile @@ -5,10 +5,19 @@ gemspec source "https://rubygems.org/" -group :development, :test do +group :development do + gem "rdoc", "~> 6.4" + gem "mini_portile2", "~> 2.1" +end + +group :test do gem "bundler", ">= 1.16", "< 3.0" gem "rake-compiler", "~> 1.0" - gem "rake-compiler-dock", "~> 1.0" - gem "rdoc", "~> 5.1" + gem "rake-compiler-dock", "~> 1.8.0" gem "rspec", "~> 3.5" + # "bigdecimal" is a gem on ruby-3.4+ and it's optional for ruby-pg. + # Specs should succeed without it, but 4 examples are then excluded. + # With bigdecimal commented out here, corresponding tests are omitted on ruby-3.4+ but are executed on ruby < 3.4. + # That way we can check both situations in CI. + # gem "bigdecimal", "~> 3.0" end diff --git a/History.md b/History.md new file mode 100644 index 000000000..5dd3dff09 --- /dev/null +++ b/History.md @@ -0,0 +1,958 @@ +## v1.6.0.rc1 [2024-11-28] Lars Kanis + +Added: + +- Add fat binary gem for platform `x86_64-linux`. + [#551](https://github.com/ged/ruby-pg/pull/551#issuecomment-2504715762) +- Add PG::BinaryDecoder::Array and PG::BinaryEncoder::Array to parse and encode PostgreSQL arrays in binary format. + [#603](https://github.com/ged/ruby-pg/pull/603) +- Add support for new query cancel functions of PostgreSQL-17. + This adds the new class `PG::CancelConnection` which provides the ability to cancel a query per blocking or per non-blocking functions. + If the new functions are available they are used and the older are no longer compiled in. + This way we can get rid of reading out the internal `PGcancel` struct by `Connection#backend_key`. + [#614](https://github.com/ged/ruby-pg/pull/614) +- Add Connection#set_chunked_rows_mode [#610](https://github.com/ged/ruby-pg/pull/610) +- Add PG::Connection#close_prepared, PG::Connection#close_portal, PG::Connection#send_close_prepared and PG::Connection#send_close_portal which are new in PostgreSQL-17. + [#611](https://github.com/ged/ruby-pg/pull/611) +- Add Connection#send_pipeline_sync, async_pipeline_sync and release GVL at PQ(sendP|P)ipelineSync. + [#612](https://github.com/ged/ruby-pg/pull/612) + +Removed: + +- Drop support of Ruby < 2.7 [#606](https://github.com/ged/ruby-pg/pull/606) +- Drop support of PostgreSQL < 10 [#606](https://github.com/ged/ruby-pg/pull/606) +- Remove workaround for Truffleruby < 21.3.0 [#613](https://github.com/ged/ruby-pg/pull/613) + + +## v1.5.9 [2024-10-24] Lars Kanis + +- Enable thread safety in static OpenSSL build for Windows. [#595](https://github.com/ged/ruby-pg/pull/595) +- Remove raising `conect_timeout` from 1 to 2 seconds. [#590](https://github.com/ged/ruby-pg/pull/590) +- Fix binary copy_data in Ractor context. [#594](https://github.com/ged/ruby-pg/pull/594) +- Exclude CI files and hidden files from built gem. [#591](https://github.com/ged/ruby-pg/pull/591) + This is to simplify security inspection. +- Update error classes to PostgreSQL-17. +- Update Windows fat binary gem to OpenSSL-3.4.0 and PostgreSQL-17.0. + + +## v1.5.8 [2024-09-06] Lars Kanis + +- Fix host list duplication every time conn.reset is used. [#586](https://github.com/ged/ruby-pg/pull/586) +- Add default decoder for anonymous record types to BasicTypeRegistry [#579](https://github.com/ged/ruby-pg/pull/579) +- Update Windows fat binary gem to OpenSSL-3.3.2 and PostgreSQL-16.4. + + +## v1.5.7 [2024-07-28] Lars Kanis + +- Remove deprecated use of fptr->fd.[#562](https://github.com/ged/ruby-pg/pull/562) + Direct access is disallowed since ruby-3.4. +- Make `pgconn_connect_poll` close the socket prior to calling `PQconnectPoll`. [#564](https://github.com/ged/ruby-pg/pull/564) + This could result in an exception while connecting when used multi threaded. +- Fix several typos and improve spelling in documentation and code. [#566](https://github.com/ged/ruby-pg/pull/566) +- Add missing PG::RollbackTransaction as an option to exit conn.transaction. [#560](https://github.com/ged/ruby-pg/pull/560) + Usage like in rails: https://api.rubyonrails.org/classes/ActiveRecord/Rollback.html +- Don't print a warning when bigdecimal is required on ruby-3.4+ [#574](https://github.com/ged/ruby-pg/pull/574) +- Update Windows fat binary gem to OpenSSL-3.3.1 and PostgreSQL-16.3. + + +## v1.5.6 [2024-03-01] Lars Kanis + +- Renew address resolution (DNS) in conn.reset. [#558](https://github.com/ged/ruby-pg/pull/558) + This is important, if DNS is used for load balancing, etc. +- Make bigdecimal an optional dependency. [#556](https://github.com/ged/ruby-pg/pull/556) + It's a gem in ruby-3.4+, so that users shouldn't be forced to use it. + + +## v1.5.5 [2024-02-15] Lars Kanis + +- Explicitly retype timespec fields to int64_t to fix compatibility with 32bit arches. [#547](https://github.com/ged/ruby-pg/pull/547) +- Fix possible buffer overflows in PG::BinaryDecoder::CopyRow on 32 bit systems. [#548](https://github.com/ged/ruby-pg/pull/548) +- Add binary Windows gems for Ruby 3.3. +- Update Windows fat binary gem to OpenSSL-3.2.1 and PostgreSQL-16.2. + + +## v1.5.4 [2023-09-01] Lars Kanis + +- Fix compiling the pg extension with MSVC 2022. [#535](https://github.com/ged/ruby-pg/pull/535) +- Set PG::Connection's encoding even if setting client_encoding on connection startup fails. [#541](https://github.com/ged/ruby-pg/pull/541) +- Don't set the server's client_encoding if it's unnecessary. [#542](https://github.com/ged/ruby-pg/pull/542) + This is important for connection proxies, who disallow configuration settings. +- Update Windows fat binary gem to OpenSSL-3.1.2 and PostgreSQL-15.4. + + +## v1.5.3 [2023-04-28] Lars Kanis + +- Fix possible segfault when creating a new PG::Result with type map. [#530](https://github.com/ged/ruby-pg/pull/530) +- Add category to deprecation warnings of Coder.new, so that they are suppressed for most users. [#528](https://github.com/ged/ruby-pg/pull/528) + + +## v1.5.2 [2023-04-26] Lars Kanis + +- Fix regression in copy_data regarding binary format when using no coder. [#527](https://github.com/ged/ruby-pg/pull/527) + + +## v1.5.1 [2023-04-24] Lars Kanis + +- Don't overwrite flags of timestamp coders. [#524](https://github.com/ged/ruby-pg/pull/524) + Fixes a regression in rails: https://github.com/rails/rails/issues/48049 + + +## v1.5.0 [2023-04-24] Lars Kanis + +Enhancements: + +- Better support for binary format: + - Extend PG::Connection#copy_data to better support binary transfers [#511](https://github.com/ged/ruby-pg/pull/511) + - Add binary COPY encoder and decoder: + * PG::BinaryEncoder::CopyRow + * PG::BinaryDecoder::CopyRow + - Add binary timestamp encoders: + * PG::BinaryEncoder::TimestampUtc + * PG::BinaryEncoder::TimestampLocal + * PG::BinaryEncoder::Timestamp + - Add PG::BinaryEncoder::Float4 and Float8 + - Add binary date type: [#515](https://github.com/ged/ruby-pg/pull/515) + * PG::BinaryEncoder::Date + * PG::BinaryDecoder::Date + - Add PG::Result#binary_tuples [#511](https://github.com/ged/ruby-pg/pull/511) + It is useful for COPY and not deprecated in that context. + - Add PG::TextEncoder::Bytea to BasicTypeRegistry [#506](https://github.com/ged/ruby-pg/pull/506) +- Ractor support: [#519](https://github.com/ged/ruby-pg/pull/519) + - Pg is now fully compatible with Ractor introduced in Ruby-3.0 and doesn't use any global mutable state. + - All type en/decoders and type maps are shareable between ractors if they are made frozen by `Ractor.make_shareable`. + - Also frozen PG::Result and PG::Tuple objects can be shared. + - All frozen objects (except PG::Connection) can still be used to do communication with the PostgreSQL server or to read retrieved data. + - PG::Connection is not shareable and must be created within each Ractor to establish a dedicated connection. +- Use keyword arguments instead of hashes for Coder initialization and #to_h. [#511](https://github.com/ged/ruby-pg/pull/511) +- Add PG::Result.res_status as a class method and extend Result#res_status to return the status of self. [#508](https://github.com/ged/ruby-pg/pull/508) +- Reduce the number of files loaded at `require 'pg'` by using autoload. [#513](https://github.com/ged/ruby-pg/pull/513) + Previously stdlib libraries `date`, `json`, `ipaddr` and `bigdecimal` were static dependencies, but now only `socket` is mandatory. +- Improve garbage collector performance by adding write barriers to all PG classes. [#518](https://github.com/ged/ruby-pg/pull/518) + Now they can be promoted to the old generation, which means they only get marked on major GC. +- New method PG::Connection#check_socket to check the socket state. [#521](https://github.com/ged/ruby-pg/pull/521) +- Mark many internal constants as private. [#522](https://github.com/ged/ruby-pg/pull/522) +- Update Windows fat binary gem to OpenSSL-3.1.0. + +Bugfixes: + +- Move nfields-check of stream-methods after result status check [#507](https://github.com/ged/ruby-pg/pull/507) + This ensures that the nfield-check doesn't hide errors like statement timeout. + +Removed: + +- Remove deprecated PG::BasicTypeRegistry.register_type and co. [Part of #519](https://github.com/ged/ruby-pg/commit/2919ee1a0c6b216e18e1d06c95c2616ef69d2f97) +- Add deprecation warning about PG::Coder initialization per Hash argument. [#514](https://github.com/ged/ruby-pg/pull/514) + It is recommended to use keyword arguments instead. +- The internal encoding cache was removed. [#516](https://github.com/ged/ruby-pg/pull/516) + It shouldn't have a practical performance impact. + +Repository: + +- `rake test` tries to find PostgreSQL server commands by pg_config [#503](https://github.com/ged/ruby-pg/pull/503) + So there's no need to set the PATH manually any longer. + + +## v1.4.6 [2023-02-26] Lars Kanis + +- Add japanese README file. [#502](https://github.com/ged/ruby-pg/pull/502) +- Improve `discard_results` to not block under memory pressure. [#500](https://github.com/ged/ruby-pg/pull/500) +- Use a dedicated error class `PG::LostCopyState` for errors due to another query within `copy_data` and mention that it's probably due to another query. + Previously the "no COPY in progress" `PG::Error` was less specific. [#499](https://github.com/ged/ruby-pg/pull/499) +- Make sure an error in `put_copy_end` of `copy_data` doesn't lose the original exception. +- Disable nonblocking mode while large object calls. [#498](https://github.com/ged/ruby-pg/pull/498) + Since pg-1.3.0 libpq's "lo_*" calls failed when a bigger amount of data was transferred. + This specifically forced the `active_storage-postgresql` gem to use pg-1.2.3. +- Add rdoc options to gemspec, so that "gem install" generates complete offline documentation. +- Add binary Windows gems for Ruby 3.2. +- Update Windows fat binary gem to PostgreSQL-15.2 and OpenSSL-3.0.8. + + +## v1.4.5 [2022-11-17] Lars Kanis + +- Return the libpq default port when blank in conninfo. [#492](https://github.com/ged/ruby-pg/pull/492) +- Add PG::DEF_PGPORT constant and use it in specs. [#492](https://github.com/ged/ruby-pg/pull/492) +- Fix name resolution when empty or `nil` port is given. +- Update error codes to PostgreSQL-15. +- Update Windows fat binary gem to PostgreSQL-15.1 AND OpenSSL-1.1.1s. + + +## v1.4.4 [2022-10-11] Lars Kanis + +- Revert to let libpq do the host iteration while connecting. [#485](https://github.com/ged/ruby-pg/pull/485) + Ensure that parameter `connect_timeout` is still respected. +- Handle multiple hosts in the connection string, where only one host has writable session. [#476](https://github.com/ged/ruby-pg/pull/476) +- Add some useful information to PG::Connection#inspect. [#487](https://github.com/ged/ruby-pg/pull/487) +- Support new pgresult_stream_any API in sequel_pg-1.17.0. [#481](https://github.com/ged/ruby-pg/pull/481) +- Update Windows fat binary gem to PostgreSQL-14.5. + + +## v1.4.3 [2022-08-09] Lars Kanis + +- Avoid memory bloat possible in put_copy_data in pg-1.4.0 to 1.4.2. [#473](https://github.com/ged/ruby-pg/pull/473) +- Use Encoding::BINARY for JOHAB, removing some useless code. [#472](https://github.com/ged/ruby-pg/pull/472) + + +## v1.4.2 [2022-07-27] Lars Kanis + +Bugfixes: + +- Properly handle empty host parameter when connecting. [#471](https://github.com/ged/ruby-pg/pull/471) +- Update Windows fat binary gem to OpenSSL-1.1.1q. + + +## v1.4.1 [2022-06-24] Lars Kanis + +Bugfixes: + +- Fix another ruby-2.7 keyword warning. [#465](https://github.com/ged/ruby-pg/pull/465) +- Allow PG::Error to be created without arguments. [#466](https://github.com/ged/ruby-pg/pull/466) + + +## v1.4.0 [2022-06-20] Lars Kanis + +Added: + +- Add PG::Connection#hostaddr, present since PostgreSQL-12. [#453](https://github.com/ged/ruby-pg/pull/453) +- Add PG::Connection.conninfo_parse to wrap PQconninfoParse. [#453](https://github.com/ged/ruby-pg/pull/453) + +Bugfixes: + +- Try IPv6 and IPv4 addresses, if DNS resolves to both. [#452](https://github.com/ged/ruby-pg/pull/452) +- Re-add block-call semantics to PG::Connection.new accidentally removed in pg-1.3.0. [#454](https://github.com/ged/ruby-pg/pull/454) +- Handle client error after all data consumed in #copy_data for output. [#455](https://github.com/ged/ruby-pg/pull/455) +- Avoid spurious keyword argument warning on Ruby 2.7. [#456](https://github.com/ged/ruby-pg/pull/456) +- Change connection setup to respect connect_timeout parameter. [#459](https://github.com/ged/ruby-pg/pull/459) +- Fix indefinite hang in case of connection error on Windows [#458](https://github.com/ged/ruby-pg/pull/458) +- Set connection attribute of PG::Error in various places where it was missing. [#461](https://github.com/ged/ruby-pg/pull/461) +- Fix transaction leak on early break/return. [#463](https://github.com/ged/ruby-pg/pull/463) +- Update Windows fat binary gem to OpenSSL-1.1.1o and PostgreSQL-14.4. + +Enhancements: + +- Don't flush at each put_copy_data call, but flush at get_result. [#462](https://github.com/ged/ruby-pg/pull/462) + + +## v1.3.5 [2022-03-31] Lars Kanis + +Bugfixes: + +- Handle PGRES_COMMAND_OK in pgresult_stream_any. [#447](https://github.com/ged/ruby-pg/pull/447) + Fixes usage when trying to stream the result of a procedure call that returns no results. + +Enhancements: + +- Rename BasicTypeRegistry#define_default_types to #register_default_types to use a more consistent terminology. + Keeping define_default_types for compatibility. +- BasicTypeRegistry: return self instead of objects by accident. + This allows call chaining. +- Add some April fun. [#449](https://github.com/ged/ruby-pg/pull/449) + +Documentation: +- Refine documentation of conn.socket_io and conn.connect_poll + + +## v1.3.4 [2022-03-10] Lars Kanis + +Bugfixes: + +- Don't leak IO in case of connection errors. [#439](https://github.com/ged/ruby-pg/pull/439) + Previously it was kept open until the PG::Connection was garbage collected. +- Fix a performance regression in conn.get_result noticed in single row mode. [#442](https://github.com/ged/ruby-pg/pull/442) +- Fix occasional error Errno::EBADF (Bad file descriptor) while connecting. [#444](https://github.com/ged/ruby-pg/pull/444) +- Fix compatibility of res.stream_each* methods with Fiber.scheduler. [#446](https://github.com/ged/ruby-pg/pull/446) +- Remove FL_TEST and FL_SET, which are MRI-internal. [#437](https://github.com/ged/ruby-pg/pull/437) + +Enhancements: + +- Allow pgresult_stream_any to be used by sequel_pg. [#443](https://github.com/ged/ruby-pg/pull/443) + + +## v1.3.3 [2022-02-22] Lars Kanis + +Bugfixes: + +- Fix omission of the third digit of IPv4 addresses in connection URI. [#435](https://github.com/ged/ruby-pg/pull/435) +- Fix wrong permission of certs/larskanis-2022.pem in the pg-1.3.2.gem. [#432](https://github.com/ged/ruby-pg/pull/432) + + +## v1.3.2 [2022-02-14] Lars Kanis + +Bugfixes: + +- Cancel only active query after failing transaction. [#430](https://github.com/ged/ruby-pg/pull/430) + This avoids an incompatibility with pgbouncer since pg-1.3.0. +- Fix String objects with non-applied encoding when using COPY or record decoders. [#427](https://github.com/ged/ruby-pg/pull/427) +- Update Windows fat binary gem to PostgreSQL-14.2. + +Enhancements: + +- Improve extconf.rb checks to reduces the number of compiler calls. +- Add a check for PGRES_PIPELINE_SYNC, to make sure the library version and the header files are PostgreSQL-14+. [#429](https://github.com/ged/ruby-pg/pull/429) + + +## v1.3.1 [2022-02-01] Michael Granger + +Bugfixes: + +- Fix wrong handling of socket writability on Windows introduced in [#417](https://github.com/ged/ruby-pg/pull/417). + This caused starvation in conn.put_copy_data. +- Fix error in PG.version_string(true). [#419](https://github.com/ged/ruby-pg/pull/419) +- Fix a regression in pg 1.3.0 where Ruby 2.x busy-looping any fractional seconds for every wait. [#420](https://github.com/ged/ruby-pg/pull/420) + +Enhancements: + +- Raise an error when conn.copy_data is used in nonblocking mode. + + +## v1.3.0 [2022-01-20] Michael Granger + +Install Enhancements: +- Print some install help if libpq wasn't found. [#396](https://github.com/ged/ruby-pg/pull/396) + This should help to pick the necessary package without googling. +- Update Windows fat binary gem to OpenSSL-1.1.1m and PostgreSQL-14.1. +- Add binary Windows gems for Ruby 3.0 and 3.1. +- Make the library path of libpq available in ruby as PG::POSTGRESQL_LIB_PATH and add it to the search paths on Windows similar to +rpath+ on Unix systems. [#373](https://github.com/ged/ruby-pg/pull/373) +- Fall back to pkg-config if pg_config is not found. [#380](https://github.com/ged/ruby-pg/pull/380) +- Add option to extconf.rb to disable nogvl-wrapping of libpq functions. + All methods (except PG::Connection.ping) are nonblocking now, so that GVL unlock is in theory no longer necessary. + However it can have some advantage in concurrency, so that GVL unlock is still enabled by default. + Use: + - gem inst pg -- --disable-gvl-unlock + +API Enhancements: +- Add full compatibility to Fiber.scheduler introduced in Ruby-3.0. [#397](https://github.com/ged/ruby-pg/pull/397) + - Add async_connect and async_send methods and add specific specs for Fiber.scheduler [#342](https://github.com/ged/ruby-pg/pull/342) + - Add async_get_result and async_get_last_result + - Add async_get_copy_data + - Implement async_put_copy_data/async_put_copy_end + - Implement async_reset method using the nonblocking libpq API + - Add async_set_client_encoding which is compatible to scheduler + - Add async_cancel as a nonblocking version of conn#cancel + - Add async_encrypt_password + - Run Connection.ping in a second thread. + - Make discard_results scheduler friendly + - Do all socket waiting through the conn.socket_io object. + - Avoid PG.connect blocking while address resolution by automatically providing the +hostaddr+ parameter and resolving in Ruby instead of libpq. + - On Windows Fiber.scheduler support requires Ruby-3.1+. + It is also only partly usable since may ruby IO methods are not yet scheduler aware on Windows. +- Add support for pipeline mode of PostgreSQL-14. [#401](https://github.com/ged/ruby-pg/pull/401) +- Allow specification of multiple hosts in PostgreSQL URI. [#387](https://github.com/ged/ruby-pg/pull/387) +- Add new method conn.backend_key - used to implement our own cancel method. + +Type cast enhancements: +- Add PG::BasicTypeMapForQueries::BinaryData for encoding of bytea columns. [#348](https://github.com/ged/ruby-pg/pull/348) +- Reduce time to build coder maps and permit to reuse them for several type maps per PG::BasicTypeRegistry::CoderMapsBundle.new(conn) . [#376](https://github.com/ged/ruby-pg/pull/376) +- Make BasicTypeRegistry a class and use a global default instance of it. + Now a local type registry can be instantiated and given to the type map, to avoid changing shared global states. +- Allow PG::BasicTypeMapForQueries to take a Proc as callback for undefined types. + +Other Enhancements: +- Convert all PG classes implemented in C to TypedData objects. [#349](https://github.com/ged/ruby-pg/pull/349) +- Support ObjectSpace.memsize_of(obj) on all classes implemented in C. [#393](https://github.com/ged/ruby-pg/pull/393) +- Make all PG objects implemented in C memory moveable and therefore GC.compact friendly. [#349](https://github.com/ged/ruby-pg/pull/349) +- Update errorcodes and error classes to PostgreSQL-14.0. +- Add PG::CONNECTION_* constants for conn.status of newer PostgreSQL versions. +- Add better support for logical replication. [#339](https://github.com/ged/ruby-pg/pull/339) +- Change conn.socket_io to read+write mode and to a BasicSocket object instead of IO. +- Use rb_io_wait() and the conn.socket_io object if available for better compatibility to Fiber.scheduler . + Fall back to rb_wait_for_single_fd() on ruby < 3.0. +- On Windows use a specialized wait function as a workaround for very poor performance of rb_io_wait(). [#416](https://github.com/ged/ruby-pg/pull/416) + +Bugfixes: +- Release GVL while calling PQping which is a blocking method, but it didn't release GVL so far. +- Fix Connection#transaction to no longer block on interrupts, for instance when pressing Ctrl-C and cancel a running query. [#390](https://github.com/ged/ruby-pg/pull/390) +- Avoid casting of OIDs to fix compat with Redshift database. [#369](https://github.com/ged/ruby-pg/pull/369) +- Call conn.block before each conn.get_result call to avoid possible blocking in case of a slow network and multiple query results. +- Sporadic Errno::ENOTSOCK when using conn.socket_io on Windows [#398](https://github.com/ged/ruby-pg/pull/398) + +Deprecated: +- Add deprecation warning to PG::BasicTypeRegistry.register_type and siblings. + +Removed: +- Remove support of ruby-2.2, 2.3 and 2.4. Minimum is ruby-2.5 now. +- Remove support for PostgreSQL-9.2. Minimum is PostgreSQL-9.3 now. +- Remove constant PG::REVISION, which was broken since pg-1.1.4. + +Repository: +- Replace Hoe by Bundler for gem packaging +- Add Github Actions CI and testing of source and binary gems. + + +## v1.2.3 [2020-03-18] Michael Granger + +Bugfixes: + +- Fix possible segfault at `PG::Coder#encode`, `decode` or their implicit calls through + a typemap after GC.compact. [#327](https://github.com/ged/ruby-pg/pull/327) +- Fix possible segfault in `PG::TypeMapByClass` after GC.compact. [#328](https://github.com/ged/ruby-pg/pull/328) + + +## v1.2.2 [2020-01-06] Michael Granger + +Enhancements: + +- Add a binary gem for Ruby 2.7. + + +## v1.2.1 [2020-01-02] Michael Granger + +Enhancements: + +- Added internal API for sequel_pg compatibility. + + +## v1.2.0 [2019-12-20] Michael Granger + +Repository: +- Our primary repository has been moved to Github https://github.com/ged/ruby-pg . + Most of the issues from https://bitbucket.org/ged/ruby-pg have been migrated. [#43](https://github.com/ged/ruby-pg/pull/43) + +API enhancements: +- Add PG::Result#field_name_type= and siblings to allow symbols to be used as field names. [#306](https://github.com/ged/ruby-pg/pull/306) +- Add new methods for error reporting: + - PG::Connection#set_error_context_visibility + - PG::Result#verbose_error_message + - PG::Result#result_verbose_error_message (alias) +- Update errorcodes and error classes to PostgreSQL-12.0. +- New constants: PG_DIAG_SEVERITY_NONLOCALIZED, PQERRORS_SQLSTATE, PQSHOW_CONTEXT_NEVER, PQSHOW_CONTEXT_ERRORS, PQSHOW_CONTEXT_ALWAYS + +Type cast enhancements: +- Add PG::TextEncoder::Record and PG::TextDecoder::Record for en/decoding of Composite Types. [#258](https://github.com/ged/ruby-pg/pull/258), [#36](https://github.com/ged/ruby-pg/pull/36) +- Add PG::BasicTypeRegistry.register_coder to register instances instead of classes. + This is useful to register parametrized en/decoders like PG::TextDecoder::Record . +- Add PG::BasicTypeMapForQueries#encode_array_as= to switch between various interpretations of ruby arrays. +- Add Time, Array