Skip to content

Separate GreenPlum connection logic from PostgreSQL package#27

Draft
Copilot wants to merge 9 commits into
masterfrom
copilot/refactor-pg-connection-again
Draft

Separate GreenPlum connection logic from PostgreSQL package#27
Copilot wants to merge 9 commits into
masterfrom
copilot/refactor-pg-connection-again

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 5, 2026

PostgreSQL users see pg_session_role errors when postgres.Connect() attempts GreenPlum-specific parameter fallbacks (gp_role, gp_session_role) that don't exist in vanilla PostgreSQL. GreenPlum segments fail to connect in utility mode during backup initialization.

Changes

Extracted GreenPlum connection logic

  • Created greenplum/connect.go with GP-specific Connect() that tries standard connection → gp_role=utilitygp_session_role=utility
  • Removed tryConnectToGpSegment() from postgres/connect.go
  • Updated 6 greenplum package files to use local Connect() instead of postgres.Connect()

Implemented connection function injection

  • Added PgConnectFunc type alias for connection function signature
  • Made BackupArguments.connectFunc field injectable
  • Created NewBackupHandlerWithConnect() to accept custom connection during initialization
  • Modified GetPgServerInfo() to accept optional connection function (variadic for backward compatibility)

Fixed segment backup initialization

  • NewSegBackupHandler() now injects greenplum.Connect via NewBackupHandlerWithConnect()
  • Ensures GP utility mode parameters used throughout handler lifecycle, including during GetPgServerInfo() calls
// Before: hard-coded postgres.Connect() in initialization
func NewBackupHandler(arguments BackupArguments) (*BackupHandler, error) {
    pgInfo, _, err := GetPgServerInfo(false)  // Uses postgres.Connect()
    ...
}

// After: injectable connection with clean delegation
func NewBackupHandlerWithConnect(arguments BackupArguments, connectFunc PgConnectFunc) (*BackupHandler, error) {
    if connectFunc != nil {
        arguments.connectFunc = connectFunc
    }
    pgInfo, _, err := GetPgServerInfo(false, arguments.connectFunc)
    ...
}

// Segment handler now passes GP connection from start
bh, err := postgres.NewBackupHandlerWithConnect(arguments, greenplum.Connect)

PostgreSQL connections no longer attempt GreenPlum-specific fallbacks. GreenPlum functionality preserved with proper utility mode connection handling.

Original prompt

This section details on the original issue you should resolve

<issue_title>Refactor PG connection from GP stuff</issue_title>
<issue_description>### What feature would you like?

Users (x4m) are very confused to see pg_session_role errors when connecting to Postgres.

Why is this feature useful?

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 5, 2026 09:31
…n logic

Co-authored-by: chipitsine <2217296+chipitsine@users.noreply.github.com>
Co-authored-by: chipitsine <2217296+chipitsine@users.noreply.github.com>
Co-authored-by: chipitsine <2217296+chipitsine@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor PG connection handling to reduce errors Separate GreenPlum connection logic from PostgreSQL package Feb 5, 2026
Copilot AI requested a review from chipitsine February 5, 2026 09:38
…iles

Co-authored-by: chipitsine <2217296+chipitsine@users.noreply.github.com>
…tion support

Co-authored-by: chipitsine <2217296+chipitsine@users.noreply.github.com>
Co-authored-by: chipitsine <2217296+chipitsine@users.noreply.github.com>
…ackupHandler

Co-authored-by: chipitsine <2217296+chipitsine@users.noreply.github.com>
Copilot AI changed the title Separate GreenPlum connection logic from PostgreSQL package Separate GreenPlum connection logic from PostgreSQL to fix connection errors Feb 5, 2026
Co-authored-by: chipitsine <2217296+chipitsine@users.noreply.github.com>
Copilot AI changed the title Separate GreenPlum connection logic from PostgreSQL to fix connection errors Separate GreenPlum and PostgreSQL connection logic Feb 5, 2026
Copilot AI changed the title Separate GreenPlum and PostgreSQL connection logic Separate GreenPlum connection logic from PostgreSQL package Feb 5, 2026
@chipitsine chipitsine force-pushed the master branch 2 times, most recently from 3633c51 to 81395bd Compare May 7, 2026 21:35
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.

Refactor PG connection from GP stuff

2 participants