GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Utilities ignore the selected database when the server's service file sets dbname · Issue #10463 · pgadmin-org/pgadmin4

Utilities ignore the selected database when the server's service file sets dbname #10463

New issue
Copy link
New issue
Copy link
Closed
Closed
Utilities ignore the selected database when the server's service file sets dbname#10463
Copy link
Labels
Bug

Description

@dpage
dpage
opened on Sep 28, 2026
Issue body actions

When a server is registered with a service name, and that service's entry in pg_service.conf sets dbname, the Backup (object), Restore, Maintenance and Import/Export tools run against the service's database rather than the one selected in pgAdmin.

Cause

Since the connection-string injection fix, these tools pass the target database to the utility through the PGDATABASE environment variable (backup/__init__.py:481, restore/__init__.py:492, maintenance/__init__.py:283, import_export/__init__.py:550), and BatchProcess sets PGSERVICE for servers with a service (bgprocess/processes.py:850). libpq applies service file settings before falling back to environment variables, so a dbname in the service always beats PGDATABASE:

$ cat pg_service.conf
[svc]
host=127.0.0.1
user=postgres
dbname=postgres

$ PGSERVICE=svc PGDATABASE=template1 psql -Atc 'select current_database()'
postgres
$ PGSERVICE=svc psql -d template1 -Atc 'select current_database()'
template1

Impact

A restore, VACUUM/REINDEX or COPY can silently run in the wrong database, which for Restore and Import means writing data into it.

Fix

Any fix has to keep the target database out of anything libpq will expand as a connection string, which is why PGDATABASE was chosen. One option is to pass it as --dbname=dbname=<quoted value>, a connection string built by pgAdmin with the value quoted per libpq's rules, since an explicit connection parameter takes precedence over the service file.

Found by CodeRabbit whilst reviewing #10060, which does not touch this code.

Activity

  1. dpage
    added
    Bug
    on Sep 28, 2026
  2. dpage
    added 2 commits that reference this issue on Oct 12, 2026

    Pass the target database to utilities as a quoted connection string.

    This issue will close once commit c41cc27 is merged into the 'master' branch.
    c41cc27

    Pass the target database to utilities as a connection string. #10463 (#…

    This issue will close once commit d924c15 is merged into the 'master' branch.
    d924c15
  3. dpage commented on Oct 12, 2026

    @dpage
    dpage
    on Oct 12, 2026
    ContributorAuthor
    More actions

    Fixed by #10464 (d924c15).

  4. dpage
    closed this as completedon Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.