Skip to content

Commit

Permalink
Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sethsamuel committed Dec 30, 2024
1 parent 97d27ae commit 1e1f1eb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pgbouncer/datadog_checks/pgbouncer/pgbouncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def _get_connect_kwargs(self):
Get the params to pass to psycopg.connect() based on passed-in vals
from yaml settings file
"""
# It's important to set the client_encoding to utf-8
# PGBouncer defaults to an encoding of 'UNICODE`, which will cause psycopg to error out
if self.database_url:
return {'conninfo': self.database_url, 'client_encoding': 'utf-8'}

Expand Down Expand Up @@ -168,6 +170,8 @@ def _get_connection(self, use_cached=None):
return self.connection
try:
connect_kwargs = self._get_connect_kwargs()
# Somewhat counterintuitively, we need to set autocommit to True to avoid a BEGIN/COMMIT block
# https://www.psycopg.org/psycopg3/docs/basic/transactions.html#autocommit-transactions
connection = pg.connect(**connect_kwargs, autocommit=True)
except Exception:
redacted_url = self._get_redacted_dsn()
Expand Down

0 comments on commit 1e1f1eb

Please sign in to comment.