0

I have PostgreSQL database form there I have created database and user using below commands.

create database webreporting;   
create user csr with password 'csrtest12!@';    
grant all on  database webreporting to csr;    
GRANT ALL PRIVILEGES ON ALL TABLES
    IN SCHEMA public to csr;    
GRANT ALL PRIVILEGES ON ALL TABLES IN
    SCHEMA public TO csr;    
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN
    SCHEMA public TO csr;    

I am trying connect this database from springboot application. Spring boot application is started successfully but while executing the query from application it's throwing exception like below

org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [Delete from facts where customer_id=?]; nested exception is
org.postgresql.util.PSQLException: ERROR: permission denied for table facts.

Application.properties file is:

spring.datasource.driver-class-name=org.postgresql.Driver   
spring.datasource.url=jdbc:postgresql://localhost:5432/webreporting 
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect   
spring.datasource.username=csr   
spring.datasource.password=csrtest12!@

I am not sure why I am getting permission denied exception.

1
  • Has your user login privileges? Try ALTER ROLE <username> WITH LOGIN; Commented Aug 28, 2019 at 23:13

1 Answer 1

2

You're probably missing permissions on schema. Try running below command:

GRANT USAGE ON SCHEMA public TO csr;
Sign up to request clarification or add additional context in comments.

3 Comments

Is that table already created or you're expecting it to be created on startup?
its startup after this i want to create table
If you want your JPA entities to be created on startup, you need to set ddl-auto property in Spring configuration - docs. Also, try to set the schema of your entity to public.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.