4

If I write a function for PostgreSql using PLV8, can I call an url with a get/post request from my PLV8 function?

mahonya
  • 9,247
  • 7
  • 39
  • 68

2 Answers2

10

No, as explained by Milen; use an untrusted PL like PL/perlu, PL/pythonu, PL/javau, etc.

Doing this has the same problem as sending email from a trigger, in that unexpected issues like DNS configuration problems could leave all your database connections busy waiting on HTTP connection attempts so nothing else can get any work done.

Instead, use LISTEN and NOTIFY to wake an external helper script that uses a queue table to manage the requests, as explained in the answer linked above.

Community
  • 1
  • 1
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • Thanks Craig, my requirements are a bit different then simply sending an email. In fact, I actually need the whole application to stop if postgresql can't successfully execute this connection. I agree with everything in the e-mail discussion, but this is a different case :) – mahonya Oct 01 '12 at 07:46
  • @sarikan Yeah, if you need the whole app to stop then making a synchronous HTTP request from a Pg database worker (and repeating until they're all stuck) will do that! I never imagined someone might want that as a *feature* but hey, if it solves your problem... – Craig Ringer Oct 01 '12 at 09:51
1

No, according to this page and my understanding of "trusted":

PL/v8 is a trusted procedural language that is safe to use, fast to run and easy to develop, powered by V8 JavaScript Engine.

Milen A. Radev
  • 60,241
  • 22
  • 105
  • 110
  • 4
    Yes; I think this is correct. However, it's a shame there is not a way to configure PostgreSQL and/or PLV8 to allow GET/POST requests to a set of "trusted" URLs. Seems like you could do some very cool stuff (probably some pretty dangerous stuff also) lol – David S Oct 01 '12 at 01:10
  • Thanks! I was not sure if http get/put calls is a part of the javascript language libraries, but it would not matter as long as the trusted status is there. – mahonya Oct 01 '12 at 07:37