Report this

What is the reason for this report?

postgres access over the web

Posted on June 27, 2016

We have a successful implementation of a web page hosted on another provider. We are able to access our postgres database using javascript that calls python and uses psycopg2 to create a database connection. with that provider there seems to be less restrictions on access to the DB.

On Digital Ocean After much research I realized I had to create a specific user in the postgres DB to allow access from a linux user:

For Example postgres Database: database db1 Schema Public Tables: testtable (owner root) have granted full access on all tables to user jim ( also have a linux user jim)

In linux I can su to user jim and log into the database and see table testtable.

Now…

When I attempt to run the query through the web browser it seems like the connection is failing. I have also created a postgis user called “www-data” and granted full access to the tables.

I assumed was the browser user is using as user www-data.

So… The questions I have are:

  1. Am I correct in assuming that the web calls are made by “www-data”?
  2. Does it sound like Is there something I have not configured to allow DB access from web/javascript/python?

Much thanks in advance:



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

OK I have found the answer - I needed to allow python to be executed by apache:

  1. Am I correct in assuming that the web calls are made by “www-data”? Yes and this can be modified in /etc/apache2/envvars # /etc/init.d/apache2, /etc/logrotate.d/apache2, etc. export APACHE_RUN_USER=www-data export APACHE_RUN_GROUP=www-data

  2. Does it sound like Is there something I have not configured to allow DB access from web/javascript/python? The problem I was having was not related to postgres it was apache not being able to run python fix by following this article: https://www.linux.com/blog/configuring-apache2-run-python-scripts

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.