Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Unable to run pg_repack due to superuser error

foo
Bronze 1
Bronze 1

Hello, I am trying to run `pg_repack` on one of my databases, but I'm stuck by this error message I get when trying to run the extension. 

```

pg_repack --dry-run -h xxx.xxx.xx.xx -p 5432 -U postgres -d db_name -t table_name
INFO: Dry run enabled, not executing repack
Password:
ERROR: pg_repack failed with error: You must be a superuser to use pg_repack

```

I followed the guide here https://cloud.google.com/sql/docs/postgres/extensions#pg_repack on how to setup and run the extensions. The user I'm using has the cloudsqlsuperuser role and as far as I can tell has the correct permissions for the database in question too. I'm at a loss on what triage or debugging steps to take next. 

For additional context I recently upgraded this db to PGv16.4. I am using pg_repack v 1.5.0 on my client, and in the database. 

0 1 256
1 REPLY 1

Hi @foo,

The error message you're encountering with pg_repack indicates that the user you're using to run the command doesn't have sufficient permissions. While the cloudsqlsuperuser role grants extensive privileges, it seems it's not enough for pg_repack in your case.

You may try adding -k or --no-superuser-check. This should be specified in the pg_repack command line. The parameter is needed because Cloud SQL uses cloudsqlsuperuser instead of superuser and pg_repack client only checks if the specified user has a superuser role.

I hope this helps.