Skip to content

Conversation

@jwaisner
Copy link
Contributor

@jwaisner jwaisner commented Nov 23, 2025

PR Type

Enhancement, Tests


Description

  • Add PostgreSQL 13.23, 14.20, 15.15, 16.11, 17.7, 18.1 configurations

  • Implement comprehensive CI/CD testing workflow for PostgreSQL versions

    • Automated testing on PR creation, updates, and edits
    • Tests latest 5 versions from releases.properties
    • Four-phase validation: installation, initialization, operations, cleanup
  • Create configuration files for each PostgreSQL version

    • bearsampp.conf with version-specific settings
    • postgresql.conf.ber with database configuration
    • pg_hba.conf.ber with authentication rules
    • init.bat initialization scripts
  • Add detailed CI/CD testing documentation


Diagram Walkthrough

flowchart LR
  A["PostgreSQL Versions<br/>13.23-18.1"] --> B["Configuration Files<br/>bearsampp.conf<br/>postgresql.conf.ber<br/>pg_hba.conf.ber<br/>init.bat"]
  A --> C["CI/CD Workflow<br/>postgresql-test.yml"]
  C --> D["Phase 1<br/>Download & Verify"]
  C --> E["Phase 2<br/>Initialize & Start"]
  C --> F["Phase 3<br/>Database Operations"]
  C --> G["Phase 4<br/>Cleanup"]
  D --> H["Test Results<br/>PR Comments<br/>Artifacts"]
  E --> H
  F --> H
  G --> H
Loading

File Walkthrough

Relevant files
Tests
1 files
postgresql-test.yml
Comprehensive PostgreSQL CI/CD testing workflow                   
+717/-0 
Documentation
2 files
CI-CD-TESTING.md
Complete CI/CD testing documentation and guide                     
+255/-0 
README.md
Documentation index for PostgreSQL module                               
+36/-0   
Configuration changes
24 files
init.bat
Database initialization script for PostgreSQL 13.23           
+5/-0     
init.bat
Database initialization script for PostgreSQL 14.20           
+5/-0     
init.bat
Database initialization script for PostgreSQL 15.15           
+5/-0     
init.bat
Database initialization script for PostgreSQL 16.11           
+5/-0     
init.bat
Database initialization script for PostgreSQL 17.7             
+5/-0     
init.bat
Database initialization script for PostgreSQL 18.1             
+5/-0     
postgresql.conf.ber
PostgreSQL server configuration template 13.23                     
+35/-0   
postgresql.conf.ber
PostgreSQL server configuration template 14.20                     
+35/-0   
postgresql.conf.ber
PostgreSQL server configuration template 15.15                     
+35/-0   
postgresql.conf.ber
PostgreSQL server configuration template 16.11                     
+35/-0   
postgresql.conf.ber
PostgreSQL server configuration template 17.7                       
+35/-0   
postgresql.conf.ber
PostgreSQL server configuration template 18.1                       
+35/-0   
pg_hba.conf.ber
PostgreSQL authentication configuration 13.23                       
+3/-0     
pg_hba.conf.ber
PostgreSQL authentication configuration 14.20                       
+3/-0     
pg_hba.conf.ber
PostgreSQL authentication configuration 15.15                       
+3/-0     
pg_hba.conf.ber
PostgreSQL authentication configuration 16.11                       
+3/-0     
pg_hba.conf.ber
PostgreSQL authentication configuration 17.7                         
+3/-0     
pg_hba.conf.ber
PostgreSQL authentication configuration 18.1                         
+3/-0     
bearsampp.conf
Bearsampp module configuration for PostgreSQL 13.23           
+14/-0   
bearsampp.conf
Bearsampp module configuration for PostgreSQL 14.20           
+14/-0   
bearsampp.conf
Bearsampp module configuration for PostgreSQL 15.15           
+14/-0   
bearsampp.conf
Bearsampp module configuration for PostgreSQL 16.11           
+14/-0   
bearsampp.conf
Bearsampp module configuration for PostgreSQL 17.7             
+14/-0   
bearsampp.conf
Bearsampp module configuration for PostgreSQL 18.1             
+14/-0   
Additional files
5 files
gc.properties [link]   
gc.properties [link]   
cache.properties +2/-0     
gc.properties [link]   
problems-report.html +659/-0 

@qodo-code-review
Copy link

qodo-code-review bot commented Nov 23, 2025

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
Insecure authentication

Description: Initializes the database with '-A trust' which disables password authentication, allowing
local connections without credentials and risking unauthorized access if the service is
exposed or reused beyond a secured dev environment.
init.bat [3-3]

Referred Code
%~dp0bin\initdb.exe -U postgres -A trust -E utf8 -D "%~dp0data" > "~BEARSAMPP_WIN_PATH~\logs\postgresql-install.log" 2>&1
copy /y "%~dp0postgresql.conf.ber" "%~dp0data\postgresql.conf"
Insecure authentication

Description: Initializes the database with '-A trust' which disables password authentication, allowing
local connections without credentials and risking unauthorized access if the service is
exposed or reused beyond a secured dev environment.
init.bat [3-3]

Referred Code
%~dp0bin\initdb.exe -U postgres -A trust -E utf8 -D "%~dp0data" > "~BEARSAMPP_WIN_PATH~\logs\postgresql-install.log" 2>&1
copy /y "%~dp0postgresql.conf.ber" "%~dp0data\postgresql.conf"
Insecure authentication

Description: Initializes the database with '-A trust' which disables password authentication, allowing
local connections without credentials and risking unauthorized access if the service is
exposed or reused beyond a secured dev environment.
init.bat [3-3]

Referred Code
%~dp0bin\initdb.exe -U postgres -A trust -E utf8 -D "%~dp0data" > "~BEARSAMPP_WIN_PATH~\logs\postgresql-install.log" 2>&1
copy /y "%~dp0postgresql.conf.ber" "%~dp0data\postgresql.conf"
Insecure authentication

Description: Initializes the database with '-A trust' which disables password authentication, allowing
local connections without credentials and risking unauthorized access if the service is
exposed or reused beyond a secured dev environment.
init.bat [3-3]

Referred Code
%~dp0bin\initdb.exe -U postgres -A trust -E utf8 -D "%~dp0data" > "~BEARSAMPP_WIN_PATH~\logs\postgresql-install.log" 2>&1
copy /y "%~dp0postgresql.conf.ber" "%~dp0data\postgresql.conf"
Insecure authentication

Description: Initializes the database with '-A trust' which disables password authentication, allowing
local connections without credentials and risking unauthorized access if the service is
exposed or reused beyond a secured dev environment.
init.bat [3-3]

Referred Code
%~dp0bin\initdb.exe -U postgres -A trust -E utf8 -D "%~dp0data" > "~BEARSAMPP_WIN_PATH~\logs\postgresql-install.log" 2>&1
copy /y "%~dp0postgresql.conf.ber" "%~dp0data\postgresql.conf"
Insecure authentication

Description: Initializes the database with '-A trust' which disables password authentication, allowing
local connections without credentials and risking unauthorized access if the service is
exposed or reused beyond a secured dev environment.
init.bat [3-3]

Referred Code
%~dp0bin\initdb.exe -U postgres -A trust -E utf8 -D "%~dp0data" > "~BEARSAMPP_WIN_PATH~\logs\postgresql-install.log" 2>&1
copy /y "%~dp0postgresql.conf.ber" "%~dp0data\postgresql.conf"
Weak pg_hba policy

Description: 'pg_hba.conf' uses 'trust' authentication for IPv4 and IPv6 localhost, which permits
passwordless access and can be unsafe if the instance binds broadly or if localhost is
accessible by untrusted local users.
pg_hba.conf.ber [2-3]

Referred Code
host        all           all             127.0.0.1/32            trust
host 		    all           all              ::1/128	      				trust
Weak pg_hba policy

Description: 'pg_hba.conf' uses 'trust' authentication for IPv4 and IPv6 localhost, which permits
passwordless access and can be unsafe if the instance binds broadly or if localhost is
accessible by untrusted local users.
pg_hba.conf.ber [2-3]

Referred Code
host        all           all             127.0.0.1/32            trust
host 		    all           all              ::1/128	      				trust
Weak pg_hba policy

Description: 'pg_hba.conf' uses 'trust' authentication for IPv4 and IPv6 localhost, which permits
passwordless access and can be unsafe if the instance binds broadly or if localhost is
accessible by untrusted local users.
pg_hba.conf.ber [2-3]

Referred Code
host        all           all             127.0.0.1/32            trust
host 		    all           all              ::1/128	      				trust
Weak pg_hba policy

Description: 'pg_hba.conf' uses 'trust' authentication for IPv4 and IPv6 localhost, which permits
passwordless access and can be unsafe if the instance binds broadly or if localhost is
accessible by untrusted local users.
pg_hba.conf.ber [2-3]

Referred Code
host        all           all             127.0.0.1/32            trust
host 		    all           all              ::1/128	      				trust
Weak pg_hba policy

Description: 'pg_hba.conf' uses 'trust' authentication for IPv4 and IPv6 localhost, which permits
passwordless access and can be unsafe if the instance binds broadly or if localhost is
accessible by untrusted local users.
pg_hba.conf.ber [2-3]

Referred Code
host        all           all             127.0.0.1/32            trust
host 		    all           all              ::1/128	      				trust
Weak pg_hba policy

Description: 'pg_hba.conf' uses 'trust' authentication for IPv4 and IPv6 localhost, which permits
passwordless access and can be unsafe if the instance binds broadly or if localhost is
accessible by untrusted local users.
pg_hba.conf.ber [2-3]

Referred Code
host        all           all             127.0.0.1/32            trust
host 		    all           all              ::1/128	      				trust
Overly broad bind

Description: 'listen_addresses = "*"' exposes the server to all network interfaces; combined with
permissive auth settings this can lead to remote, unauthenticated access if firewalling is
misconfigured.
postgresql.conf.ber [11-11]

Referred Code
listen_addresses = '*'
port = 5432
Overly broad bind

Description: 'listen_addresses = "*"' exposes the server to all network interfaces; combined with
permissive auth settings this can lead to remote, unauthenticated access if firewalling is
misconfigured.
postgresql.conf.ber [11-11]

Referred Code
listen_addresses = '*'
port = 5432
Overly broad bind

Description: 'listen_addresses = "*"' exposes the server to all network interfaces; combined with
permissive auth settings this can lead to remote, unauthenticated access if firewalling is
misconfigured.
postgresql.conf.ber [11-11]

Referred Code
listen_addresses = '*'
port = 5432
Overly broad bind

Description: 'listen_addresses = "*"' exposes the server to all network interfaces; combined with
permissive auth settings this can lead to remote, unauthenticated access if firewalling is
misconfigured.
postgresql.conf.ber [11-11]

Referred Code
listen_addresses = '*'
port = 5432
Overly broad bind

Description: 'listen_addresses = "*"' exposes the server to all network interfaces; combined with
permissive auth settings this can lead to remote, unauthenticated access if firewalling is
misconfigured.
postgresql.conf.ber [11-11]

Referred Code
listen_addresses = '*'
port = 5432
Overly broad bind

Description: 'listen_addresses = "*"' exposes the server to all network interfaces; combined with
permissive auth settings this can lead to remote, unauthenticated access if firewalling is
misconfigured.
postgresql.conf.ber [11-11]

Referred Code
listen_addresses = '*'
port = 5432
Insecure file permissions

Description: 'log_file_mode = 0777' makes log files world-readable and writable, risking tampering,
privilege escalation via symlink attacks, or leakage of sensitive data contained in logs.
postgresql.conf.ber [27-27]

Referred Code
log_file_mode = 0777
log_truncate_on_rotation = off
Insecure file permissions

Description: 'log_file_mode = 0777' makes log files world-readable and writable, risking tampering,
privilege escalation via symlink attacks, or leakage of sensitive data contained in logs.
postgresql.conf.ber [27-27]

Referred Code
log_file_mode = 0777
log_truncate_on_rotation = off
Insecure file permissions

Description: 'log_file_mode = 0777' makes log files world-readable and writable, risking tampering,
privilege escalation via symlink attacks, or leakage of sensitive data contained in logs.
postgresql.conf.ber [27-27]

Referred Code
log_file_mode = 0777
log_truncate_on_rotation = off
Insecure file permissions

Description: 'log_file_mode = 0777' makes log files world-readable and writable, risking tampering,
privilege escalation via symlink attacks, or leakage of sensitive data contained in logs.
postgresql.conf.ber [27-27]

Referred Code
log_file_mode = 0777
log_truncate_on_rotation = off
Insecure file permissions

Description: 'log_file_mode = 0777' makes log files world-readable and writable, risking tampering,
privilege escalation via symlink attacks, or leakage of sensitive data contained in logs.
postgresql.conf.ber [27-27]

Referred Code
log_file_mode = 0777
log_truncate_on_rotation = off
Insecure file permissions

Description: 'log_file_mode = 0777' makes log files world-readable and writable, risking tampering,
privilege escalation via symlink attacks, or leakage of sensitive data contained in logs.
postgresql.conf.ber [27-27]

Referred Code
log_file_mode = 0777
log_truncate_on_rotation = off
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

🔴
Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status:
Insecure Log Mode: The configuration sets log_file_mode to 0777 which over-permits access to logs and risks
exposure of sensitive operational information.

Referred Code
log_file_mode = 0777
log_truncate_on_rotation = off

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status:
Insecure Authentication: The pg_hba configuration uses trust authentication for local IPv4 and IPv6 which allows
passwordless access and violates secure authentication requirements.

Referred Code
host        all           all             127.0.0.1/32            trust
host 		    all           all              ::1/128	      				trust

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
Limited Audit Logs: Initialization actions are redirected to a single install log without clear inclusion of
user identity or action outcome details, and broader operational audit logging is not
configured here.

Referred Code
%~dp0bin\initdb.exe -U postgres -A trust -E utf8 -D "%~dp0data" > "~BEARSAMPP_WIN_PATH~\logs\postgresql-install.log" 2>&1
copy /y "%~dp0postgresql.conf.ber" "%~dp0data\postgresql.conf"

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Missing Error Checks: The batch script executes multiple commands without explicit error checking or conditional
handling for failures, relying solely on redirection to a log file.

Referred Code
%~dp0bin\initdb.exe -U postgres -A trust -E utf8 -D "%~dp0data" > "~BEARSAMPP_WIN_PATH~\logs\postgresql-install.log" 2>&1
copy /y "%~dp0postgresql.conf.ber" "%~dp0data\postgresql.conf"
copy /y "%~dp0pg_hba.conf.ber" "%~dp0data\pg_hba.conf"

Learn more about managing compliance generic rules or creating your own custom rules

  • Update
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link

qodo-code-review bot commented Nov 23, 2025

PR Code Suggestions ✨

Latest suggestions up to 7435ea9

CategorySuggestion                                                                                                                                    Impact
Possible issue
Add robust server readiness check

Replace the fixed 5-second sleep with a robust readiness check loop. The loop
should poll for a server connection with a timeout to prevent flaky test
failures caused by slow startup.

.github/workflows/postgresql-test.yml [303-351]

 - name: Start PostgreSQL Server
   id: start-server
   if: steps.init-database.outputs.success == 'true'
   continue-on-error: true
   run: |
     $ErrorActionPreference = "Continue"
     $binPath = "${{ steps.verify-postgresql.outputs.bin-path }}"
     $dataDir = "${{ steps.init-database.outputs.data-dir }}"
     $logFile = Join-Path (Get-Location) "test-results\postgresql.log"
-    
+    $port = 5432
+
     Write-Host "=== Phase 2.2: Start PostgreSQL Server ==="
-    
+
     try {
       $pgCtlExe = Join-Path $binPath "pg_ctl.exe"
-      
-      # Start the server
+      $psqlExe = Join-Path $binPath "psql.exe"
+
       Write-Host "Starting PostgreSQL server..."
       $output = & $pgCtlExe -D $dataDir -l $logFile start 2>&1 | Out-String
       Write-Host $output
-      
-      # Wait for server to be ready
-      Write-Host "Waiting for server to be ready..."
-      Start-Sleep -Seconds 5
-      
-      # Check server status
-      $statusOutput = & $pgCtlExe -D $dataDir status 2>&1 | Out-String
-      Write-Host $statusOutput
-      
-      if ($statusOutput -match "server is running") {
-        Write-Host "✅ PostgreSQL server is running"
+
+      # Wait for readiness up to 60s: try pg_isready (via psql), then TCP connect fallback
+      $ready = $false
+      $maxSeconds = 60
+      for ($i = 0; $i -lt $maxSeconds; $i++) {
+        Start-Sleep -Seconds 1
+
+        # Try a lightweight connection using psql (no query execution)
+        try {
+          $conn = & $psqlExe -U postgres -d postgres -c "SELECT 1;" -t -A 2>$null
+          if ($LASTEXITCODE -eq 0) {
+            $ready = $true
+            break
+          }
+        } catch {}
+
+        # TCP fallback
+        try {
+          $client = New-Object System.Net.Sockets.TcpClient
+          $iar = $client.BeginConnect("127.0.0.1", $port, $null, $null)
+          $success = $iar.AsyncWaitHandle.WaitOne(500)
+          if ($success -and $client.Connected) {
+            $client.EndConnect($iar)
+            $client.Close()
+            $ready = $true
+            break
+          }
+          $client.Close()
+        } catch {}
+      }
+
+      if ($ready) {
+        Write-Host "✅ PostgreSQL server is accepting connections"
         echo "success=true" >> $env:GITHUB_OUTPUT
         echo "log-file=$logFile" >> $env:GITHUB_OUTPUT
       } else {
-        Write-Host "❌ Server is not running"
+        Write-Host "❌ Server did not become ready within timeout"
         if (Test-Path $logFile) {
-          Write-Host "Server log:"
-          Get-Content $logFile | Write-Host
+          Write-Host "Server log (tail):"
+          Get-Content $logFile -Tail 200 | Write-Host
         }
         echo "success=false" >> $env:GITHUB_OUTPUT
         exit 1
       }
     } catch {
       Write-Host "❌ Error starting server: $_"
       if (Test-Path $logFile) {
-        Write-Host "Server log:"
-        Get-Content $logFile | Write-Host
+        Write-Host "Server log (tail):"
+        Get-Content $logFile -Tail 200 | Write-Host
       }
       echo "success=false" >> $env:GITHUB_OUTPUT
       exit 1
     }

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 8

__

Why: This suggestion correctly identifies that a fixed Start-Sleep is a common source of flaky tests and replaces it with a robust polling mechanism, which significantly improves the reliability of the CI workflow.

Medium
Prevent psql prompts and hangs

Make psql calls more robust by using environment variables like PGHOST and
PGCONNECT_TIMEOUT and adding the -w flag to prevent password prompts and
indefinite hangs.

.github/workflows/postgresql-test.yml [353-384]

 - name: Phase 3.1 - Test Database Connection
   id: test-connection
   if: steps.start-server.outputs.success == 'true'
   continue-on-error: true
   run: |
     $ErrorActionPreference = "Continue"
     $binPath = "${{ steps.verify-postgresql.outputs.bin-path }}"
     
     Write-Host "=== Phase 3.1: Test Database Connection ==="
     
     try {
       $psqlExe = Join-Path $binPath "psql.exe"
+      $env:PGHOST = "127.0.0.1"
+      $env:PGPORT = "5432"
+      $env:PGUSER = "postgres"
+      $env:PGCONNECT_TIMEOUT = "5"
       
-      # Test connection to default postgres database
       Write-Host "Testing connection to postgres database..."
-      $output = & $psqlExe -U postgres -d postgres -c "SELECT version();" 2>&1 | Out-String
+      $output = & $psqlExe -w -d postgres -c "SELECT version();" -t -A 2>&1 | Out-String
       
       if ($LASTEXITCODE -eq 0) {
         Write-Host "✅ Connection successful"
         Write-Host $output
         echo "success=true" >> $env:GITHUB_OUTPUT
       } else {
         Write-Host "❌ Connection failed"
         Write-Host $output
         echo "success=false" >> $env:GITHUB_OUTPUT
         exit 1
       }
     } catch {
       Write-Host "❌ Error testing connection: $_"
       echo "success=false" >> $env:GITHUB_OUTPUT
       exit 1
     }
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: This is a valuable suggestion that hardens the psql command against potential hangs by using environment variables for connection parameters and adding the -w flag, making the test script more reliable.

Medium
Align config paths with CI directories

After initdb, modify the generated postgresql.conf to explicitly set
listen_addresses and log_directory to ensure they match the CI environment,
improving test robustness.

.github/workflows/postgresql-test.yml [266-300]

 - name: Phase 2.1 - Initialize Database Cluster
   id: init-database
   if: steps.verify-postgresql.outputs.success == 'true'
   continue-on-error: true
   run: |
     $ErrorActionPreference = "Continue"
     $binPath = "${{ steps.verify-postgresql.outputs.bin-path }}"
-    $dataDir = Join-Path (Get-Location) "test-data\pgdata"
-    
+    $rootDir = Get-Location
+    $dataDir = Join-Path $rootDir "test-data\pgdata"
+    $logDir  = Join-Path $rootDir "test-results"
+
     Write-Host "=== Phase 2.1: Initialize Database Cluster ==="
     Write-Host "Data directory: $dataDir"
-    
+
+    New-Item -ItemType Directory -Force -Path $dataDir | Out-Null
+
     try {
       $initdbExe = Join-Path $binPath "initdb.exe"
-      
-      # Initialize the database cluster
+
       Write-Host "Initializing database cluster..."
       $output = & $initdbExe -D $dataDir -U postgres -A trust --locale=C --encoding=UTF8 2>&1 | Out-String
-      
+
       if ($LASTEXITCODE -eq 0) {
         Write-Host "✅ Database cluster initialized successfully"
-        Write-Host $output
+        # Update postgresql.conf to ensure correct log directory and listen address for CI
+        $conf = Join-Path $dataDir "postgresql.conf"
+        (Get-Content $conf) |
+          ForEach-Object {
+            $_ -replace "^[#\s]*listen_addresses\s*=.*","listen_addresses = 'localhost'" `
+               -replace "^[#\s]*log_directory\s*=.*","log_directory = '$logDir'"
+          } | Set-Content $conf -Encoding UTF8
+
         echo "success=true" >> $env:GITHUB_OUTPUT
         echo "data-dir=$dataDir" >> $env:GITHUB_OUTPUT
       } else {
         Write-Host "❌ Database initialization failed"
         Write-Host $output
         echo "success=false" >> $env:GITHUB_OUTPUT
         exit 1
       }
     } catch {
       Write-Host "❌ Error initializing database: $_"
       echo "success=false" >> $env:GITHUB_OUTPUT
       exit 1
     }
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly proposes to make the test configuration more explicit and robust by modifying postgresql.conf after initdb, which is a good practice for CI stability, even though the CI script does not use the .conf.ber files.

Low
General
Verify DB via pg_database query

Instead of parsing the output of \l, verify database creation by directly
querying the pg_database catalog. This approach is more robust and not dependent
on output formatting or locale.

.github/workflows/postgresql-test.yml [387-416]

 - name: Phase 3.2 - Test Database Creation
   id: test-create-db
   if: steps.test-connection.outputs.success == 'true'
   continue-on-error: true
   run: |
     $ErrorActionPreference = "Continue"
     $binPath = "${{ steps.verify-postgresql.outputs.bin-path }}"
     $testDbName = "bearsampp_test_db"
+    $env:PGHOST = "127.0.0.1"
+    $env:PGPORT = "5432"
+    $env:PGUSER = "postgres"
+    $env:PGCONNECT_TIMEOUT = "5"
     
     Write-Host "=== Phase 3.2: Test Database Creation ==="
     
     try {
       $createdbExe = Join-Path $binPath "createdb.exe"
       $psqlExe = Join-Path $binPath "psql.exe"
       
-      # Create test database
       Write-Host "Creating test database: $testDbName"
-      $output = & $createdbExe -U postgres $testDbName 2>&1 | Out-String
+      $output = & $createdbExe -w $testDbName 2>&1 | Out-String
       
       if ($LASTEXITCODE -eq 0) {
         Write-Host "✅ Database created successfully"
         
-        # Verify database exists
         Write-Host "Verifying database exists..."
-        $verifyOutput = & $psqlExe -U postgres -d postgres -c "\l" 2>&1 | Out-String
+        $verifyOutput = & $psqlExe -w -d postgres -t -A -c "SELECT 1 FROM pg_database WHERE datname = '$testDbName';" 2>&1 | Out-String
+        if ($LASTEXITCODE -eq 0 -and $verifyOutput.Trim() -eq "1") {
+          Write-Host "✅ Database verified in pg_database"
+          # Create, insert, and query test data as before...
+        } else {
+          Write-Host "❌ Database not found in pg_database"
+          echo "success=false" >> $env:GITHUB_OUTPUT
+        }
+      } else {
+        Write-Host "❌ Database creation failed"
+        Write-Host $output
+        echo "success=false" >> $env:GITHUB_OUTPUT
+        exit 1
+      }
+    } catch {
+      Write-Host "❌ Error creating database: $_"
+      echo "success=false" >> $env:GITHUB_OUTPUT
+      exit 1
+    }

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 7

__

Why: This suggestion correctly identifies that parsing the output of \l is brittle and replaces it with a direct query to the pg_database catalog, which is a much more reliable and standard way to verify database existence.

Medium
Use portable, relative config paths

Replace the hardcoded, Linux-style paths in the postgresql.conf.ber files with
relative paths and set listen_addresses to localhost to make the configuration
more portable and secure.

bin/postgresql13.23/postgresql.conf.ber [4-25]

-data_directory = '~BEARSAMPP_LIN_PATH~/bin/postgresql/postgresql13.23/data'
-hba_file = '~BEARSAMPP_LIN_PATH~/bin/postgresql/postgresql13.23/data/pg_hba.conf'
-ident_file = '~BEARSAMPP_LIN_PATH~/bin/postgresql/postgresql13.23/data/pg_ident.conf'
-listen_addresses = '*'
+# Portable defaults for test environments (relative paths, loopback only)
+# data_directory is typically the cluster root; omit to use server -D path
+# data_directory = 'data'
+hba_file = 'data/pg_hba.conf'
+ident_file = 'data/pg_ident.conf'
+
+listen_addresses = 'localhost'
 port = 5432
-log_directory = '~BEARSAMPP_LIN_PATH~/logs'
 
+# Log to cluster-relative directory by default
+logging_collector = on
+log_directory = 'log'
+log_filename = 'postgresql.log'
+log_truncate_on_rotation = off
+log_rotation_age = 0
+log_rotation_size = 0
+
  • Apply / Chat
Suggestion importance[1-10]: 5

__

Why: The suggestion correctly points out that the hardcoded, Linux-style paths in the .conf.ber files are not portable, although these files are not used by the CI test workflow. The advice to use relative paths is a good general practice for configuration files.

Low
  • More

Previous suggestions

Suggestions up to commit 786b13d
CategorySuggestion                                                                                                                                    Impact
High-level
Use templates to avoid duplication

The PR adds duplicated configuration files for multiple PostgreSQL versions,
which is difficult to maintain. A templating mechanism should be used to
generate these files from a common source.

Examples:

bin/postgresql13.23/postgresql.conf.ber [4-6]
data_directory = '~BEARSAMPP_LIN_PATH~/bin/postgresql/postgresql13.23/data'
hba_file = '~BEARSAMPP_LIN_PATH~/bin/postgresql/postgresql13.23/data/pg_hba.conf'
ident_file = '~BEARSAMPP_LIN_PATH~/bin/postgresql/postgresql13.23/data/pg_ident.conf'
bin/postgresql14.20/postgresql.conf.ber [4-6]
data_directory = '~BEARSAMPP_LIN_PATH~/bin/postgresql/postgresql14.20/data'
hba_file = '~BEARSAMPP_LIN_PATH~/bin/postgresql/postgresql14.20/data/pg_hba.conf'
ident_file = '~BEARSAMPP_LIN_PATH~/bin/postgresql/postgresql14.20/data/pg_ident.conf'

Solution Walkthrough:

Before:

// file: bin/postgresql13.23/postgresql.conf.ber
data_directory = '.../postgresql13.23/data'
hba_file = '.../postgresql13.23/data/pg_hba.conf'
...
shared_buffers = 32MB
...

// file: bin/postgresql14.20/postgresql.conf.ber
data_directory = '.../postgresql14.20/data'
hba_file = '.../postgresql14.20/data/pg_hba.conf'
...
shared_buffers = 32MB
...

// ... and 4 other nearly identical sets of files

After:

// Template: templates/postgresql/postgresql.conf.ber.tpl
data_directory = '~BEARSAMPP_LIN_PATH~/bin/postgresql/postgresql{{PG_VERSION_SHORT}}/data'
hba_file = '~BEARSAMPP_LIN_PATH~/bin/postgresql/postgresql{{PG_VERSION_SHORT}}/data/pg_hba.conf'
...
shared_buffers = 32MB
...

// Build script logic
for version in ["13.23", "14.20", ...]:
  render_template(
    'templates/postgresql/postgresql.conf.ber.tpl',
    'bin/postgresql' + version + '/postgresql.conf.ber',
    { PG_VERSION_SHORT: version }
  )
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a critical maintainability issue due to massive file duplication and proposes a robust templating solution, which would significantly improve the long-term management of these configurations.

High
Security
Use password authentication instead of trust

Replace the insecure trust authentication method with a password-based one like
scram-sha-256 in all pg_hba.conf.ber files to prevent unauthorized access.

bin/postgresql13.23/pg_hba.conf.ber [2-3]

-host        all           all             127.0.0.1/32            trust
-host 		    all           all              ::1/128	      				trust
+host        all           all             127.0.0.1/32            scram-sha-256
+host 		    all           all              ::1/128	      				scram-sha-256
Suggestion importance[1-10]: 9

__

Why: This is a critical security suggestion, as using trust authentication allows passwordless access to the database for local users, which is a major vulnerability.

High
Restrict listening to localhost interface

Change listen_addresses from '*' to 'localhost' in all postgresql.conf.ber files
to prevent exposing the database to external networks.

bin/postgresql13.23/postgresql.conf.ber [11]

-listen_addresses = '*'
+listen_addresses = 'localhost'
Suggestion importance[1-10]: 9

__

Why: This is a critical security suggestion that correctly identifies that listening on all interfaces (*) unnecessarily exposes the database to the network, increasing the attack surface.

High
Use secure permissions for log files

Change log_file_mode from 0777 to a more secure 0600 in all postgresql.conf.ber
files to protect sensitive information in log files.

bin/postgresql13.23/postgresql.conf.ber [27]

-log_file_mode = 0777
+log_file_mode = 0600
Suggestion importance[1-10]: 8

__

Why: This is a valid and important security suggestion, as 0777 permissions on log files are insecure and could lead to information disclosure or log tampering.

Medium

@github-actions
Copy link

github-actions bot commented Nov 23, 2025

🐘 PostgreSQL Module Tests - Complete Results

Test Date: 2025-11-23 11:05:25 UTC

⚠️ No test results available


📋 Test Phases

Completed:

  • Phase 1: Installation Validation (Download, Extract, Verify)
  • Phase 2: Server Initialization (Init Cluster, Start Server)
  • Phase 3: Database Operations (Connect, Create DB, Delete DB)
  • Phase 4: Cleanup (Stop Server)

All phases of PostgreSQL testing are complete! Check artifacts for detailed logs.

@qodo-code-review
Copy link

CI Feedback 🧐

A test triggered by this PR failed. Here is an AI-generated analysis of the failure:

Action: Detect PostgreSQL Versions

Failed stage: Get PostgreSQL Versions [❌]

Failure summary:

The action failed while computing the list of versions using jq. The pipeline builds VERSIONS by
grepping releases.properties, then piping into jq with:
- split(".") | map(tonumber) to sort
versions numerically.
This failed because at least one version string contains a non-numeric
component (e.g., 0-RC1), which tonumber cannot parse, causing:
- jq: error (at :40): Invalid numeric
literal at EOF at line 1, column 5 (while parsing '0-RC1')
As a result, the step exited with code 5
and the action failed.

Relevant error logs:
1:  ##[group]Runner Image Provisioner
2:  Hosted Compute Agent
...

163:  �[36;1mif [ "" != "" ]; then�[0m
164:  �[36;1m  # Manual workflow with specific version�[0m
165:  �[36;1m  VERSION=""�[0m
166:  �[36;1m  echo "Testing specific version: $VERSION"�[0m
167:  �[36;1m  VERSIONS="[\"$VERSION\"]"�[0m
168:  �[36;1melse�[0m
169:  �[36;1m  # Get all versions from releases.properties�[0m
170:  �[36;1m  VERSIONS=$(grep -E "^[0-9]+\.[0-9]+" releases.properties | cut -d'=' -f1 | tr -d ' ' | jq -R -s -c 'split("\n") | map(select(length > 0)) | unique | sort_by(split(".") | map(tonumber)) | reverse | .[0:5]')�[0m
171:  �[36;1m  echo "Testing latest 5 versions"�[0m
172:  �[36;1mfi�[0m
173:  �[36;1m�[0m
174:  �[36;1mecho "versions=$VERSIONS" >> $GITHUB_OUTPUT�[0m
175:  �[36;1mecho "Versions to test: $VERSIONS"�[0m
176:  shell: /usr/bin/bash -e {0}
177:  ##[endgroup]
178:  jq: error (at <stdin>:40): Invalid numeric literal at EOF at line 1, column 5 (while parsing '0-RC1')
179:  ##[error]Process completed with exit code 5.
180:  Post job cleanup.

@qodo-code-review
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 Security concerns

Trust authentication in pg_hba.conf and init scripts:
The configurations set authentication to trust and listen_addresses='*'. While acceptable for CI, ensure these files are never shipped or enabled by default in production bundles. Also confirm that the data_directory and log_directory placeholders (BEARSAMPP_LIN_PATH, BEARSAMPP_WIN_PATH) are properly templated so no sensitive paths are exposed in logs or configs.

⚡ Recommended focus areas for review

Possible Issue

The version-detection step uses jq in a shell pipeline on ubuntu-latest; ensure jq is available on the runner or explicitly install it to avoid failures when parsing releases.properties.

  # Get all versions from releases.properties
  VERSIONS=$(grep -E "^[0-9]+\.[0-9]+" releases.properties | cut -d'=' -f1 | tr -d ' ' | jq -R -s -c 'split("\n") | map(select(length > 0)) | unique | sort_by(split(".") | map(tonumber)) | reverse | .[0:5]')
  echo "Testing latest 5 versions"
fi
Logging Path

The log redirection uses BEARSAMPP_WIN_PATH; verify this env/placeholder is expanded at runtime in CI and end-user environments to prevent writes to a literal path.

%~dp0bin\initdb.exe -U postgres -A trust -E utf8 -D "%~dp0data" > "~BEARSAMPP_WIN_PATH~\logs\postgresql-install.log" 2>&1
copy /y "%~dp0postgresql.conf.ber" "%~dp0data\postgresql.conf"
Flaky Startup

Server startup waits a fixed 5 seconds before status check; consider a retry/backoff loop to reduce flakiness across versions and runners.

Write-Host "Waiting for server to be ready..."
Start-Sleep -Seconds 5

# Check server status
$statusOutput = & $pgCtlExe -D $dataDir status 2>&1 | Out-String
Write-Host $statusOutput

if ($statusOutput -match "server is running") {
  Write-Host "✅ PostgreSQL server is running"
  echo "success=true" >> $env:GITHUB_OUTPUT
  echo "log-file=$logFile" >> $env:GITHUB_OUTPUT
} else {
  Write-Host "❌ Server is not running"
  if (Test-Path $logFile) {

@N6REJ N6REJ changed the title PostgreSQL 13.23, 14.20, 15.15, 16.11, 17.7, and 18.1 PostgreSQL 13.23, 14.20, 15.15, 16.11, 17.7, and 18.1 Nov 23, 2025
@N6REJ N6REJ merged commit 7435ea9 into main Nov 23, 2025
15 of 22 checks passed
@N6REJ N6REJ changed the title PostgreSQL 13.23, 14.20, 15.15, 16.11, 17.7, and 18.1 PostgreSQL 13.23, 14.20, 15.15, 16.11, 17.7, and 18.1 Nov 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants