subsquid / squid-sdk

The main repo of the squid SDK
Apache License 2.0
1.23k stars 151 forks source link

Connect to non-local Postgres instance? #198

Closed sam-potter closed 1 year ago

sam-potter commented 1 year ago

As far as I can tell from looking through examples, the only way to connect to the database instance is by specifying the DB_NAME and DB_PORT env variables and have the process connect on the localhost network.

Is there no way to specify a full database connection string? I.e. allow the subsquid process and database be run separately on different networks?

justraman commented 1 year ago

@sam-potter you need to set DB_HOST

sam-potter commented 1 year ago

Working now, thanks for that.

It would be worth adding this to the documentation, or perhaps an .env.example file in repos

DB_NAME=""
DB_USER=""
DB_PORT=""
DB_PASS=""
DB_HOST=""
bauti-defi commented 1 year ago

Hello @sam-potter, tried doing this with a simple RDS S3 aws postgres instance.

I have the following .env defined

DB_NAME=postgres
DB_HOST=database-1.xxxxx.sa-east-1.rds.amazonaws.com
DB_PORT=5432
DB_USER=postgres
DB_PASS=XXXXX

I am able to connect to the remote database from a local pgadmin instance. but starting the squid process gives me the following error...

CLEAN
BUILD
MIGRATION:APPLY
error: no pg_hba.conf entry for host "190.210.192.47", user "postgres", database "postgres", no encryption
    at Parser.parseErrorMessage (/Users/bautista/Desktop/DAMMcap/uni-v3-squid/node_modules/pg-protocol/dist/parser.js:287:98)
    at Parser.handlePacket (/Users/bautista/Desktop/DAMMcap/uni-v3-squid/node_modules/pg-protocol/dist/parser.js:126:29)
    at Parser.parse (/Users/bautista/Desktop/DAMMcap/uni-v3-squid/node_modules/pg-protocol/dist/parser.js:39:38)
    at Socket.<anonymous> (/Users/bautista/Desktop/DAMMcap/uni-v3-squid/node_modules/pg-protocol/dist/index.js:11:42)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  length: 162,
  severity: 'FATAL',
  code: '28000',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'auth.c',
  line: '543',
  routine: 'ClientAuthentication'
}

Did you encounter this error?

eldargab commented 1 year ago

@bauti-defi , please, try DB_SSL=true