The Graph Academy
Master The GraphBug BountyExplorer
  • Welcome to The Graph Hub
  • FAQs
  • Official Docs
    • Get Started
    • About The Graph
      • Introduction
      • Network Overview
    • Developer
      • Mastering Subgraphs
      • Quick Start
      • Define a Subgraph
      • Create a Subgraph
      • Publish a Subgraph to the Decentralized Network
      • Query The Graph
      • Querying from an Application
      • Distributed Systems
      • AssemblyScript API
      • AssemblyScript Migration Guide
      • GraphQL API
      • Unit Testing Framework
      • Quick and easy subgraph debugging using forks
      • Deprecating a Subgraph
    • Indexer
      • What are Indexers?
      • Revenue Streams
      • Reward Distribution
      • Allocation Lifecycles
      • Indexing & Querying
      • Hardware requirements
      • IPFS hash converter
      • Vulnerabilities
      • Indexer Subgraph Selection Guide
      • Testnet
        • Graph Protocol Testnet Docker Compose
        • Graph Protocol Testnet Baremetal
          • Architecture Considerations
          • Deploy and Configure Database
          • Deploy and Configure Graph-node
          • Deploy and Configure Indexer stack
      • Monitoring
        • Ethereum Node Chainhead Monitoring - no third parties
      • Best Practices
        • Failed subgraphs - Manually Closing Allocations
    • Delegator
      • Choosing Indexers
        • Network Page
        • Tools
        • Guides
      • Reward Statuses
    • Curator
    • Subgraph Studio
      • How to Use the Subgraph Studio
      • Deploy a Subgraph to the Subgraph Studio
      • Billing on the Subgraph Studio
      • Managing your API keys
      • Subgraph Studio FAQs
      • Transferring Subgraph Ownership
    • The Graph Explorer
    • Supported Networks
      • Building Subgraphs on NEAR
      • Building Subgraphs on Cosmos
      • Building Subgraphs on Arweave
  • The Graph Ecosystem
    • Network
      • Core Developer Teams
        • Edge & Node
        • Streamingfast
        • Figment
        • Semiotic
        • The Guild
        • GraphOps
      • The Graph Foundation
      • The Graph Council
      • Graph Advocates
      • Graph Advocates DAO
    • Infrastructure
      • Mainnet
      • Testnet
      • Network Migration
      • Multichain Migration
      • Firehose
      • Substreams
      • The Graph Client
Powered by GitBook
On this page
  • Summary
  • Acknowledgements and Disclaimer
  • Prerequisites
  • Install Postgres
  • Configure the postgres database user
  • Create databases
  • Configure Postgres for remote access
  • Test database remote access

Was this helpful?

  1. Official Docs
  2. Indexer
  3. Testnet
  4. Graph Protocol Testnet Baremetal

Deploy and Configure Database

PreviousArchitecture ConsiderationsNextDeploy and Configure Graph-node

Last updated 3 years ago

Was this helpful?

Summary

This guide provides instructions for:

  • Installing Postgres on Ubuntu 20.04

  • Configuring an indexing database for use with Graph

  • Configuring an agent database for use with the Graph agent and service

  • Making sure the database is accessible on the local network

Acknowledgements and Disclaimer

The contents of this guide has been pulled together from a variety of sources. It has been tested on Ubuntu Server 18.04 and 20.04. Your mileage may vary. Most of the Postgres install detail has been pulled from koen84's install scripts and edited for manual installation -

Prerequisites

First and foremost, it is assumed that you have decided on your architecture per the earlier part of this guide series - VMs or containers, storage sizing and redundancy, Eth node choice. At all times, this guide will use the reference architecture from the first page for all instructions. This guide is not intended for absolute beginners. It assumes some knowledge of using a linux terminal. Before you get started you will need to have your Ubuntu server instance up and running and up to date. Your server will require an internet connection. This guide assumes that you are logged into the server using a non-root account with SUDO access. Security will not be covered in this guide.

Additional packages that may need to be installed: gnupg - sudo apt-get install gnupg

It is assumed that the latest stable version of Postgres will be installed. At time of writing this guide that is Postgres13.

Install Postgres

Firstly, add the Postgres repo to package sources

sudo su -c "echo 'deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main' > /etc/apt/sources.list.d/pgdg.list"

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - && sudo apt-get update && sudo apt-get install -y postgresql

If the install is successful you should see a confirmation message:

Success. You can now start the database server using:

    pg_ctlcluster 13 main start

Configure the postgres database user

sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'changeme';" Set the password "changeme" as you see fit and make a note of it

Create databases

sudo -u postgres createdb graph-node

sudo -u postgres createdb graph-agent

Configure Postgres for remote access

If your database will be accessed remotely, you need to update the Postgres configuration to allow connections from remote hosts:

Open /etc/postgresql/13/main/postgresql.conf in an editor, find #listen_addresses = 'localhost' and change it to listen_addresses = '*' (or if you have very specific interfaces that will allow access the database, you can use those instead for additional security)

Open /etc/postgresql/13/main/pg_hba.conf in an editor and add host all all 0.0.0.0/0 md5 to the top of the file. Again, if you want to restrict scope to specific subnets or IP addresses you can choose to do so here for additional security.

Restart the Postgres service so changes take effect. sudo systemctl restart postgresql@13-main.service

Test database remote access

From another server, run a quick telnet test to check that the database server is now responding on the postgres port: telnet <postgresServer> 5432

If succesfully connected, the output should look something like:

$ telnet graphpostgres-0 5432
Trying 192.168.10.12...
Connected to graphpostgres-0.localdomain.
Escape character is '^]'.

If you get a timeout error, it is likely your database is not open to the rest of your network.

https://github.com/koen84/Graph-tools/blob/master/install/postgres.sh