SQLAgent tries to create schema in Postgres

Describe the problem/error/question

I get a “permission denied for database XXXX” when using the SQL Agent.

Looking at the database query logs I saw:

 LOG: statement: CREATE SCHEMA IF NOT EXISTS undefined
 ERROR: permission denied for database XXXX

I can successfully connect and query the Postgres database using the Postgres node and the same connection.

What is the error message (if any)?

error: permission denied for database odoo at /usr/local/lib/node_modules/n8n/node_modules/pg/lib/client.js:526:17 at processTicksAndRejections (node:internal/process/task_queues:95:5) at PostgresDriver.obtainMasterConnection (/usr/local/lib/node_modules/n8n/node_modules/@n8n/typeorm/driver/postgres/PostgresDriver.js:886:13) at PostgresQueryRunner.query (/usr/local/lib/node_modules/n8n/node_modules/@n8n/typeorm/driver/postgres/PostgresQueryRunner.js:178:36) at PostgresQueryRunner.getCurrentSchema (/usr/local/lib/node_modules/n8n/node_modules/@n8n/typeorm/driver/postgres/PostgresQueryRunner.js:279:23) at PostgresDriver.connect (/usr/local/lib/node_modules/n8n/node_modules/@n8n/typeorm/driver/postgres/PostgresDriver.js:267:37) at DataSource.initialize (/usr/local/lib/node_modules/n8n/node_modules/@n8n/typeorm/data-source/DataSource.js:136:9) at Function.fromDataSourceParams (/usr/local/lib/node_modules/n8n/node_modules/langchain/dist/sql_db.cjs:87:13) at Object.sqlAgentAgentExecute (/usr/local/lib/node_modules/n8n/node_modules/@n8n/n8n-nodes-langchain/dist/nodes/agents/Agent/agents/SqlAgent/execute.js:68:32) at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/@n8n/n8n-nodes-langchain/dist/nodes/agents/Agent/Agent.node.js:388:20)

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.68.0 (Self Hosted)
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: ubuntu

Welcome to the community @Juan_Cruz_Martino !

Tip for sharing information

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

That implies to any JSON output you would like to share with us.

Make sure that you have removed any sensitive information from your workflow and include dummy or pinned data with it!


What are you trying to do with AI agent that it attempts to create a new schema? Moreover, the schema is undefined. Sharing your workflow could help to understand the reason.