Problem/Motivation

The pgsql driver connects and then runs SET NAMES 'UTF8' as a separate statement in Connection::__construct(). This adds one network round trip to every connection. Drupal opens a new database connection on every request, so every request pays this cost.

libpq can set session settings in the connection startup packet through the options DSN parameter. SET NAMES 'UTF8' is equivalent to SET client_encoding TO 'UTF8'. The encoding can be set with options='-c client_encoding=UTF8' in the DSN, with no extra round trip.

Steps to reproduce

Enable statement logging on PostgreSQL. Load any page. The log shows SET NAMES 'UTF8' after each connection start.

Proposed resolution

Append options='-c client_encoding=UTF8' to the DSN in Connection::open(). Remove the exec() call from the constructor.

Remaining tasks

Create a merge request. Review.

API changes

None.

Data model changes

None.

For the committer

The changes to the .gitlab-ci.yml file need to be removed before merging!

Issue fork drupal-3615187

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

daffie created an issue. See original summary.

daffie’s picture

Status: Active » Needs review

Added the fix and testing.

daffie’s picture

Disclosure: I have used AI on the PR and the IS.

daffie’s picture

Issue summary: View changes
smustgrave’s picture

Status: Needs review » Needs work

For 1 comment on the MR.

daffie’s picture

Status: Needs work » Needs review
longwave’s picture

Status: Needs review » Needs work

Added a suggestion to the MR.