# Can't login as superuser to pgbouncer

**URL:** <https://forums.percona.com/t/cant-login-as-superuser-to-pgbouncer/14356>\
**Category:** Percona Operator for PostgreSQL\
**Created:** [February 10, 2022, 4:31pm UTC](https://forums.percona.com/t/cant-login-as-superuser-to-pgbouncer/14356 "2022-02-10T16:31:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason123](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jason123](https://forums.percona.com/u/jason123)\
**Post date:** [February 10, 2022, 4:31pm UTC](https://forums.percona.com/t/cant-login-as-superuser-to-pgbouncer/14356/1 "2022-02-10T16:31:35Z")

</div>

Hi all,

I’m running the kubernetes operator. I am following all the steps for Install Percona Distribution for PostgreSQL on Kubernetes

I am able to create all the pods and I am able to login to pgdb as pguser (step 6). However, when I try to login as postgres (superuser), I get an error that says no such user.

```auto
psql: error: connection to server at "cluster1-pgbouncer" (XX.XXX.XXX.XXX), port 5432 failed: FATAL: no such user

```

Also, when I alter the pguser role to superuser, I can no longer login with pguser anymore. Then, when I remove the superuser privilege, I can login again to pguser. Can someone help with this? Thanks.

---

<div class="post-metadata">

**Author:** ![Sergey\_Pronin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/sergey_pronin/32/14887_2.png) [@Sergey\_Pronin](https://forums.percona.com/u/Sergey_Pronin)\
**Post date:** [February 11, 2022, 8:27am UTC](https://forums.percona.com/t/cant-login-as-superuser-to-pgbouncer/14356/2 "2022-02-11T08:27:28Z")

</div>

Hello @jason123 ,

we already had this concern raised by the user here: [[K8SPG-111] Cannot connect to pgsql through pgbouncer using postgres user - Percona JIRA](https://jira.percona.com/browse/K8SPG-111)

This is done for security reasons. Superuser should not be connecting to the database through pgbouncer. There is a workaround though.

Do you mind sharing your use case here?

---

<div class="post-metadata">

**Author:** ![jason123](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jason123](https://forums.percona.com/u/jason123)\
**Post date:** [February 11, 2022, 12:38pm UTC](https://forums.percona.com/t/cant-login-as-superuser-to-pgbouncer/14356/3 "2022-02-11T12:38:47Z")

</div>

Hi @Sergey_Pronin,

I wanted to deploy everything from terraform, which I got running. After the pods are running, I created a kubernetes job with perconalab/percona-distribution-postgresql and want to run some steps automatically like:

`psql -h cluster1-pgbouncer -p 5432 -U postgres/any superuser postgres -c 'CREATE EXTENSION IF NOT EXISTS extension1, extension2, etc..` Then I would want to automatically run some commands from those extensions.

So I need to be able to log into pgbouncer with the superuser to create those extensions. I could do it manually if I exec into the pod, but I want to automate the database functions through terraform.

---

<div class="post-metadata">

**Author:** ![Craig\_Rodrigues](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/craig_rodrigues/32/8992_2.png) [@Craig\_Rodrigues](https://forums.percona.com/u/Craig_Rodrigues)\
**Post date:** [April 21, 2023, 4:24pm UTC](https://forums.percona.com/t/cant-login-as-superuser-to-pgbouncer/14356/4 "2023-04-21T16:24:56Z")

</div>

@Sergey_Pronin So the workaround is to modify the pgbouncer-users.txt field with the additional postgres user in the pgbouncer secret created by the operator?

Is there a way I can configure the operator to add multiple users, to pgbouncer-users.txt?  
Right now the default behavior of the operator seems to be to only add one user to pgbouncer-users.txt.

But if in yaml I define a PerconaPGCluster with multiple users:

```auto
spec:
  users:
    - name: user1
      databases:
        - mydb
    - name: user2
      databases:
        - mydb

```

Then only one user seems to be written to pgbouncer-users.txt (this is with the 2.0.0 version of the operator)

---

<div class="post-metadata">

**Author:** ![Slava\_Sarzhan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/slava_sarzhan/32/3196_2.png) [@Slava\_Sarzhan](https://forums.percona.com/u/Slava_Sarzhan)\
**Post date:** [April 24, 2023, 8:38am UTC](https://forums.percona.com/t/cant-login-as-superuser-to-pgbouncer/14356/5 "2023-04-24T08:38:58Z")

</div>

Hi @jason123 if we are talking about PGv1 operator you need to use [pgBouncer.exposePostgresUser](https://docs.percona.com/percona-operator-for-postgresql/users.html#application-users) option to allow access superuser via pgbouncer.

---

<div class="post-metadata">

**Author:** ![Slava\_Sarzhan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/slava_sarzhan/32/3196_2.png) [@Slava\_Sarzhan](https://forums.percona.com/u/Slava_Sarzhan)\
**Post date:** [April 24, 2023, 8:44am UTC](https://forums.percona.com/t/cant-login-as-superuser-to-pgbouncer/14356/6 "2023-04-24T08:44:06Z")

</div>

Hi @Craig_Rodrigues, you want to be able to use several users with superuser privileges and allow them access via pgbouncer. And it is for PGv2. Am I right?
