Domanda

I have created a user for my Postgres database but I cannot access the data with the user that I set up.

In a python shell I have run the following code:

>>> import psycopg2

>>> conn=psycopg2.connect(
database="db",
user="postgres",
host="/tmp/",
password="opensesame"
)

>>> cur = conn.cursor()

>>> state = 'Arkansas'

>>> cur.execute("SELECT city FROM table WHERE state = %s", (state,))

Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    cur.execute("SELECT city FROM table WHERE state = %s", (state,))
ProgrammingError: permission denied for relation table

As the superuser, I have tried:

db=# ALTER USER postgres SET TO default

but it did not help

I need to get this user access to this table, any help would be appreciated. Thank you for viewing.

È stato utile?

Soluzione

try this, log into postgres

sudo -u postgres psql

then enter \l it will list all the tables, you will see a list of your created databases,

then

GRANT ALL ON db TO postgres;

if all goes well you should now do \l again and see that you are now privileged.

Altri suggerimenti

In my code, I was receiving the error message:

ProgrammingError: permission denied for relation author

Although:

GRANT ALL ON db TO postgres;

may resolve this error for some, I later located: Permission denied for relation

and found that you may want to name the relation, sequence or table instead of the DB. According to the link above, granting privilege on the DB might have more to do with accessing the connection, rather than sort of recursively going through the tables, relations and sequences and granting privilege on all of them.

At the very least, if you run into this error, read both this article and that one and see if either one resolves the problem.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top