Share via


在已啟用 Azure Arc 的 PostgreSQL 伺服器中使用 PostgreSQL 延伸模組

PostgreSQL 最適合搭配延伸模組使用。

注意

作為預覽功能,本文所述的技術受限於 Microsoft Azure 預覽版增補使用規定

版本資訊中提供的最新更新。

支援的擴充功能

已在已啟用 Azure Arc 的 PostgreSQL 伺服器容器中預設部署下列延伸模組,有些是標準 contrib 延伸模組:

  • address_standardizer_data_us 3.3.1
  • adminpack 2.1
  • amcheck 1.3
  • autoinc 1
  • bloom 1
  • btree_gin 1.3
  • btree_gist 1.6
  • citext 1.6
  • cube 1.5
  • dblink 1.2
  • dict_int 1
  • dict_xsyn 1
  • earthdistance 1.1
  • file_fdw 1
  • fuzzystrmatch 1.1
  • hstore 1.8
  • hypopg 1.3.1
  • insert_username 1
  • intagg 1.1
  • intarray 1.5
  • isn 1.2
  • lo 1.1
  • ltree 1.2
  • moddatetime 1
  • old_snapshot 1
  • orafce 4
  • pageinspect 1.9
  • pg_buffercache 1.3
  • pg_cron 1.4-1
  • pg_freespacemap 1.2
  • pg_partman 4.7.1
  • pg_prewarm 1.2
  • pg_repack 1.4.8
  • pg_stat_statements 1.9
  • pg_surgery 1
  • pg_trgm 1.6
  • pg_visibility 1.2
  • pgaudit 1.7
  • pgcrypto 1.3
  • pglogical 2.4.2
  • pglogical_origin 1.0.0
  • pgrouting 3.4.1
  • pgrowlocks 1.2
  • pgstattuple 1.5
  • plpgsql 1
  • postgis 3.3.1
  • postgis_raster 3.3.1
  • postgis_tiger_geocoder 3.3.1
  • postgis_topology 3.3.1
  • postgres_fdw 1.1
  • refint 1
  • seg 1.4
  • sslinfo 1.2
  • tablefunc 1
  • tcn 1
  • timescaledb 2.8.1
  • tsm_system_rows 1
  • tsm_system_time 1
  • unaccent 1.1

此清單的更新將會在其隨著時間演進時發佈。

在已啟用 Arc 的 PostgreSQL 伺服器中啟用延伸模組

您可以將逗號分隔的延伸模組清單傳遞至 create 命令的 --extensions 參數,以建立已啟用 Arc 的 PostgreSQL 伺服器,並啟用任何支援的延伸模組。

az postgres server-arc create -n <name> --k8s-namespace <namespace> --extensions "pgaudit,pg_partman" --use-k8s

注意:啟用的延伸模組會新增至設定 shared_preload_libraries。 您必須先在資料庫中安裝延伸模組,然後才能使用它們。 若要安裝特定延伸模組,您應該執行 CREATE EXTENSION 命令。 此命令會將封裝的物件載入您的資料庫。

例如,連線到您的資料庫,並發出下列 PostgreSQL 命令來安裝 pgaudit 延伸模組:

CREATE EXTENSION pgaudit;

更新延伸模組

您可以從已啟用 Arc 的現有 PostgreSQL 伺服器新增或移除延伸模組。

您可以執行 kubectl describe 命令來取得目前已啟用延伸模組的清單:

kubectl describe postgresqls <server-name> -n <namespace>

如果啟用延伸模組,輸出會包含如下的區段:

  config:
    postgreSqlExtensions: pgaudit,pg_partman

執行下列 PostgreSQL 命令,檢查延伸模組是否已在連線到資料庫之後安裝:

select * from pg_extension;

將延伸模組附加至現有的清單,或從現有清單中移除延伸模組,以啟用新的延伸模組。 將所需的清單傳遞至 update 命令。 例如,若要在上述範例中新增 pgcrypto,並從伺服器移除 pg_partman

az postgres server-arc update -n <name> --k8s-namespace <namespace> --extensions "pgaudit,pgrypto" --use-k8s

一旦更新允許的延伸模組清單。 連線到資料庫,並透過下列命令安裝新增的延伸模組:

CREATE EXTENSION pgcrypto;

同樣地,若要從現有的資料庫移除延伸模組,請發出命令 DROP EXTENSION

DROP EXTENSION pg_partman;

顯示已安裝的延伸模組清單

使用您選擇的用戶端工具連線至資料庫,並執行標準 PostgreSQL 查詢:

select * from pg_extension;
  • 立即試用。在 Azure Kubernetes Service (AKS)、AWS Elastic Kubernetes Service (EKS)、Google Cloud Kubernetes Engine (GKE) 或 Azure VM 中快速開始使用 Azure Arc 快速入門