How to run an indexer node?

... 2022-11-16 About 1 min

# How to run an indexer node?

# Video guida

# Introduction

L'esecuzione di un nodo indicizzatore è un'altra opzione al di fuori dell'utilizzo di Docker o di un progetto ospitato in < 0 > Progetti SubQuery </0 >. Richiede più tempo e sforzo, ma migliorerà la comprensione di come SubQuery funziona sotto le copertine.

# Postgres

Running an indexer node on your infrastructure will require the setup of a Postgres database. You can install Postgres from here (opens new window) and ensure the version is 12 or greater.

# Install subql/node

Then to run a SubQuery node, run the following command:

npm install -g @subql/node
1

The -g flag means to install it globally which means on OSX, the location will be /usr/local/lib/node_modules.

Once installed, you can check the version by running:

> subql-node --version
0.19.1
1
2

# Setting DB configs

Next, you need to set the following environmental variables:

export DB_USER=postgres
export DB_PASS=postgres
export DB_DATABASE=postgres
export DB_HOST=localhost
export DB_PORT=5432
1
2
3
4
5

Of course, if you have different values for the above keys, please adjust accordingly. Note that the env command will display the current environment variables and that this process only sets these values temporarily. That is, they are only valid for the duration of the terminal session. To set them permanently, store them in your ~/bash_profile instead.

# Indexing a project

To start indexing a project, navigate into your project folder and run the following command:

subql-node -f .
1

If you do not have a project handy, git clone https://github.com/subquery/subql-helloworld. You should see the indexer node kick into life and start indexing blocks.

# Inspecting Postgres

If you navigate to Postgres, you should see two tables created. public.subqueries and subquery_1.starter_entities.

public.subqueries only contains 1 row which the indexer checks upon start up to “understand the current state” so it knows where to continue from. The starter_entities table contains the indexes. To view the data, run select (*) from subquery_1.starter_entities.

Last update: November 16, 2022 22:54