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
A pgcat-based PostgreSQL proxy that allows to use PostgresML functions on managed PostgreSQL databases that may not have Internet access, like AWS RDS.
4
+
5
+
##Getting started
6
+
7
+
A Docker image is provided and is the easiest way to get started. To run the image, you can simply:
**Note:** Replace the`DATABASE_URL` above with the`DATABASE_URL` of your own PostgresML database.
17
+
18
+
If you're running this on EC2, make sure the instance is placed inside the same VPC as your RDS database and that the RDS database is allowed to make outbound connections to the EC2 instance.
19
+
The example above starts the proxy process on port 6432, so for your security group configuration, make sure the database can make outbound connections to the EC2 instance using TCP on port 6432.
20
+
21
+
###Configure FDW
22
+
23
+
We'll be using the Foreign Data Wrapper extension to connect from your RDS database to PostgresML, forwarding the connection through the proxy. If you're running the proxy on EC2, take note of the private IP
24
+
or DNS entry of the instance.
25
+
26
+
Before proceeding, make sure you have the following extensions installed into your RDS database:
27
+
28
+
```postgresql
29
+
CREATE EXTENSION IF NOT EXISTS dblink;
30
+
CREATE EXTENSION IF NOT EXISTS postgres_fdw;
31
+
```
32
+
33
+
Both of these require superuser, so make sure you're running these commands with a user that has the`rds_superuser` role.
34
+
35
+
To create a foreign data wrapper connection, take your PostgresML host and port and replace the host with the private IP or DNS entry of the instance.
36
+
37
+
```postgresql
38
+
CREATE SERVER postgresml
39
+
FOREIGN DATA WRAPPER postgres_fdw
40
+
OPTIONS (
41
+
host '127.0.0.1',
42
+
port '6432',
43
+
dbname 'pgml'
44
+
);
45
+
```
46
+
47
+
Replace the value for`host` with the private IP or DNS entry of the EC2 instance running the proxy. Replace the`dbname` with the name of the database from your PostgresML database`DATABASE_URL`.
48
+
49
+
####User mapping
50
+
51
+
PostgresML and the proxy requires authentication. For each user that will use the connection, create a user mapping, like so:
52
+
53
+
```postgresql
54
+
CREATE USER MAPPING
55
+
FOR CURRENT_USER
56
+
SERVER postgresml
57
+
OPTIONS (
58
+
user 'pg',
59
+
password 'ml'
60
+
);
61
+
```
62
+
63
+
Replace the values for`user` and`password` with the values from your PostgresML database`DATABASE_URL`. This example contains values that will only work with our demo server and aren't suitable for production.`CURRENT_USER` is a special PostgreSQL variable that's replaced by the name of the user running the command. If you want to create this mapping for other users, replace it with the name of the user/role.
64
+
65
+
###Test the connection
66
+
67
+
To test the connection, you can use`dblink`:
68
+
69
+
```
70
+
SELECT
71
+
*
72
+
FROM
73
+
dblink(
74
+
'postgresml',
75
+
'SELECT * FROM pgml.embed(''intfloat/e5-small'', ''embed this text'') AS embedding'
76
+
) AS t1(embedding real[386]);
77
+
```
78
+
79
+
If everything is configured correctly, you should see an array of 386 floating points, your first embedding generated using PostgresML on AWS RDS. Both dblink and the proxy makes efficient use of connections, so queries will be executed as fast as the network connection allows.