A PostgreSQL databse is utilized to prevent duplicate DSP transactions by creating, getting, and updating service events as needed. An external database can be set by ensuring the node_env variable in the config.toml file is set to production. The database settings may be specified with the url variable, e.g., postgres://user:pass@example.com:5432/dbname.
config.toml:
[database]
# url syntax: postgres://user:pass@example.com:5432/dbname, only necessary for production
url = "postgres://user:pass@example.com:5432/dbname"
# production (uses above database_url for database)
node_env = "production"
sudo su - postgres
psql
CREATE DATABASE dsp;
CREATE USER dsp WITH ENCRYPTED PASSWORD 'Put-Some-Strong-Password-Here';
GRANT ALL PRIVILEGES ON DATABASE dsp to dsp;
Create vRAM IPFS Tables
CREATE TABLE IF NOT EXISTS blocks (key TEXT NOT NULL UNIQUE, data BYTEA);
CREATE INDEX IF NOT EXISTS blocks_key_text_pattern_ops_idx ON blocks (key text_pattern_ops);
Note if you are setting up the PostgreSQL server for vRAM where other users were previously using that service, you will need to see the replay contract section to replay all staked contracts to populate the DB with their data. Otherwise the db will not be able to fetch that info.
Run PostgreSQL server for IPFS
Systemd service
Run which go to see where your install location is, if it is not /usr/local/go/bin/go, update the ExecStart below with your path.
sudo-Esu--pcat<<EOF>/lib/systemd/system/ipfs-ds-postgres.service[Unit]Description=IPFS PostgreSQL alternative backendAfter=network.target[Service]User=root# update working directory# echo $(readlink -f `whichsetup-dsp`|xargs dirname)/../ipfs-ds-postgres/services/ipfs-ds-postgresWorkingDirectory=/root/.nvm/versions/node/v16.19.0/lib/node_modules/@liquidapps/dsp/zeus_boxes/ipfs-ds-postgres/services/ipfs-ds-postgres
Environment="DATABASE_URL=postgres://user:password@domain/db"# determine go install path with below command, if different than below, update# which goExecStart=/usr/local/go/bin/go run main.goKillMode=processRestart=on-failure[Install]WantedBy=multi-user.targetEOFsystemctlstartipfs-ds-postgressystemctlenableipfs-ds-postgresexitsleep3systemctlstatusipfs-ds-postgres