This is documentation for the legacy indexer. To learn how to run the underlying infrastructure for the latest indexer stack, see Transaction Stream Service.
Run an Aptos Indexer
The below installation steps are verified only on macOS with Apple Silicon. They might require minor tweaking when running on other builds.
Summary
To run an indexer fullnode, these are the steps in summary:
- Make sure that you have all the required tools and packages described below in this document.
- Follow the instructions to set up a public fullnode but do not start the fullnode yet.
- Edit the
fullnode.yaml
as described below in this document. - Run the indexer fullnode per the instructions below.
Prerequisites
Install the packages below. Note, you may have already installed many of these while preparing your development environment. You can confirm by running which command-name
and ensuring the package appears in the output (although libpq
will not be returned even when installed).
Important: If you are on macOS, you will need to install Docker following the official guidance rather than
brew
.
For an Aptos indexer fullnode, install these packages:
brew
-/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Run the commands emitted in the output to add the command to your path and install any dependenciescargo
Rust package manager -curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
docker
-brew install docker
- libpq Postgres C API library containing the
pg_ctl
command -brew install libpq
Make sure to perform all export commands after the installation. postgres
PostgreSQL server -brew install postgresql
diesel
-brew install diesel
Set up the database
- Start the PostgreSQL server:
brew services start postgresql
- Ensure you can run
psql postgres
and then exit the prompt by entering:\q
- Create a PostgreSQL user
postgres
with thecreateuser
command (find it withwhich
):/path/to/createuser -s postgres
- Clone
aptos-core
repository if you have not already:git clone https://github.com/aptos-labs/aptos-core.git
- Navigate (or
cd
) intoaptos-core/crates/indexer
directory. - Create the database schema:
This will create a database schema with the subdirectory
diesel migration run --database-url postgresql://localhost/postgres
migrations
located in thisaptos-core/crates/indexer
directory. If for some reason this database is already in use, try a different database. For example:DATABASE_URL=postgres://postgres@localhost:5432/indexer_v2 diesel database reset
Start the fullnode indexer
-
Follow the instructions to set up a public fullnode and prepare the setup, but do not yet start the indexer (with
cargo run
ordocker run
). -
Pull the latest indexer Docker image with:
docker pull aptoslabs/validator:nightly_indexer
-
Edit the
./fullnode.yaml
and add the following configuration:storage:
enable_indexer: true
# This is to avoid the node being pruned
storage_pruner_config:
ledger_pruner_config:
enable: false
indexer:
enabled: true
postgres_uri: "postgres://postgres@localhost:5432/postgres"
processor: "default_processor"
check_chain_id: true
emit_every: 500
Instead of syncing your indexer fullnode from genesis, which may take a long period of time, you can choose to bootstrap your fullnode using backup data before starting it. To do so, follow the instructions to restore from a backup.
Note: indexers cannot be bootstrapped using a snapshot or fast sync.
- Run the indexer fullnode with either
cargo run
ordocker run
depending upon your setup. Remember to supply the arguments you need for your specific node:or:docker run -p 8080:8080 \
-p 9101:9101 -p 6180:6180 \
-v $(pwd):/opt/aptos/etc -v $(pwd)/data:/opt/aptos/data \
--workdir /opt/aptos/etc \
--name=aptos-fullnode aptoslabs/validator:nightly_indexer aptos-node \
-f /opt/aptos/etc/fullnode.yamlcargo run -p aptos-node --features "indexer" --release -- -f ./fullnode.yaml
Restart the indexer
To restart the PostgreSQL server:
-
shut down the server by searching for the
postmaster
process and killing it:ps -ef | grep -i postmaster
-
Copy the process ID (PID) for the process and pass it to the following command to shut it down:
kill -INT PID
-
Restart the PostgreSQL server with:
brew services restart postgresql@14