From 19888fa8b89f7e8af87f6a45ed4e22b658fc834a Mon Sep 17 00:00:00 2001 From: Gaurav Khanna Date: Fri, 29 Mar 2024 19:26:23 -0700 Subject: [PATCH] add init extension script --- Dockerfile | 4 +++- README.md | 44 +++++++++++++++++++++++++++++--------------- initdb-extensions.sh | 13 +++++++++++++ 3 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 initdb-extensions.sh diff --git a/Dockerfile b/Dockerfile index 59e92cb..ecd3dec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,4 +23,6 @@ RUN apt-get update \ && apt-get autoremove -y \ && apt-get clean \ && apt-mark unhold locales \ - && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ No newline at end of file + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +COPY ./initdb-extensions.sh /docker-entrypoint-initdb.d/20_extensions.sh \ No newline at end of file diff --git a/README.md b/README.md index 26dd7c0..e196188 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +postgresql,postgis docker container with pgvector added + # Deploy [![Docker](https://github.com/gvkhna/postgis-vector/actions/workflows/publish.yml/badge.svg?branch=main)](https://github.com/gvkhna/postgis-vector/actions/workflows/publish.yml) @@ -6,20 +8,6 @@ ghcr.io/gvkhna/postgis-vector:latest ``` -# After Deploy Initialize Extensions - -```sh -$ su - postgres -$ psql -postgres=# CREATE EXTENSION vector; -postgres=# CREATE EXTENSION fuzzystrmatch; -postgres=# CREATE EXTENSION pg_trgm; -postgres=# CREATE EXTENSION pg_uuidv7; - -# to verify extensions installed -postgres=# \dx -``` - ## Build ```sh @@ -28,7 +16,33 @@ podman build -t postgis-vector . ## Minimal Run -``` +```sh podman run -it --name postgis-vector -e POSTGRES_PASSWORD=mysecretpassword -d postgis-vector podman exec -it postgis-vector bash + +## +# To verify extensions installed +## +$ su - postgres +$ psql +postgres=# \dx + + List of installed extensions + Name | Version | Schema | Description +------------------------+---------+------------+------------------------------------------------------------------- + fuzzystrmatch | 1.2 | public | determine similarities and distance between strings + pg_trgm | 1.6 | public | text similarity measurement and index searching based on trigrams + pg_uuidv7 | 1.5 | public | pg_uuidv7: create UUIDv7 values in postgres + plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language + postgis | 3.4.2 | public | PostGIS geometry and geography spatial types and functions + postgis_tiger_geocoder | 3.4.2 | tiger | PostGIS tiger geocoder and reverse geocoder + postgis_topology | 3.4.2 | topology | PostGIS topology spatial types and functions + vector | 0.6.2 | public | vector data type and ivfflat and hnsw access methods +(8 rows) + +## +# To list all available extensions +## +postgres=# select * from pg_available_extensions; + ``` \ No newline at end of file diff --git a/initdb-extensions.sh b/initdb-extensions.sh new file mode 100644 index 0000000..4a64458 --- /dev/null +++ b/initdb-extensions.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e + +# Load additional extensions into database +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL + CREATE EXTENSION IF NOT EXISTS pg_trgm; + ALTER EXTENSION pg_trgm UPDATE; + CREATE EXTENSION IF NOT EXISTS pg_uuidv7; + ALTER EXTENSION pg_uuidv7 UPDATE; + CREATE EXTENSION IF NOT EXISTS vector; + ALTER EXTENSION vector UPDATE; +EOSQL \ No newline at end of file