2 ms·
As I just learned, apparently you can make HTTP requests from postgres like so: copy (select 'hello world') to program 'curl -m 10 --data-binary @- https:/
by cuu508 2y ago
As I just learned, apparently you can make HTTP requests from postgres like so:
copy (select 'hello world') to program 'curl -m 10 --data-binary @- https://some-url-here';
There's also a postgres extension for making HTTP requests but this seems to work out of the box (if curl is installed).
The "-m 10" parameter is 10 second timeout, to reduce the risk of this command hanging. I did not test what happens if curl returns non-zero exit code, this would also need to be tested and handled.
One could use this to monitor pg_cron tasks with external cron monitoring services. I'm not sure if this would be overall good idea, but one could :-)
- radimm 2y agoAutor here. Generally I feel much more confident about external services 'pulling' the status. But I have something cooking up to reduce the friction of external calls and possible process blocking...
- cuu508 2y agoBrowsing StackOverflow I saw a suggestion to use NOTIFY/LISTEN for stuff like this (it was a question about sending emails from postgres) – an external process listens for notifications and runs the external commands. No blocking risk, and the external process can run on a different host, but you have one extra moving part to look after.
- mattashii 2y ago> As I just learned, apparently you can make HTTP requests from postgres like so: Well, it's more "you can execute arbitrary commands on the host node, which happens to include curl if it's installed". Which is also why this is limited to admins, as it is often seen as a security problem when users can execute arbitrary commands on the host server. So IMV there's nothing PostgreSQL-specific to that curl command and HTTP request, other than that it happened to be part of the execution stack.
- RedShift1 2y agoThis only works as admin, use https://github.com/pramsey/pgsql-http https://github.com/pramsey/pgsql-http instead. Whether or not you should, is a different question, there is a certain "oh no" factor to this.
- dijit 2y agoit can be exceedingly handy to update things like daily conversion tables or grab output from an ETL job that has been exposed by an API. Construct your SQL well with proper TX isolation and guards and there's no worry, and it's much better in many cases where data warehouses are employed than writing extra software on top.