Question

postgres access over the web

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:


Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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