【发布时间】:2020-03-19 20:02:01
【问题描述】:
我正在使用 docker-compose 创建一个能够使用 pg_trgm 扩展名执行三元相似度搜索的数据库:
postgres-db:
restart: always
image: postgres:12.2
env_file:
- ../../.envs/_compose_prod.env
expose:
- 5432
volumes:
- database-data:/var/lib/postgresql/data/
- ../entrypoints/init.sql:/docker-entrypoint-initdb.d/init.sql
../entrypoints/init.sql:
create extension pg_trgm;
我首先使用了docker-compose down -v。这是docker-compose up --build输出的摘录:
postgres-db_1 | 2020-03-19 19:36:42.352 UTC [46] LOG: database system was shut down at 2020-03-19 19:36:42 UTC
postgres-db_1 | 2020-03-19 19:36:42.360 UTC [45] LOG: database system is ready to accept connections
postgres-db_1 | done
postgres-db_1 | server started
postgres-db_1 | CREATE DATABASE
postgres-db_1 |
postgres-db_1 |
postgres-db_1 | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sql
postgres-db_1 | CREATE EXTENSION
postgres-db_1 |
postgres-db_1 |
postgres-db_1 | 2020-03-19 19:36:42.643 UTC [45] LOG: received fast shutdown request
postgres-db_1 | waiting for server to shut down....2020-03-19 19:36:42.647 UTC [45] LOG: aborting any active transactions
postgres-db_1 | 2020-03-19 19:36:42.649 UTC [45] LOG: background worker "logical replication launcher" (PID 52) exited with exit code 1
postgres-db_1 | 2020-03-19 19:36:42.650 UTC [47] LOG: shutting down
postgres-db_1 | 2020-03-19 19:36:42.686 UTC [45] LOG: database system is shut down
postgres-db_1 | done
postgres-db_1 | server stopped
postgres-db_1 |
postgres-db_1 | PostgreSQL init process complete; ready for start up.
postgres-db_1 |
postgres-db_1 | 2020-03-19 19:36:42.757 UTC [1] LOG: starting PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
扩展程序似乎已成功创建。我已经在自己的计算机上成功完成了这项工作,所以我希望它现在可以工作,但是当使用 queryset.annotate(similarity=TrigramSimilarity("title", value_to_search_for)) 并评估我的 Django REST Framework 应用程序中的查询集时,我得到以下信息:
postgres-db_1 | 2020-03-19 19:36:55.384 UTC [81] ERROR: function similarity(text, unknown) does not exist at character 146
postgres-db_1 | 2020-03-19 19:36:55.384 UTC [81] HINT: No function matches the given name and argument types. You might need to add explicit type casts.
我能做什么?
感谢您的帮助。
【问题讨论】:
-
@iklinac 我已经在使用启动脚本文件夹了。
标签: django postgresql docker