The following is a guide to deploy a Gateway on Ubuntu 20.04. In general, we suggest at minimum an 8 core vCPU, 32 GB RAM instance on platforms like Digital Ocean, Vultr and AWS. You should also tune and configure your Postgres instance. Read tuning the database in the Gateway docs to learn more about optimizing your Postgres Database.
After SSHing into your Ubuntu VPS, install Postgres and NVM by running the following commands.
sudo apt update
sudo apt install postgresql postgresql-contrib -y
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
nvm install --ltsMake sure to also install yarn and pm2 for later.
npm install pm2 yarn --globalMake sure to add the Arweave user to the database, you can do so by running the following.
# Access PSQL Terminal
sudo -u postgres psql
--- Create the arweave database and user
CREATE DATABASE arweave;
CREATE USER arweave WITH ENCRYPTED PASSWORD 'arweave';
GRANT ALL PRIVILEGES ON DATABASE arweave TO arweave;
--- Required in order to import blocks from a snapshot
ALTER ROLE arweave WITH SUPERUSER;
After, update the Postgres configuration. You can customize your RAM and Cores below to match your system configuration.
RAM (in GB)
CPU Cores
Max Connections
ALTER SYSTEM SET max_connections = '1000';
ALTER SYSTEM SET shared_buffers = '8GB';
ALTER SYSTEM SET effective_cache_size = '24GB';
ALTER SYSTEM SET maintenance_work_mem = '8GB';
ALTER SYSTEM SET checkpoint_completion_target = '0.9';
ALTER SYSTEM SET wal_buffers = '64MB';
ALTER SYSTEM SET default_statistics_target = '100';
ALTER SYSTEM SET random_page_cost = '2.0';
ALTER SYSTEM SET effective_io_concurrency = '200';
ALTER SYSTEM SET work_mem = '128MB';
ALTER SYSTEM SET min_wal_size = '2GB';
ALTER SYSTEM SET max_wal_size = '4GB';
ALTER SYSTEM SET max_worker_processes = '16';
ALTER SYSTEM SET max_parallel_workers_per_gather = '4';
ALTER SYSTEM SET max_parallel_workers = '16';
ALTER SYSTEM SET max_parallel_maintenance_workers = '4';
ALTER SYSTEM SET autovacuum_vacuum_scale_factor = '0.1';
ALTER SYSTEM SET autovacuum_max_workers = '2';
--- Do a non intrusive reload after altering system settings
SELECT pg_reload_conf();Then exit and restart your database.
--- exit PSQL Terminal
exit;
# restart the Postgres database
/etc/init.d/postgresql restartMake the /arweave directory and then download the snapshot from the Amplify website.
mkdir /arweave
cd /arweave
curl -o snapshot.tar.gz https://snapshots.amplify.host/APRIL7TH/snapshot.tar.gz
tar -xvzf snapshot.tar.gzClone the Gateway github repo, install node modules and then configure the environment and setup the tables. Make sure to drop the indices on the table too.
git clone https://github.com/ArweaveTeam/gateway
cd gateway
yarn
cp .env.dev .env
yarn migrate:latest
sh bin/index.drop.shAssuming the Snapshot is stored in /arweave/snapshot after decompressing the .tar.gz file. Run the import shell script. After the import command is complete. Recreate the indices by running the index create shell script.
sh bin/import.sh
sh bin/index.create.shTo finalize the deployment. Build the Gateway project and then start the Gateway with pm2. You can change the port it's on and the parallelization of synchronization by changing the .env file.
yarn dev:build
pm2 start dist/src/Gateway.js --name gateway