You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-arc/data/using-extensions-in-postgresql-server.md
+1-202Lines changed: 1 addition & 202 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,208 +14,7 @@ ms.topic: how-to
14
14
15
15
# Use PostgreSQL extensions in your Azure Arc-enabled PostgreSQL server
16
16
17
-
PostgreSQL is at its best when you use it with extensions. In fact, a key element of our own Hyperscale functionality is the Microsoft-provided `citus` extension that is installed by default, which allows Postgres to transparently shard data across multiple nodes.
The standard [`contrib`](https://www.postgresql.org/docs/12/contrib.html) extensions and the following extensions are already deployed in the containers of your Azure Arc-enabled PostgreSQL server:
23
-
-[`citus`](https://github.com/citusdata/citus), v: 10.2. The Citus extension by [Citus Data](https://www.citusdata.com/) is loaded by default as it brings the Hyperscale capability to the PostgreSQL engine. Dropping the Citus extension from your Azure Arc PostgreSQL server is not supported.
Updates to this list will be posted as it evolves over time.
33
-
34
-
> [!IMPORTANT]
35
-
> While you may bring to your server group an extension other than those listed above, in this Preview, it will not be persisted to your system. It means that it will not be available after a restart of the system and you would need to bring it again.
36
-
37
-
This guide will take in a scenario to use two of these extensions:
## Add extensions to the `shared_preload_libraries`
52
-
For details about that are `shared_preload_libraries`, read the PostgreSQL documentation [here](https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-SHARED-PRELOAD-LIBRARIES):
53
-
- This step isn't needed for the extensions that are part of `contrib`
54
-
- this step isn't required for extensions that are not required to pre-load by shared_preload_libraries. For these extensions you may jump the next paragraph [Create extensions](#create-extensions).
55
-
56
-
### Add an extension to an instance that already exists
57
-
```azurecli
58
-
az postgres server-arc server edit -n <postgresql server> --extensions <extension names> --k8s-namespace <namespace> --use-k8s
59
-
```
60
-
61
-
## Show the list of extensions added to shared_preload_libraries
62
-
Run either of the following command.
63
-
64
-
### With CLI command
65
-
```azurecli
66
-
az postgres server-arc show -n <server name> --k8s-namespace <namespace> --use-k8s
67
-
```
68
-
Scroll in the output and notice the engine\extensions sections in the specifications of your server group. For example:
Scroll in the output and notice the engine\extensions sections in the specifications of your server group. For example:
84
-
```console
85
-
Spec:
86
-
Dev: false
87
-
Engine:
88
-
Extensions:
89
-
Name: citus
90
-
```
91
-
92
-
93
-
## Create extensions
94
-
Connect to your server group with the client tool of your choice and run the standard PostgreSQL query:
95
-
```console
96
-
CREATE EXTENSION <extension name>;
97
-
```
98
-
99
-
## Show the list of extensions created
100
-
Connect to your server group with the client tool of your choice and run the standard PostgreSQL query:
101
-
```console
102
-
select * from pg_extension;
103
-
```
104
-
105
-
## Drop an extension
106
-
Connect to your server group with the client tool of your choice and run the standard PostgreSQL query:
107
-
```console
108
-
drop extension <extension name>;
109
-
```
110
-
111
-
## The `PostGIS` extension
112
-
You do not need to add the `PostGIS` extension to the `shared_preload_libraries`.
113
-
Get [sample data](http://duspviz.mit.edu/tutorials/intro-postgis/) from the MIT’s Department of Urban Studies & Planning. Run `apt-get install unzip` to install unzip as needed.
Let's connect to our database, and create the `PostGIS` extension:
121
-
122
-
```console
123
-
CREATE EXTENSION postgis;
124
-
```
125
-
126
-
> [!NOTE]
127
-
> If you would like to use one of the extensions in the `postgis` package (for example `postgis_raster`, `postgis_topology`, `postgis_sfcgal`, `fuzzystrmatch`...) you need to first create the postgis extension and then create the other extension. For instance: `CREATE EXTENSION postgis`; `CREATE EXTENSION postgis_raster`;
128
-
129
-
And create the schema:
130
-
131
-
```sql
132
-
CREATETABLEcoffee_shops (
133
-
id serialNOT NULL,
134
-
name character varying(50),
135
-
address character varying(50),
136
-
city character varying(50),
137
-
state character varying(50),
138
-
zip character varying(10),
139
-
lat numeric,
140
-
lon numeric,
141
-
geom geometry(POINT,4326)
142
-
);
143
-
CREATEINDEXcoffee_shops_gistON coffee_shops USING gist (geom);
144
-
```
145
-
146
-
Now, we can combine `PostGIS` with the scale-out functionality, by making the coffee_shops table distributed:
\copy coffee_shops(id,name,address,city,state,zip,lat,lon) from cambridge_coffee_shops.csv CSV HEADER;
156
-
```
157
-
158
-
And fill the `geom` field with the correctly encoded latitude and longitude in the `PostGIS``geometry` data type:
159
-
160
-
```sql
161
-
UPDATE coffee_shops SET geom = ST_SetSRID(ST_MakePoint(lon,lat),4326);
162
-
```
163
-
164
-
Now we can list the coffee shops closest to MIT (77 Massachusetts Ave at 42.359055, -71.093500):
165
-
166
-
```sql
167
-
SELECT name, address FROM coffee_shops ORDER BY geom <-> ST_SetSRID(ST_MakePoint(-71.093500,42.359055),4326);
168
-
```
169
-
170
-
171
-
## The `pg_cron` extension
172
-
173
-
Now, let's enable `pg_cron` on our PostgreSQL server group by adding it to the shared_preload_libraries:
174
-
175
-
```azurecli
176
-
az postgres server-arc update -n pg2 -ns arc --extensions pg_cron
177
-
```
178
-
179
-
Your server group will restart complete the installation of the extensions. It may take 2 to 3 minutes.
180
-
181
-
We can now connect again, and create the `pg_cron` extension:
182
-
183
-
```sql
184
-
CREATE EXTENSION pg_cron;
185
-
```
186
-
187
-
For test purposes, lets make a table `the_best_coffee_shop` that takes a random name from our earlier `coffee_shops` table, and inserts the table contents:
188
-
189
-
```sql
190
-
CREATETABLEthe_best_coffee_shop(name text);
191
-
```
192
-
193
-
We can use `cron.schedule` plus a few SQL statements, to get a random table name (notice the use of a temporary table to store a distributed query result), and store it in `the_best_coffee_shop`:
194
-
195
-
```sql
196
-
SELECTcron.schedule('* * * * *', $$
197
-
TRUNCATE the_best_coffee_shop;
198
-
CREATE TEMPORARY TABLE tmp ASSELECT name FROM coffee_shops ORDER BY random() LIMIT1;
199
-
INSERT INTO the_best_coffee_shop SELECT*FROM tmp;
200
-
DROPTABLE tmp;
201
-
$$);
202
-
```
203
-
204
-
And now, once a minute, we'll get a different name:
205
-
206
-
```sql
207
-
SELECT*FROM the_best_coffee_shop;
208
-
```
209
-
210
-
```console
211
-
name
212
-
-----------------
213
-
B & B Snack Bar
214
-
(1 row)
215
-
```
216
-
217
-
See the [pg_cron README](https://github.com/citusdata/pg_cron) for full details on the syntax.
218
-
17
+
Extensions are not currently supported in this preview.
219
18
220
19
## Next steps
221
20
- Read documentation on [`plv8`](https://plv8.github.io/)
0 commit comments