由于权限不足,使用 cloud_sql_proxy 创建扩展失败

时间:2021-05-20 15:32:46

标签: django postgresql google-cloud-platform google-cloud-sql cloud-sql-proxy

我的目标是以自动方式 (GCP PostgreSQL extensions) 启用 ltree postgres 扩展。

这是创建扩展所需的查询 CREATE EXTENSION IF NOT EXISTS ltree;。当我使用以下方法手动连接到 cloudsql 实例时,我验证了此命令是否有效。当我这样做时,该实例的迁移运行良好。

gcloud sql connect MyBackendInstance --user=postgres
postgres=> \c my_database;
Password:
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
You are now connected to database "my_database" as user "postgres".
mch_staging=> CREATE EXTENSION IF NOT EXISTS ltree;
CREATE EXTENSION

现在我从一个名为 django-ltree 的库中进行了以下 Django 迁移,它在我的本地安装上运行良好。

migrations.RunSQL(
    "CREATE EXTENSION IF NOT EXISTS ltree;",
    "DROP EXTENSION ltree;"
)

但是,当我在我的管道中运行该迁移时(没有使用上述方法手动安装 ltree 连接),它使用 cloud_sql_proxy 连接到数据库,我收到以下错误:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 82, in _execute
    return self.cursor.execute(sql)
psycopg2.errors.InsufficientPrivilege: permission denied to create extension "ltree"
HINT:  Must be superuser to create this extension.

管道中的命令非常简单:

./cloud_sql_proxy -instances="$CLOUD_SQL_INSTANCES"=tcp:5432 -credential_file=gcloud-api-credentials.json &
python backend/manage.py migrate

在 django 设置中正确定义了与数据库连接的凭据,我们已经能够使用这些凭据来执行各种迁移。

我已尝试按照此问题中的描述创建一个 new user,但这并没有解决问题,因此似乎无关。

更新我尝试在本地运行 cloud_sql_proxy,使用相同的身份验证文件安装不同的扩展程序,这似乎完美无缺。

0 个答案:

没有答案