docker - 如何在 Postgres 上将 UUID 与非特权用户一起使用?
问题描述
How make a default value for uuid rows?,该uuid_generate_v4()
功能仅在uuid-ossp
启用扩展但无法启用的情况下起作用。
postgres=# CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION
postgres=# SELECT uuid_generate_v4();
uuid_generate_v4
--------------------------------------
929d5e41-d7a8-408a-b0e9-feecf10d853d
(1 row)
...
demo=> select uuid_generate_v4();
ERROR: function uuid_generate_v4() does not exist
LINE 1: select uuid_generate_v4();
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
demo=> CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
ERROR: permission denied to create extension "uuid-ossp"
HINT: Must be superuser to create this extension.
解决方案
最重要的是,它并没有说它不可用,但不允许使用非特权用户创建扩展。在 Docker 映像合成期间,您应该创建和/或启用所需的扩展。
官方的 postgres docker images 将执行放置在/docker-entrypoint-initdb.d/
文件夹下的脚本。
如果您使用官方镜像作为基础镜像(推荐),您只需创建一个.sh
文件,授予可执行标志(chmod 755),然后将其添加到/docker-entrypoint-initdb.d/
文件夹中。
希望它会起作用:
#!/bin/bash
set -e
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname="$POSTGRES_DB"<<-EOSQL
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
EOSQL
推荐阅读
- python - 查找数字是否是一个完美的立方体
- excel - 公式放在不计算 VBA 的单元格中
- html - Facebook 登录按钮出现在页面上
- javascript - 不和谐机器人。试图在没有消息信息的情况下获取用户的用户名
- c++ - 传递地址的增加值
- matlab - 如何在 Matlab 中求解具有三个一阶 ODE 的系统
- c# - 正确地将 GameObects 旋转指向鼠标位置?
- python - 带有分类数据的 hbar bokeh 1.3.4
- java - 如何从设备文件管理器的特定文件夹中获取文件而不在android studio中打开文件管理器?
- python - GraphQL-“未知参数 \"country\" 在类型 \"Query\" 的字段 \"allNews\" 上。",