Launching multiple instances of PostGraphile with PM2

PM2 allows you to restart your application instances if they stop for any internal reason. A typical way to launch the PostGraphile with PM2 is as below:

  pm2 start --name "postgraphile" postgraphile -- --append-plugins postgraphile-plugin-connection-filter -c postgres://user:password@localhost:15432/db -s public -a -j -n 0.0.0.0 -p 15433 --enhance-graphiql --disable-query-log --no-ignore-indexes --simple-collections both	

The postgraphile-plugin-connection-filter plugin can be installed with command as below:

  npm install -g tslib postgraphile-plugin-connection-filter postgraphile
monitoring multiple PM2 instances for a Startup MVP

However, when you have multiple databases that need PostGraphile, then you would have to start multiple instances of it and the way to achieve with PM2 is to have a configuration file as below:

// content of pm2.config.js file
module.exports = {
   "apps": [
     {
       "name": "postgraphile-mimic",
       "script": "postgraphile --append-plugins postgraphile-plugin-connection-filter -c postgres://localhost/mimic -s mimiciii -a -j -n 0.0.0.0 -p 15433 --enhance-graphiql --disable-query-log --no-ignore-indexes --simple-collections both",
       "env": {
         "PGUSER": "user",
         "PGPASSWORD": "password",
         "PGPORT": 15432,
       }
     },
     {
       "name": "postgraphile-fup",
       "script": "postgraphile --append-plugins postgraphile-plugin-connection-filter -c postgres://localhost/fup -s public -a -j -n 0.0.0.0 -p 15434 --enhance-graphiql --disable-query-log --no-ignore-indexes --simple-collections both",
       "env": {
         "PGUSER": "user",
         "PGPASSWORD": "password",
         "PGPORT": 15432,
       }
     }
   ]
 }	

Launch the apps as below:

  pm2 start pm2.config.js

Now use the command pm2 list to observe the status of the launched applications.

Developer References:

Reach out for a free consulting session on GK Palem can translate your business vision into product roadmaps, technology architectures and build an MVP with optimal cost, time and resources using GraphQL, React and Postgres, Full-stack.

By   
GK Palem, Consulting CTO for Startups in AI, Blockchain, Metaverse
Published On: 11-Sep-2022

Gopalakrishna Palem is Startup Consultant with more than 2 decades of experience in building Enterprise Solutions and MVP using Postgres, NoSQL, FIDO2, DID, Blockchain Development, Artificial Intelligence, IOT, Open Source, CarMusTy, CFugue, C/C++ Music Library, Carnatic Music, Song, Notation, MIDI, Typesetting, PDF, Books, Maya, Visual Effects, DirectX, OpenGL, Simulation, Predictive Analytics, Big Data, M2M Telematics, Predictive Maintenance, Condition-based Maintenance, Research, Cryptography, Distributed Ledgers. He is a Mentor for PhD scholars and is a CTO for Hire, Consulting CTO for MVP Building, CTO for Startups, providing CTO as a Service, Virtual CTO and CTO Advisory Services.